wnx / commonmark-mark-extension
Render ==highlighted== texts as <mark> elements in league/commonmark
Fund package maintenance!
stefanzweifel
buymeacoff.ee/3oQ64YW
Requires
- php: ^8.0
- league/commonmark: ^2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpunit/phpunit: ^9.5 | ^10
- vimeo/psalm: ^5
README
A league/commonmark extension to turn highlighted text into <mark>
-HTML elements.
For example, the following markdown text …
The ==quick brown fox== jumps over the lazy dog.
… is turned into the following HTML.
<p>The <mark>quick brown fox</mark> jumps over the lazy dog.</p>
Installation
You can install the package via composer:
composer require wnx/commonmark-mark-extension
Usage
Create a custom CommonMark environment, and register the MarkExtension
.
use League\CommonMark\Environment\Environment; use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension; use League\CommonMark\MarkdownConverter; use Wnx\CommonmarkMarkExtension\MarkExtension; // Configure the Environment with all the CommonMark parsers/renderers $environment = new Environment(); $environment->addExtension(new CommonMarkCoreExtension()); // Add this extension $environment->addExtension(new MarkExtension()); // Instantiate the converter engine and start converting some Markdown! $converter = new MarkdownConverter($environment); echo $converter->convertToHtml('The ==quick== brown fox jumps over the ==lazy dog==');
If you're using a different character than =
to highlight text in Markdown, you can pass a character
configuration to the extension.
use League\CommonMark\Environment\Environment; use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension; use League\CommonMark\MarkdownConverter; use Wnx\CommonmarkMarkExtension\MarkExtension; // Define your configuration, if needed $config = [ 'mark' => [ 'character' => ':', ], ]; // Configure the Environment with all the CommonMark parsers/renderers $environment = new Environment($config); $environment->addExtension(new CommonMarkCoreExtension()); // Add this extension $environment->addExtension(new MarkExtension()); // Instantiate the converter engine and start converting some Markdown! $converter = new MarkdownConverter($environment); echo $converter->convertToHtml('The ::quick:: brown fox jumps over the ::lazy dog::');
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.