MdRender.php 24 KB

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