MdRender.php 24 KB

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