MdRender.php 24 KB

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