2
0

TestMdRender.php 3.9 KB

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