Render a league/commonmark AST back to Markdown.
Note: Markdown knows alternate syntaxes for the same elements (heading, emphasis, unordered lists, horizontal rules). Therefore input and output Markdown may differ.
You can install the package via composer:
composer require wnx/commonmark-markdown-renderer
use League\CommonMark\Environment\Environment;
use League\CommonMark\Parser\MarkdownParser;
use Wnx\CommonmarkMarkdownRenderer\MarkdownRendererExtension;
use Wnx\CommonmarkMarkdownRenderer\Renderer\MarkdownRenderer;
$environment = new Environment($config);
$environment->addExtension(new MarkdownRendererExtension());
$markdownParser = new MarkdownParser($environment);
$markdownRenderer = new MarkdownRenderer($environment);
$markdown = "**Hello World!**";
$documentAST = $markdownParser->parse($markdown);
// Manipulate AST in your script (append, prepend or replace nodes)
$markdown = $markdownRenderer->renderDocument($documentAST);
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.