Introduzione

This extension provides access to the reference implementation of CommonMark, a rationalized version of Markdown syntax with a specification.

Parsing:

The CommonMark extension provides a simple parsing API:

CommonMark\Parse(string $content, int $options = ?): CommonMark\Node

Rendering:

The CommonMark extension provides simple rendering API that supports multiple formats:

CommonMark\Render(CommonMark\Node $node, int $options = ?, int $width = ?): string
CommonMark\Render\Man(CommonMark\Node $node, int $options = ?, int $width = ?): string
CommonMark\Render\Latex(CommonMark\Node $node, int $options = ?, int $width = ?): string

AST:

The CommonMark extension implements visitation for CommonMark\Node objects:

CQL:

The CommonMark extension provides an interface to CQL, CommonMark Query Language:

add a note add a note

User Contributed Notes 1 note

up
1
xuepeng dot gao dot ggle at gmail dot com
1 year ago
in PHP 7.4.27

code:
<?php
    $markDownContent
="### test_H3 \r\n
    #### test_H4"
;
   
$c = CommonMark\Parse($markDownContent);
   
var_dump($c);
    echo
"The markdown syntax content is converted to html content: \r\n";
   
$str = CommonMark\Render\HTML($c);
    echo
$str;
?>

output :
   object(CommonMark\Node\Document)#1 (1) {
  ["children"]=>
  array(2) {
    [0]=>
    object(CommonMark\Node\Heading)#2 (1) {
      ["children"]=>
      array(1) {
        [0]=>
        object(CommonMark\Node\Text)#4 (1) {
          ["literal"]=>
          string(7) "test_H3"
        }
      }
    }
    [1]=>
    object(CommonMark\Node\Heading)#3 (1) {
      ["children"]=>
      array(1) {
        [0]=>
        object(CommonMark\Node\Text)#4 (1) {
          ["literal"]=>
          string(7) "test_H4"
        }
      }
    }
  }
}
The markdown syntax content is converted to html content:
<h3>test_H3</h3>
<h4>test_H4</h4>
To Top