2
0

TestMdRender.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. if(\App\Tools\Tools::isStop()){
  38. return 0;
  39. }
  40. Log::info('md render start item='.$this->argument('item'));
  41. $data = array();
  42. $data['bold'] = <<<md
  43. **三十位** 经
  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. ## heading
  54. [[bhagavantu]]
  55. ```
  56. test
  57. ```
  58. md;
  59. $data['noteMulti'] = <<<md
  60. ## heading
  61. [点击](http://127.0.0.1:3000/my/article/para/168-876?mode=edit&channel=00ae2c48-c204-4082-ae79-79ba2740d506&book=168&par=876)
  62. ----
  63. dfef
  64. ```
  65. bla **content**
  66. {{99-556-8-12}}
  67. bla **content**
  68. ```
  69. md;
  70. $data['note'] = '`bla **bold** _em_ bla`';
  71. $data['noteTpl'] = <<<md
  72. {{note|trigger=kacayana|text=bla **bold** _em_ bla}}
  73. md;
  74. $data['noteTpl2'] = <<<md
  75. {{note|trigger=kacayana|text={{99-556-8-12}}}}
  76. md;
  77. $data['trigger'] = <<<md
  78. ## heading
  79. ddd
  80. - title
  81. content-1
  82. - title-2
  83. content-2
  84. aaa bbb
  85. md;
  86. $data['exercise'] = <<<md
  87. {{168-916-10-37}}
  88. {{exercise|1|((168-916-10-37))}}
  89. {{exercise|
  90. id=1|
  91. content={{168-916-10-37}}
  92. }}
  93. {{exercise|
  94. id=2|
  95. content=# ddd}}
  96. md;
  97. $data['article'] = <<<md
  98. {{article|
  99. type=article|
  100. id=27ade9ad-2d0c-4f66-b857-e9335252cc08|
  101. title=第一章 戒律概说(Vinaya)|
  102. style=modal}}
  103. md;
  104. $data['empty'] = '';
  105. //$wiki = MdRender::markdown2wiki($data['noteMulti']);
  106. //$xml = MdRender::wiki2xml($wiki,['00ae2c48-c204-4082-ae79-79ba2740d506']);
  107. //$this->info($xml);
  108. //$html = MdRender::markdownToHtml($xml);
  109. //$this->info($html);
  110. //$html = MdRender::xmlQueryId($xml, "1");
  111. //$sent = MdRender::take_sentence($html);
  112. //print_r($sent);
  113. $formats = $this->option('format');
  114. if(empty($format)){
  115. $formats = ['react','unity','text','tex'];
  116. }else{
  117. $formats = [$formats];
  118. }
  119. foreach ($formats as $format) {
  120. $this->info("format:{$format}");
  121. foreach ($data as $key => $value) {
  122. $_item = $this->argument('item');
  123. if(!empty($_item) && $key !==$_item){
  124. continue;
  125. }
  126. echo MdRender::render($value,
  127. ['00ae2c48-c204-4082-ae79-79ba2740d506'],
  128. null,'read','translation',
  129. $contentType="markdown",$format);
  130. }
  131. }
  132. return 0;
  133. }
  134. }