TestMdRender.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. class TestMdRender extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. * run php artisan test:md.render term unity
  12. * @var string
  13. */
  14. protected $signature = 'test:md.render {item?} {--format}';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = 'Command description';
  21. /**
  22. * Create a new command instance.
  23. *
  24. * @return void
  25. */
  26. public function __construct()
  27. {
  28. parent::__construct();
  29. }
  30. /**
  31. * Execute the console command.
  32. *
  33. * @return int
  34. */
  35. public function handle()
  36. {
  37. Log::info('md render start item='.$this->argument('item'));
  38. $data = array();
  39. $data['bold'] = <<<md
  40. **三十位** 经
  41. 在[中间]六处为**[[licchavi]]**,在极果为**慧解脱**
  42. md;
  43. $data['sentence'] = <<<md
  44. {{168-916-2-9}}
  45. md;
  46. $data['link'] = <<<md
  47. aa `[link](wikipali.org/aa.php?view=b&c=d)` bb
  48. md;
  49. $data['term'] = <<<md
  50. ## heading
  51. [[bhagavantu]]
  52. ```
  53. test
  54. ```
  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. //$wiki = MdRender::markdown2wiki($data['noteMulti']);
  103. //$xml = MdRender::wiki2xml($wiki,['00ae2c48-c204-4082-ae79-79ba2740d506']);
  104. //$this->info($xml);
  105. //$html = MdRender::markdownToHtml($xml);
  106. //$this->info($html);
  107. //$html = MdRender::xmlQueryId($xml, "1");
  108. //$sent = MdRender::take_sentence($html);
  109. //print_r($sent);
  110. $formats = $this->option('format');
  111. if(empty($format)){
  112. $formats = ['react','unity','text','tex'];
  113. }else{
  114. $formats = [$formats];
  115. }
  116. foreach ($formats as $format) {
  117. $this->info("format:{$format}");
  118. foreach ($data as $key => $value) {
  119. $_item = $this->argument('item');
  120. if(!empty($_item) && $key !==$_item){
  121. continue;
  122. }
  123. echo MdRender::render($value,
  124. ['00ae2c48-c204-4082-ae79-79ba2740d506'],
  125. null,'read','translation',
  126. $contentType="markdown",$format);
  127. }
  128. }
  129. return 0;
  130. }
  131. }