MdRender.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  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. return $tplProps[0];
  334. } else {
  335. return $tplProps;
  336. }
  337. } else {
  338. Log::error('tplProps undefine');
  339. return '';
  340. }
  341. break;
  342. }
  343. }
  344. /**
  345. * 将markdown文件中的模版转换为标准的wiki模版
  346. */
  347. private function markdown2wiki(string $markdown): string
  348. {
  349. //$markdown = mb_convert_encoding($markdown,'UTF-8','UTF-8');
  350. $markdown = iconv('UTF-8', 'UTF-8//IGNORE', $markdown);
  351. /**
  352. * nissaya
  353. * aaa=bbb\n
  354. * {{nissaya|aaa|bbb}}
  355. */
  356. if ($this->options['channelType'] === 'nissaya') {
  357. if ($this->options['contentType'] === "json") {
  358. $json = json_decode($markdown);
  359. $nissayaWord = [];
  360. if (is_array($json)) {
  361. foreach ($json as $word) {
  362. if (count($word->sn) === 1) {
  363. //只输出第一层级
  364. $str = "{{nissaya|";
  365. if (isset($word->word->value)) {
  366. $str .= $word->word->value;
  367. }
  368. $str .= "|";
  369. if (isset($word->meaning->value)) {
  370. $str .= $word->meaning->value;
  371. }
  372. $str .= "}}";
  373. $nissayaWord[] = $str;
  374. }
  375. }
  376. } else {
  377. Log::error('json data is not array', ['data' => $markdown]);
  378. }
  379. $markdown = implode('', $nissayaWord);
  380. } else if ($this->options['contentType'] === "markdown") {
  381. $lines = explode("\n", $markdown);
  382. $newLines = array();
  383. foreach ($lines as $line) {
  384. if (strstr($line, '=') === FALSE) {
  385. $newLines[] = $line;
  386. } else {
  387. $nissaya = explode('=', $line);
  388. $meaning = array_slice($nissaya, 1);
  389. $meaning = implode('=', $meaning);
  390. $newLines[] = "{{nissaya|{$nissaya[0]}|{$meaning}}}";
  391. }
  392. }
  393. $markdown = implode("\n", $newLines);
  394. }
  395. }
  396. //$markdown = preg_replace("/\n\n/","<div></div>",$markdown);
  397. /**
  398. * 处理 mermaid
  399. */
  400. if (strpos($markdown, "```mermaid") !== false) {
  401. $lines = explode("\n", $markdown);
  402. $newLines = array();
  403. $mermaidBegin = false;
  404. $mermaidString = array();
  405. foreach ($lines as $line) {
  406. if ($line === "```mermaid") {
  407. $mermaidBegin = true;
  408. $mermaidString = [];
  409. continue;
  410. }
  411. if ($mermaidBegin) {
  412. if ($line === "```") {
  413. $newLines[] = "{{mermaid|" . base64_encode(\json_encode($mermaidString)) . "}}";
  414. $mermaidBegin = false;
  415. } else {
  416. $mermaidString[] = $line;
  417. }
  418. } else {
  419. $newLines[] = $line;
  420. }
  421. }
  422. $markdown = implode("\n", $newLines);
  423. }
  424. /**
  425. * 替换换行符
  426. * react 无法处理 <br> 替换为<div></div>代替换行符作用
  427. */
  428. //$markdown = str_replace('<br>','<div></div>',$markdown);
  429. /**
  430. * markdown -> html
  431. */
  432. /*
  433. $html = MdRender::fixHtml($html);
  434. */
  435. #替换术语
  436. $pattern = "/\[\[(.+?)\]\]/";
  437. $replacement = '{{term|$1}}';
  438. $markdown = preg_replace($pattern, $replacement, $markdown);
  439. #替换句子模版
  440. $pattern = "/\{\{([0-9].+?)\}\}/";
  441. $replacement = '{{sent|id=$1}}';
  442. $markdown = preg_replace($pattern, $replacement, $markdown);
  443. /**
  444. * 替换多行注释
  445. * ```
  446. * bla
  447. * bla
  448. * ```
  449. * {{note|
  450. * bla
  451. * bla
  452. * }}
  453. */
  454. if (strpos($markdown, "```\n") !== false) {
  455. $lines = explode("\n", $markdown);
  456. $newLines = array();
  457. $noteBegin = false;
  458. $noteString = array();
  459. foreach ($lines as $line) {
  460. if ($noteBegin) {
  461. if ($line === "```") {
  462. $newLines[] = "}}";
  463. $noteBegin = false;
  464. } else {
  465. $newLines[] = $line;
  466. }
  467. } else {
  468. if ($line === "```") {
  469. $noteBegin = true;
  470. $newLines[] = "{{note|";
  471. continue;
  472. } else {
  473. $newLines[] = $line;
  474. }
  475. }
  476. }
  477. if ($noteBegin) {
  478. $newLines[] = "}}";
  479. }
  480. $markdown = implode("\n", $newLines);
  481. }
  482. /**
  483. * 替换单行注释
  484. * `bla bla`
  485. * {{note|bla}}
  486. */
  487. $pattern = "/`(.+?)`/";
  488. $replacement = '{{note|$1}}';
  489. $markdown = preg_replace($pattern, $replacement, $markdown);
  490. return $markdown;
  491. }
  492. private function markdownToHtml($markdown)
  493. {
  494. $markdown = str_replace('MdTpl', 'mdtpl', $markdown);
  495. $markdown = str_replace(['<param', '</param>'], ['<span', '</span>'], $markdown);
  496. $html = Markdown::render($markdown);
  497. if ($this->options['format'] === 'react') {
  498. $html = $this->fixHtml($html);
  499. }
  500. $html = str_replace('<hr>', '<hr />', $html);
  501. //给H1-6 添加uuid
  502. for ($i = 1; $i < 7; $i++) {
  503. if (strpos($html, "<h{$i}>") === false) {
  504. continue;
  505. }
  506. $output = array();
  507. $input = $html;
  508. $hPos = strpos($input, "<h{$i}>");
  509. while ($hPos !== false) {
  510. $output[] = substr($input, 0, $hPos);
  511. $output[] = "<h{$i} id='" . Str::uuid() . "'>";
  512. $input = substr($input, $hPos + 4);
  513. $hPos = strpos($input, "<h{$i}>");
  514. }
  515. $output[] = $input;
  516. $html = implode('', $output);
  517. }
  518. $html = str_replace('mdtpl', 'MdTpl', $html);
  519. return $html;
  520. }
  521. private function fixHtml($html)
  522. {
  523. $doc = new \DOMDocument();
  524. libxml_use_internal_errors(true);
  525. $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8");
  526. $doc->loadHTML('<span>' . $html . '</span>', LIBXML_NOERROR | LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
  527. $fixed = $doc->saveHTML();
  528. $fixed = mb_convert_encoding($fixed, "UTF-8", 'HTML-ENTITIES');
  529. return $fixed;
  530. }
  531. public static function init()
  532. {
  533. $GLOBALS["MdRenderStack"] = 0;
  534. }
  535. public function convert($markdown, $channelId = [], $queryId = null)
  536. {
  537. if (isset($GLOBALS["MdRenderStack"]) && is_numeric($GLOBALS["MdRenderStack"])) {
  538. $GLOBALS["MdRenderStack"]++;
  539. } else {
  540. $GLOBALS["MdRenderStack"] = 1;
  541. }
  542. if ($GLOBALS["MdRenderStack"] < 3) {
  543. $output = $this->_convert($markdown, $channelId, $queryId);
  544. } else {
  545. $output = $markdown;
  546. }
  547. $GLOBALS["MdRenderStack"]--;
  548. return $output;
  549. }
  550. private function _convert($markdown, $channelId = [], $queryId = null)
  551. {
  552. if (empty($markdown)) {
  553. switch ($this->options['format']) {
  554. case 'react':
  555. return "<span></span>";
  556. break;
  557. default:
  558. return "";
  559. break;
  560. }
  561. }
  562. $wiki = $this->markdown2wiki($markdown);
  563. $wiki = $this->preprocessingForParagraph($wiki);
  564. $markdownWithTpl = $this->wiki2xml($wiki, $channelId);
  565. if (!is_null($queryId)) {
  566. $html = $this->xmlQueryId($markdownWithTpl, $queryId);
  567. }
  568. $html = $this->markdownToHtml($markdownWithTpl);
  569. //后期处理
  570. $output = '';
  571. switch ($this->options['format']) {
  572. case 'react':
  573. //生成可展开组件
  574. $html = str_replace("<div/>", "<div></div>", $html);
  575. $pattern = '/<li><div>(.+?)<\/div><\/li>/';
  576. $replacement = '<li><MdTpl name="toggle" tpl="toggle" props=""><div>$1</div></MdTpl></li>';
  577. $output = preg_replace($pattern, $replacement, $html);
  578. break;
  579. case 'text':
  580. case 'simple':
  581. case 'prompt':
  582. $html = strip_tags($html);
  583. $output = htmlspecialchars_decode($html, ENT_QUOTES);
  584. //$output = html_entity_decode($html);
  585. break;
  586. case 'tex':
  587. $html = strip_tags($html);
  588. $output = htmlspecialchars_decode($html, ENT_QUOTES);
  589. //$output = html_entity_decode($html);
  590. break;
  591. case 'unity':
  592. $html = str_replace(['<strong>', '</strong>', '<em>', '</em>'], ['[%b%]', '[%/b%]', '[%i%]', '[%/i%]'], $html);
  593. $html = strip_tags($html);
  594. $html = str_replace(['[%b%]', '[%/b%]', '[%i%]', '[%/i%]'], ['<b>', '</b>', '<i>', '</i>'], $html);
  595. $output = htmlspecialchars_decode($html, ENT_QUOTES);
  596. break;
  597. case 'html':
  598. $output = htmlspecialchars_decode($html, ENT_QUOTES);
  599. //处理脚注
  600. if ($this->options['footnote'] && isset($GLOBALS['note']) && count($GLOBALS['note']) > 0) {
  601. $output .= '<div><h1>endnote</h1>';
  602. foreach ($GLOBALS['note'] as $footnote) {
  603. $output .= '<p><a name="footnote-' . $footnote['sn'] . '">[' . $footnote['sn'] . ']</a> ' . $footnote['content'] . '</p>';
  604. }
  605. $output .= '</div>';
  606. unset($GLOBALS['note']);
  607. }
  608. //处理图片链接
  609. $output = str_replace('<img src="', '<img src="' . config('app.url'), $output);
  610. break;
  611. case 'markdown':
  612. //处理脚注
  613. $footnotes = array();
  614. if ($this->options['footnote'] && isset($GLOBALS['note']) && count($GLOBALS['note']) > 0) {
  615. foreach ($GLOBALS['note'] as $footnote) {
  616. $footnotes[] = '[^' . $footnote['sn'] . ']: ' . $footnote['content'];
  617. }
  618. unset($GLOBALS['note']);
  619. }
  620. //处理图片链接
  621. $output = str_replace('/attachments/', config('app.url') . "/attachments/", $markdownWithTpl);
  622. $output = $output . "\n\n" . implode("\n\n", $footnotes);
  623. break;
  624. }
  625. return $output;
  626. }
  627. /**
  628. * string[] $channelId
  629. */
  630. public static function render($markdown, $channelId, $queryId = null, $mode = 'read', $channelType = 'translation', $contentType = "markdown", $format = 'react')
  631. {
  632. $mdRender = new MdRender(
  633. [
  634. 'mode' => $mode,
  635. 'channelType' => $channelType,
  636. 'contentType' => $contentType,
  637. 'format' => $format
  638. ]
  639. );
  640. $output = $mdRender->convert($markdown, $channelId, $queryId);
  641. return $output;
  642. }
  643. }