This aims to fully support the Markua specification, and will continue to evolve as the spec does.
This package depends on League\CommonMark and functions identically except for using the Markua specification.
This project can be installed via Composer:
$ composer require league/markua
MarkuaConverter class provides a simple wrapper for converting Markua to HTML:
use League\Markua\MarkuaConverter; $converter = new MarkuaConverter(); echo $converter->convertToHtml('# Hello World!'); // <h1>Hello World!</h1>
Advanced Usage & Customization
The actual conversion process requires two steps:
- Parsing the Markdown input into an AST
- Rendering the AST document as HTML
MarkuaConverter wrapper simplifies this process for you, advanced users will likely want to do this themselves:
use League\CommonMark\DocParser; use League\CommonMark\Environment; use League\CommonMark\HtmlRenderer; use League\Markua\Environment\Markua; // Obtain a pre-configured Environment with all the Markua parsers/renderers ready-to-go $environment = Environment::createEnvironment(new Markua()); // Optional: Add your own parsers/renderers here, if desired // For example: $environment->addInlineParser(new TwitterHandleParser()); // Create the document parser and HTML renderer engines $parser = new DocParser($environment); $htmlRenderer = new HtmlRenderer($environment); // Here's our sample input $markdown = '# Hello World!'; // 1. Parse the Markdown to AST $documentAST = $parser->parse($markdown); // Optional: If you want to access/modify the AST before rendering, do it here // 2. Render the AST as HTML echo $htmlRenderer->renderBlock($documentAST); // The output should be: // <h1>Hello World!</h1>
This approach allows you to access/modify the AST before rendering it.
You can also reference the core CommonMark parsers/renderers as they use the same functionality available to you.
Compatibility with Markua
This project aims to fully support the entire Markua Spec. Other flavors of Markdown may work but are not supported. Any/all changes made to the spec should eventually find their way back into this codebase.
This package is not part of Markua, but rather a compatible derivative.
Documentation can be found at markua.thephpleague.com.
Stability and Versioning
While this package does work well, the underlying code should not be considered "stable" yet. The original spec may undergo changes in the near future, which will result in corresponding changes to this code. Any methods tagged with
@api are not expected to change, but other methods/classes might.
Major release 1.0.0 will be reserved for when both Markua and this project are considered stable. 0.x.x will be used until that happens.
SemVer will be followed closely.
If you encounter a bug in the spec, please report it to the Markua project. Any resulting fix will eventually be implemented in this project as well.
Please see CONTRIBUTING for additional details.
Credits & Acknowledgements
league/markua is licensed under the BSD-3 license. See the
LICENSE file for more details.