MdRender.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. <?php
  2. namespace App\Http\Api;
  3. use Illuminate\Support\Str;
  4. use App\Models\Channel;
  5. use Illuminate\Support\Facades\Log;
  6. use App\Tools\Markdown;
  7. //use App\Services\TemplateRender;
  8. define("STACK_DEEP", 8);
  9. class MdRender
  10. {
  11. /**
  12. * 文字渲染模式
  13. * read 阅读模式
  14. * edit 编辑模式
  15. */
  16. protected $options = [
  17. 'mode' => 'read',
  18. 'channelType' => 'translation',
  19. 'contentType' => "markdown",
  20. 'format' => 'react',
  21. 'debug' => [],
  22. 'studioId' => null,
  23. 'lang' => 'zh-Hans',
  24. 'footnote' => false,
  25. 'paragraph' => false,
  26. ];
  27. public function __construct($options = [])
  28. {
  29. foreach ($options as $key => $value) {
  30. $this->options[$key] = $value;
  31. }
  32. }
  33. /**
  34. * 将句子模版组成的段落复制一份,为了实现巴汉逐段对读
  35. */
  36. private function preprocessingForParagraph($input)
  37. {
  38. if (!$this->options['paragraph']) {
  39. return $input;
  40. }
  41. $paragraphs = explode("\n\n", $input);
  42. $output = [];
  43. foreach ($paragraphs as $key => $paragraph) {
  44. # 判断是否是纯粹的句子模版
  45. $pattern = "/\{\{sent\|id=([0-9].+?)\}\}/";
  46. $replacement = '';
  47. $space = preg_replace($pattern, $replacement, $paragraph);
  48. $space = str_replace('>', '', $space);
  49. if (empty(trim($space))) {
  50. $output[] = str_replace('}}', '|text=origin}}', $paragraph);
  51. $output[] = str_replace('}}', '|text=translation}}', $paragraph);
  52. } else {
  53. $output[] = $paragraph;
  54. }
  55. }
  56. return implode("\n\n", $output);
  57. }
  58. /**
  59. * 按照{{}}把字符串切分成三个部分。模版之前的,模版,和模版之后的
  60. */
  61. private function tplSplit($tpl)
  62. {
  63. $before = strpos($tpl, '{{');
  64. if ($before === FALSE) {
  65. //未找到
  66. return ['data' => [$tpl, '', ''], 'error' => 0];
  67. } else {
  68. $pointer = $before;
  69. $stack = array();
  70. $stack[] = $pointer;
  71. $after = substr($tpl, $pointer + 2);
  72. while (!empty($after) && count($stack) > 0 && count($stack) < STACK_DEEP) {
  73. $nextBegin = strpos($after, "{{");
  74. $nextEnd = strpos($after, "}}");
  75. if ($nextBegin !== FALSE) {
  76. if ($nextBegin < $nextEnd) {
  77. //有嵌套找到最后一个}}
  78. $pointer = $pointer + 2 + $nextBegin;
  79. $stack[] = $pointer;
  80. $after = substr($tpl, $pointer + 2);
  81. } else if ($nextEnd !== FALSE) {
  82. //无嵌套有结束
  83. $pointer = $pointer + 2 + $nextEnd;
  84. array_pop($stack);
  85. $after = substr($tpl, $pointer + 2);
  86. } else {
  87. //无结束符 没找到
  88. break;
  89. }
  90. } else if ($nextEnd !== FALSE) {
  91. $pointer = $pointer + 2 + $nextEnd;
  92. array_pop($stack);
  93. $after = substr($tpl, $pointer + 2);
  94. } else {
  95. //没找到
  96. break;
  97. }
  98. }
  99. if (count($stack) > 0) {
  100. if (count($stack) === STACK_DEEP) {
  101. return ['data' => [$tpl, '', ''], 'error' => 2];
  102. } else {
  103. //未关闭
  104. return ['data' => [$tpl, '', ''], 'error' => 1];
  105. }
  106. } else {
  107. return [
  108. 'data' =>
  109. [
  110. substr($tpl, 0, $before),
  111. substr($tpl, $before, $pointer - $before + 2),
  112. substr($tpl, $pointer + 2)
  113. ],
  114. 'error' => 0
  115. ];
  116. }
  117. }
  118. }
  119. private function wiki2xml(string $wiki, $channelId = []): string
  120. {
  121. /**
  122. * 渲染markdown里面的模版
  123. */
  124. $remain = $wiki;
  125. $buffer = array();
  126. do {
  127. $arrWiki = $this->tplSplit($remain);
  128. $buffer[] = $arrWiki['data'][0];
  129. $tpl = $arrWiki['data'][1];
  130. if (!empty($tpl)) {
  131. /**
  132. * 处理模版 提取参数
  133. */
  134. $tpl = str_replace("|\n", "|", $tpl);
  135. $pattern = "/\{\{(.+?)\|/";
  136. $replacement = '<MdTpl class="tpl" name="$1"><param>';
  137. $tpl = preg_replace($pattern, $replacement, $tpl);
  138. $tpl = str_replace("}}", "</param></MdTpl>", $tpl);
  139. $tpl = str_replace("|", "</param><param>", $tpl);
  140. /**
  141. * 替换变量名
  142. */
  143. $pattern = "/<param>([a-z]+?)=/";
  144. $replacement = '<param name="$1">';
  145. $tpl = preg_replace($pattern, $replacement, $tpl);
  146. //tpl to react
  147. $tpl = str_replace('<param', '<span class="param"', $tpl);
  148. $tpl = str_replace('</param>', '</span>', $tpl);
  149. $tpl = $this->xml2tpl($tpl, $channelId);
  150. $buffer[] = $tpl;
  151. }
  152. $remain = $arrWiki['data'][2];
  153. } while (!empty($remain));
  154. $html = implode('', $buffer);
  155. return $html;
  156. }
  157. private function xmlQueryId(string $xml, string $id): string
  158. {
  159. try {
  160. $dom = simplexml_load_string($xml);
  161. } catch (\Exception $e) {
  162. Log::error($e);
  163. return "<div></div>";
  164. }
  165. $tpl_list = $dom->xpath('//MdTpl');
  166. foreach ($tpl_list as $key => $tpl) {
  167. foreach ($tpl->children() as $param) {
  168. # 处理每个参数
  169. if ($param->getName() === "param") {
  170. foreach ($param->attributes() as $pa => $pa_value) {
  171. $pValue = $pa_value->__toString();
  172. if ($pa === "name" && $pValue === "id") {
  173. if ($param->__toString() === $id) {
  174. return $tpl->asXML();
  175. }
  176. }
  177. }
  178. }
  179. }
  180. }
  181. return "<div></div>";
  182. }
  183. public static function take_sentence(string $xml): array
  184. {
  185. $output = [];
  186. try {
  187. $dom = simplexml_load_string($xml);
  188. } catch (\Exception $e) {
  189. Log::error($e);
  190. return $output;
  191. }
  192. $tpl_list = $dom->xpath('//MdTpl');
  193. foreach ($tpl_list as $key => $tpl) {
  194. foreach ($tpl->attributes() as $a => $a_value) {
  195. if ($a === "name") {
  196. if ($a_value->__toString() === "sent") {
  197. foreach ($tpl->children() as $param) {
  198. # 处理每个参数
  199. if ($param->getName() === "param") {
  200. $sent = $param->__toString();
  201. if (!empty($sent)) {
  202. $output[] = $sent;
  203. break;
  204. }
  205. }
  206. }
  207. }
  208. }
  209. }
  210. }
  211. return $output;
  212. }
  213. private function xml2tpl(string $xml, $channelId = []): string
  214. {
  215. /**
  216. * 解析xml
  217. * 获取模版参数
  218. * 生成react 组件参数
  219. */
  220. try {
  221. //$dom = simplexml_load_string($xml);
  222. $doc = new \DOMDocument();
  223. $xml = str_replace('MdTpl', 'dfn', $xml);
  224. $xml = mb_convert_encoding($xml, 'HTML-ENTITIES', "UTF-8");
  225. $ok = $doc->loadHTML($xml, LIBXML_NOERROR | LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
  226. } catch (\Exception $e) {
  227. Log::error($e);
  228. Log::error($xml);
  229. return "<span>xml解析错误{$e}</span>";
  230. }
  231. if (!$ok) {
  232. return "<span>xml解析错误</span>";
  233. }
  234. /*
  235. if(!$dom){
  236. Log::error($xml);
  237. return "<span>xml解析错误</span>";
  238. }
  239. */
  240. $tpl_list = $doc->getElementsByTagName('dfn');
  241. foreach ($tpl_list as $key => $tpl) {
  242. /**
  243. * 遍历 MdTpl 处理参数
  244. */
  245. $props = [];
  246. $tpl_name = '';
  247. foreach ($tpl->attributes as $a => $a_value) {
  248. if ($a_value->nodeName === "name") {
  249. $tpl_name = $a_value->nodeValue;
  250. break;
  251. }
  252. }
  253. $param_id = 0;
  254. $child = $tpl->firstChild;
  255. while ($child) {
  256. # 处理每个参数
  257. if ($child->nodeName === "span") {
  258. $param_id++;
  259. $paramName = "";
  260. foreach ($child->attributes as $pa => $pa_value) {
  261. if ($pa_value->nodeName === "name") {
  262. $nodeText = $pa_value->nodeValue;
  263. $props["{$nodeText}"] = $child->nodeValue;
  264. $paramName = $pa_value;
  265. }
  266. }
  267. if (empty($paramName)) {
  268. foreach ($child->childNodes as $param_child) {
  269. # code...
  270. if ($param_child->nodeType === 3) {
  271. $props["{$param_id}"] = $param_child->nodeValue;
  272. }
  273. }
  274. }
  275. }
  276. $child = $child->nextSibling;
  277. }
  278. /**
  279. * 生成模版参数
  280. *
  281. */
  282. //TODO 判断$channelId里面的是否都是uuid
  283. $channelInfo = [];
  284. foreach ($channelId as $key => $id) {
  285. $channelInfo[] = Channel::where('uid', $id)->first();
  286. }
  287. $tplRender = new TemplateRender(
  288. $props,
  289. $channelInfo,
  290. $this->options['mode'],
  291. $this->options['format'],
  292. $this->options['studioId'],
  293. $this->options['debug'],
  294. $this->options['lang'],
  295. );
  296. $tplRender->options($this->options);
  297. $tplProps = $tplRender->render($tpl_name);
  298. /*
  299. $tplProps = TemplateRender::name($tpl_name)
  300. ->options($this->options)
  301. ->param($props)
  302. ->render();
  303. */
  304. if ($this->options['format'] === 'react' && $tplProps) {
  305. $props = $doc->createAttribute("props");
  306. $props->nodeValue = $tplProps['props'];
  307. $tpl->appendChild($props);
  308. $attTpl = $doc->createAttribute("tpl");
  309. $attTpl->nodeValue = $tplProps['tpl'];
  310. $tpl->appendChild($attTpl);
  311. $htmlElement = $doc->createElement($tplProps['tag']);
  312. $htmlElement->nodeValue = $tplProps['html'];
  313. $tpl->appendChild($htmlElement);
  314. }
  315. }
  316. $html = $doc->saveHTML();
  317. $html = str_replace(['<dfn', '</dfn>'], ['<MdTpl', '</MdTpl>'], $html);
  318. switch ($this->options['format']) {
  319. case 'react':
  320. return trim($html);
  321. break;
  322. case 'unity':
  323. if ($tplProps) {
  324. return "{{" . "{$tplProps['tpl']}|{$tplProps['props']}" . "}}";
  325. } else {
  326. return '';
  327. }
  328. break;
  329. default:
  330. /**html tex text simple markdown */
  331. if (isset($tplProps)) {
  332. if (is_array($tplProps)) {
  333. if (isset($tplProps[0])) {
  334. return $tplProps[0];
  335. } else {
  336. return '';
  337. }
  338. } else {
  339. return $tplProps;
  340. }
  341. } else {
  342. Log::error('tplProps undefine');
  343. return '';
  344. }
  345. break;
  346. }
  347. }
  348. /**
  349. * 将markdown文件中的模版转换为标准的wiki模版
  350. */
  351. private function markdown2wiki(string $markdown): string
  352. {
  353. //$markdown = mb_convert_encoding($markdown,'UTF-8','UTF-8');
  354. $markdown = iconv('UTF-8', 'UTF-8//IGNORE', $markdown);
  355. /**
  356. * nissaya
  357. * aaa=bbb\n
  358. * {{nissaya|aaa|bbb}}
  359. */
  360. if ($this->options['channelType'] === 'nissaya') {
  361. if ($this->options['contentType'] === "json") {
  362. $json = json_decode($markdown);
  363. $nissayaWord = [];
  364. if (is_array($json)) {
  365. foreach ($json as $word) {
  366. if (count($word->sn) === 1) {
  367. //只输出第一层级
  368. $str = "{{nissaya|";
  369. if (isset($word->word->value)) {
  370. $str .= $word->word->value;
  371. }
  372. $str .= "|";
  373. if (isset($word->meaning->value)) {
  374. $str .= $word->meaning->value;
  375. }
  376. $str .= "}}";
  377. $nissayaWord[] = $str;
  378. }
  379. }
  380. } else {
  381. Log::error('json data is not array', ['data' => $markdown]);
  382. }
  383. $markdown = implode('', $nissayaWord);
  384. } else if ($this->options['contentType'] === "markdown") {
  385. $lines = explode("\n", $markdown);
  386. $newLines = array();
  387. foreach ($lines as $line) {
  388. if (
  389. strstr($line, '=') === FALSE &&
  390. strstr($line, '$') === FALSE
  391. ) {
  392. $newLines[] = $line;
  393. } else {
  394. $line = str_replace('$', '=', $line);
  395. $nissaya = explode('=', $line);
  396. $meaning = array_slice($nissaya, 1);
  397. $meaning = implode('=', $meaning);
  398. $newLines[] = "{{nissaya|{$nissaya[0]}|{$meaning}}}";
  399. }
  400. }
  401. $markdown = implode("\n", $newLines);
  402. }
  403. }
  404. //$markdown = preg_replace("/\n\n/","<div></div>",$markdown);
  405. /**
  406. * 处理 mermaid
  407. */
  408. if (strpos($markdown, "```mermaid") !== false) {
  409. $lines = explode("\n", $markdown);
  410. $newLines = array();
  411. $mermaidBegin = false;
  412. $mermaidString = array();
  413. foreach ($lines as $line) {
  414. if ($line === "```mermaid") {
  415. $mermaidBegin = true;
  416. $mermaidString = [];
  417. continue;
  418. }
  419. if ($mermaidBegin) {
  420. if ($line === "```") {
  421. $newLines[] = "{{mermaid|" . base64_encode(\json_encode($mermaidString)) . "}}";
  422. $mermaidBegin = false;
  423. } else {
  424. $mermaidString[] = $line;
  425. }
  426. } else {
  427. $newLines[] = $line;
  428. }
  429. }
  430. $markdown = implode("\n", $newLines);
  431. }
  432. /**
  433. * 替换换行符
  434. * react 无法处理 <br> 替换为<div></div>代替换行符作用
  435. */
  436. //$markdown = str_replace('<br>','<div></div>',$markdown);
  437. /**
  438. * markdown -> html
  439. */
  440. /*
  441. $html = MdRender::fixHtml($html);
  442. */
  443. #替换术语
  444. $pattern = "/\[\[(.+?)\]\]/";
  445. $replacement = '{{term|$1}}';
  446. $markdown = preg_replace($pattern, $replacement, $markdown);
  447. #替换句子模版
  448. $pattern = "/\{\{([0-9].+?)\}\}/";
  449. $replacement = '{{sent|id=$1}}';
  450. $markdown = preg_replace($pattern, $replacement, $markdown);
  451. /**
  452. * 替换多行注释
  453. * ```
  454. * bla
  455. * bla
  456. * ```
  457. * {{note|
  458. * bla
  459. * bla
  460. * }}
  461. */
  462. if (strpos($markdown, "```\n") !== false) {
  463. $lines = explode("\n", $markdown);
  464. $newLines = array();
  465. $noteBegin = false;
  466. $noteString = array();
  467. foreach ($lines as $line) {
  468. if ($noteBegin) {
  469. if ($line === "```") {
  470. $newLines[] = "}}";
  471. $noteBegin = false;
  472. } else {
  473. $newLines[] = $line;
  474. }
  475. } else {
  476. if ($line === "```") {
  477. $noteBegin = true;
  478. $newLines[] = "{{note|";
  479. continue;
  480. } else {
  481. $newLines[] = $line;
  482. }
  483. }
  484. }
  485. if ($noteBegin) {
  486. $newLines[] = "}}";
  487. }
  488. $markdown = implode("\n", $newLines);
  489. }
  490. /**
  491. * 替换单行注释
  492. * `bla bla`
  493. * {{note|bla}}
  494. */
  495. $pattern = "/`(.+?)`/";
  496. $replacement = '{{note|$1}}';
  497. $markdown = preg_replace($pattern, $replacement, $markdown);
  498. return $markdown;
  499. }
  500. private function markdownToHtml($markdown)
  501. {
  502. $markdown = str_replace('MdTpl', 'mdtpl', $markdown);
  503. $markdown = str_replace(['<param', '</param>'], ['<span', '</span>'], $markdown);
  504. $html = Markdown::render($markdown);
  505. if ($this->options['format'] === 'react') {
  506. $html = $this->fixHtml($html);
  507. }
  508. $html = str_replace('<hr>', '<hr />', $html);
  509. //给H1-6 添加uuid
  510. for ($i = 1; $i < 7; $i++) {
  511. if (strpos($html, "<h{$i}>") === false) {
  512. continue;
  513. }
  514. $output = array();
  515. $input = $html;
  516. $hPos = strpos($input, "<h{$i}>");
  517. while ($hPos !== false) {
  518. $output[] = substr($input, 0, $hPos);
  519. $output[] = "<h{$i} id='" . Str::uuid() . "'>";
  520. $input = substr($input, $hPos + 4);
  521. $hPos = strpos($input, "<h{$i}>");
  522. }
  523. $output[] = $input;
  524. $html = implode('', $output);
  525. }
  526. $html = str_replace('mdtpl', 'MdTpl', $html);
  527. return $html;
  528. }
  529. private function fixHtml($html)
  530. {
  531. $doc = new \DOMDocument();
  532. libxml_use_internal_errors(true);
  533. $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8");
  534. $doc->loadHTML('<span>' . $html . '</span>', LIBXML_NOERROR | LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
  535. $fixed = $doc->saveHTML();
  536. $fixed = mb_convert_encoding($fixed, "UTF-8", 'HTML-ENTITIES');
  537. return $fixed;
  538. }
  539. public static function init()
  540. {
  541. $GLOBALS["MdRenderStack"] = 0;
  542. }
  543. public function convert($markdown, $channelId = [], $queryId = null)
  544. {
  545. if (isset($GLOBALS["MdRenderStack"]) && is_numeric($GLOBALS["MdRenderStack"])) {
  546. $GLOBALS["MdRenderStack"]++;
  547. } else {
  548. $GLOBALS["MdRenderStack"] = 1;
  549. }
  550. if ($GLOBALS["MdRenderStack"] < 3) {
  551. $output = $this->_convert($markdown, $channelId, $queryId);
  552. } else {
  553. $output = $markdown;
  554. }
  555. $GLOBALS["MdRenderStack"]--;
  556. return $output;
  557. }
  558. private function _convert($markdown, $channelId = [], $queryId = null)
  559. {
  560. if (empty($markdown)) {
  561. switch ($this->options['format']) {
  562. case 'react':
  563. return "<span></span>";
  564. break;
  565. default:
  566. return "";
  567. break;
  568. }
  569. }
  570. $wiki = $this->markdown2wiki($markdown);
  571. $wiki = $this->preprocessingForParagraph($wiki);
  572. $markdownWithTpl = $this->wiki2xml($wiki, $channelId);
  573. if (!is_null($queryId)) {
  574. $html = $this->xmlQueryId($markdownWithTpl, $queryId);
  575. }
  576. $html = $this->markdownToHtml($markdownWithTpl);
  577. //后期处理
  578. $output = '';
  579. switch ($this->options['format']) {
  580. case 'react':
  581. //生成可展开组件
  582. $html = str_replace("<div/>", "<div></div>", $html);
  583. $pattern = '/<li><div>(.+?)<\/div><\/li>/';
  584. $replacement = '<li><MdTpl name="toggle" tpl="toggle" props=""><div>$1</div></MdTpl></li>';
  585. $output = preg_replace($pattern, $replacement, $html);
  586. break;
  587. case 'text':
  588. case 'simple':
  589. case 'prompt':
  590. $html = strip_tags($html);
  591. $output = htmlspecialchars_decode($html, ENT_QUOTES);
  592. //$output = html_entity_decode($html);
  593. break;
  594. case 'tex':
  595. $html = strip_tags($html);
  596. $output = htmlspecialchars_decode($html, ENT_QUOTES);
  597. //$output = html_entity_decode($html);
  598. break;
  599. case 'unity':
  600. $html = str_replace(['<strong>', '</strong>', '<em>', '</em>'], ['[%b%]', '[%/b%]', '[%i%]', '[%/i%]'], $html);
  601. $html = strip_tags($html);
  602. $html = str_replace(['[%b%]', '[%/b%]', '[%i%]', '[%/i%]'], ['<b>', '</b>', '<i>', '</i>'], $html);
  603. $output = htmlspecialchars_decode($html, ENT_QUOTES);
  604. break;
  605. case 'html':
  606. $output = htmlspecialchars_decode($html, ENT_QUOTES);
  607. //处理脚注
  608. if ($this->options['footnote'] && isset($GLOBALS['note']) && count($GLOBALS['note']) > 0) {
  609. $output .= '<div><h1>endnote</h1>';
  610. foreach ($GLOBALS['note'] as $footnote) {
  611. $output .= '<p><a name="footnote-' . $footnote['sn'] . '">[' . $footnote['sn'] . ']</a> ' . $footnote['content'] . '</p>';
  612. }
  613. $output .= '</div>';
  614. unset($GLOBALS['note']);
  615. }
  616. //处理图片链接
  617. $output = str_replace('<img src="', '<img src="' . config('app.url'), $output);
  618. break;
  619. case 'markdown':
  620. //处理脚注
  621. $footnotes = array();
  622. if ($this->options['footnote'] && isset($GLOBALS['note']) && count($GLOBALS['note']) > 0) {
  623. foreach ($GLOBALS['note'] as $footnote) {
  624. $footnotes[] = '[^' . $footnote['sn'] . ']: ' . $footnote['content'];
  625. }
  626. unset($GLOBALS['note']);
  627. }
  628. //处理图片链接
  629. $output = str_replace('/attachments/', config('app.url') . "/attachments/", $markdownWithTpl);
  630. $output = $output . "\n\n" . implode("\n\n", $footnotes);
  631. break;
  632. }
  633. return $output;
  634. }
  635. /**
  636. * string[] $channelId
  637. */
  638. public static function render($markdown, $channelId, $queryId = null, $mode = 'read', $channelType = 'translation', $contentType = "markdown", $format = 'react')
  639. {
  640. $mdRender = new MdRender(
  641. [
  642. 'mode' => $mode,
  643. 'channelType' => $channelType,
  644. 'contentType' => $contentType,
  645. 'format' => $format
  646. ]
  647. );
  648. $output = $mdRender->convert($markdown, $channelId, $queryId);
  649. return $output;
  650. }
  651. }