TestMdRender.php 3.6 KB

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