2
0

MdRender.php 24 KB

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