💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
## **CommonMark\Parse**(string`$markdown_content`[,int`$options`] ) :CommonMark\\Node >[info]解析markdown语句 返回节点CommonMark\\Node 参数: `options` **`CommonMark\Parser\Normal`**([integer](https://www.php.net/manual/en/language.types.integer.php)) **`CommonMark\Parser\Normalize`**([integer](https://www.php.net/manual/en/language.types.integer.php)) **`CommonMark\Parser\ValidateUTF8`**([integer](https://www.php.net/manual/en/language.types.integer.php)) **`CommonMark\Parser\Smart`**([integer](https://www.php.net/manual/en/language.types.integer.php)) ``` $node=CommonMark\Parse("## **标题**"); var_dump($node); 结果: CommonMark\Node\Document Object ( [children] => Array ( [0] => CommonMark\Node\Heading Object ( [children] => Array ( [0] => CommonMark\Node\Text\Strong Object ( [children] => Array ( [0] => CommonMark\Node\Text Object ( [literal] => 标题 ) ) ) ) ) ) ) ``` ***** ## **CommonMark\Render**(CommonMark\\Node`$node`\[,int`$options`\[,int`$width`\]\] ) :string >[info]渲染节点为markdown语句 参数: `options` **`CommonMark\Render\Normal`**([integer](https://www.php.net/manual/en/language.types.integer.php)) **`CommonMark\Render\SourcePos`**([integer](https://www.php.net/manual/en/language.types.integer.php)) **`CommonMark\Render\HardBreaks`**([integer](https://www.php.net/manual/en/language.types.integer.php)) **`CommonMark\Render\Safe`**([integer](https://www.php.net/manual/en/language.types.integer.php)) **`CommonMark\Render\NoBreaks`**([integer](https://www.php.net/manual/en/language.types.integer.php)) ``` $heading=new \CommonMark\Node\Heading(2); $r=CommonMark\Render($heading); var_dump($r);//## ``` 例子2: ``` $heading=new CommonMark\Node\Heading(2);//默认值为1 一个# 值为2则两个# $child=new CommonMark\Node\Text('title'); $heading->appendChild($child); $render=CommonMark\Render($heading); var_dump($render);//## title ``` 例子3: ``` $heading=new CommonMark\Node\Heading(2);//默认值为1 一个# 值为2则两个# $child_strong=new CommonMark\Node\Text\Strong(); $heading->appendChild($child_strong); $child_text=new CommonMark\Node\Text('title'); $child_strong->appendChild($child_text); $render=CommonMark\Render($heading); var_dump($render);//## **title** ``` ***** **CommonMark\\Render\\HTML**(CommonMark\\Node`$node`\[,int`$options`\] ) :string >[info]将节点渲染为html `options` **`CommonMark\Render\Normal`**([integer](https://www.php.net/manual/en/language.types.integer.php)) **`CommonMark\Render\SourcePos`**([integer](https://www.php.net/manual/en/language.types.integer.php)) **`CommonMark\Render\HardBreaks`**([integer](https://www.php.net/manual/en/language.types.integer.php)) **`CommonMark\Render\Safe`**([integer](https://www.php.net/manual/en/language.types.integer.php)) **`CommonMark\Render\NoBreaks`**([integer](https://www.php.net/manual/en/language.types.integer.php)) 例子: ``` $heading=new CommonMark\Node\Heading(2);//默认值为1 一个# 值为2则两个# $child_strong=new CommonMark\Node\Text\Strong(); $heading->appendChild($child_strong); $child_text=new CommonMark\Node\Text('title'); $child_strong->appendChild($child_text); //$render=CommonMark\Render($heading); //var_dump($render);//## **title** $render=CommonMark\Render\HTML($heading);//转成html var_dump($render);//<h2><strong>title</strong></h2> ``` ***** **CommonMark\Render\XML**(CommonMark\\Node`$node`\[,int`$options`\] ) :string >[info]将节点渲染成XML格式 参数: `options` **`CommonMark\Render\Normal`**([integer](https://www.php.net/manual/en/language.types.integer.php)) **`CommonMark\Render\SourcePos`**([integer](https://www.php.net/manual/en/language.types.integer.php)) **`CommonMark\Render\HardBreaks`**([integer](https://www.php.net/manual/en/language.types.integer.php)) **`CommonMark\Render\Safe`**([integer](https://www.php.net/manual/en/language.types.integer.php)) **`CommonMark\Render\NoBreaks`**([integer](https://www.php.net/manual/en/language.types.integer.php)) ``` $heading=new CommonMark\Node\Heading(2);//默认值为1 一个# 值为2则两个# $child_strong=new CommonMark\Node\Text\Strong(); $heading->appendChild($child_strong); $child_text=new CommonMark\Node\Text('title'); $child_strong->appendChild($child_text); // $render=CommonMark\Render($heading); // var_dump($render);//## **title** // $render=CommonMark\Render\HTML($heading);//转成html // var_dump($render);//<h2><strong>title</strong></h2> $render=CommonMark\Render\XML($heading);//转成XML var_dump($render); ``` 结果: ``` <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE document SYSTEM "CommonMark.dtd"> <heading level="2"> <strong> <text>title</text> </strong> </heading> ``` ***** **CommonMark\Render\Man**(CommonMark\\Node`$node`\[,int`$options`\[,int`$width`\]\] ) :string >[info]将节点渲染为Man(什么格式???) 参数: `options` **`CommonMark\Render\Normal`**([integer](https://www.php.net/manual/en/language.types.integer.php)) **`CommonMark\Render\SourcePos`**([integer](https://www.php.net/manual/en/language.types.integer.php)) **`CommonMark\Render\HardBreaks`**([integer](https://www.php.net/manual/en/language.types.integer.php)) **`CommonMark\Render\Safe`**([integer](https://www.php.net/manual/en/language.types.integer.php)) **`CommonMark\Render\NoBreaks`**([integer](https://www.php.net/manual/en/language.types.integer.php)) ***** **CommonMark\Render\Latex**(CommonMark\\Node`$node`\[,int`$options`\[,int`$width`\]\] ) :string >[info]将节点渲染成Latex 参数: `options` **`CommonMark\Render\Normal`**([integer](https://www.php.net/manual/en/language.types.integer.php)) **`CommonMark\Render\SourcePos`**([integer](https://www.php.net/manual/en/language.types.integer.php)) **`CommonMark\Render\HardBreaks`**([integer](https://www.php.net/manual/en/language.types.integer.php)) **`CommonMark\Render\Safe`**([integer](https://www.php.net/manual/en/language.types.integer.php)) **`CommonMark\Render\NoBreaks`**([integer](https://www.php.net/manual/en/language.types.integer.php)) *****