wnx / commonmark-markdown-renderer
Render Markdown AST back to Markdown.
Fund package maintenance!
stefanzweifel
Installs: 64 654
Dependents: 4
Suggesters: 0
Security: 0
Stars: 7
Watchers: 3
Forks: 2
Open Issues: 3
Requires
- php: ^8.1
- league/commonmark: ^2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpunit/phpunit: ^10.0
- rector/rector: ^0.15.17
- vimeo/psalm: ^5.7
README
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.
Installation
You can install the package via composer:
composer require wnx/commonmark-markdown-renderer
Usage
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);
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.