TestMdRender.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. * run php artisan test:md.render term unity
  13. * @var string
  14. */
  15. protected $signature = 'test:md.render {item?} {--format=} {--driver=str}';
  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['empty'] = '';
  102. Markdown::driver($this->option('driver'));
  103. $format = $this->option('format');
  104. if(empty($format)){
  105. $formats = ['react','unity','text','tex','html'];
  106. }else{
  107. $formats = [$format];
  108. }
  109. foreach ($formats as $format) {
  110. $this->info("format:{$format}");
  111. foreach ($data as $key => $value) {
  112. $_item = $this->argument('item');
  113. if(!empty($_item) && $key !==$_item){
  114. continue;
  115. }
  116. echo MdRender::render($value,
  117. ['00ae2c48-c204-4082-ae79-79ba2740d506'],
  118. null,'read','translation',
  119. $contentType="markdown",$format);
  120. }
  121. }
  122. return 0;
  123. }
  124. }