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>
You can install the package via composer:
composer require wnx/commonmark-mark-extension
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::');
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.