TestMdRender.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Http\Api\MdRender;
  4. use App\Tools\Markdown;
  5. use App\Tools\Tools;
  6. use Illuminate\Console\Command;
  7. use Illuminate\Support\Facades\Log;
  8. use Illuminate\Support\Str;
  9. class TestMdRender extends Command
  10. {
  11. /**
  12. * The name and signature of the console command.
  13. * php artisan test:md.render term --format=unity --driver=str
  14. *
  15. * @var string
  16. */
  17. protected $signature = 'test:md.render {item?} {--format=html} {--driver=morus}';
  18. /**
  19. * The console command description.
  20. *
  21. * @var string
  22. */
  23. protected $description = 'Command description';
  24. /**
  25. * Create a new command instance.
  26. *
  27. * @return void
  28. */
  29. public function __construct()
  30. {
  31. parent::__construct();
  32. }
  33. /**
  34. * Execute the console command.
  35. *
  36. * @return int
  37. */
  38. public function handle()
  39. {
  40. if (Tools::isStop()) {
  41. return 0;
  42. }
  43. Log::info('md render start item='.$this->argument('item'));
  44. $data = [];
  45. $data['bold'] = <<<'md'
  46. **三十位** 经在[中间]六处为**[licchavi]**,在极果为**慧解脱**
  47. md;
  48. $data['sentence'] = <<<'md'
  49. {{168-916-2-9}}
  50. md;
  51. $data['link'] = <<<'md'
  52. aa `[link](wikipali.org/aa.php?view=b&c=d)` bb
  53. md;
  54. $data['term'] = <<<'md'
  55. ## term
  56. [[bhagavantu]]
  57. md;
  58. $data['noteMulti'] = <<<'md'
  59. ## heading
  60. [点击](http://127.0.0.1:3000/my/article/para/168-876?mode=edit&channel=00ae2c48-c204-4082-ae79-79ba2740d506&book=168&par=876)
  61. ----
  62. dfef
  63. ```
  64. bla **content**
  65. {{99-556-8-12}}
  66. bla **content**
  67. ```
  68. md;
  69. $data['note'] = '`bla **bold** _em_ bla`';
  70. $data['noteTpl'] = <<<'md'
  71. {{note|trigger=kacayana|text=bla **bold** _em_ bla}}
  72. md;
  73. $data['noteTpl2'] = <<<'md'
  74. {{note|trigger=kacayana|text={{99-556-8-12}}}}
  75. md;
  76. $data['trigger'] = <<<'md'
  77. ## heading
  78. ddd
  79. - title
  80. content-1
  81. - title-2
  82. content-2
  83. aaa bbb
  84. md;
  85. $data['exercise'] = <<<'md'
  86. {{168-916-10-37}}
  87. {{exercise|1|((168-916-10-37))}}
  88. {{exercise|
  89. id=1|
  90. content={{168-916-10-37}}
  91. }}
  92. {{exercise|
  93. id=2|
  94. content=# ddd}}
  95. md;
  96. $data['article'] = <<<'md'
  97. {{article|
  98. type=article|
  99. id=27ade9ad-2d0c-4f66-b857-e9335252cc08|
  100. title=第一章 戒律概说(Vinaya)|
  101. style=modal}}
  102. md;
  103. $data['footnote'] = <<<'md'
  104. # title
  105. content `note content` `note2 content`
  106. md;
  107. $data['paragraph'] = <<<'md'
  108. # title
  109. content
  110. {{168-916-10-37}}
  111. {{168-916-10-37}}
  112. the end
  113. md;
  114. $data['img'] = <<<'md'
  115. # title
  116. content
  117. ![aaa](/images/aaa.jpg)
  118. the end
  119. md;
  120. $data['empty'] = '';
  121. Markdown::driver($this->option('driver'));
  122. $format = $this->option('format');
  123. if (empty($format)) {
  124. $formats = ['react', 'unity', 'text', 'tex', 'html', 'simple'];
  125. } else {
  126. $formats = [$format];
  127. }
  128. foreach ($formats as $format) {
  129. $this->info("format:{$format}");
  130. foreach ($data as $key => $value) {
  131. $_item = $this->argument('item');
  132. if (! empty($_item) && $key !== $_item) {
  133. continue;
  134. }
  135. $mdRender = new MdRender([
  136. 'format' => $format,
  137. 'footnote' => true,
  138. 'paragraph' => true,
  139. ]);
  140. $output = $mdRender->convert($value, ['00ae2c48-c204-4082-ae79-79ba2740d506']);
  141. echo $output;
  142. }
  143. }
  144. return 0;
  145. }
  146. }