wnx/commonmark-mark-extension

在league/commonmark中将==高亮==的文本渲染为<mark>元素

v1.2.0 2023-10-16 12:17 UTC

This package is auto-updated.

Last update: 2024-09-19 19:07:56 UTC


README

Latest Version on Packagist Tests Check & fix styling Total Downloads

A league/commonmark 扩展,用于将高亮文本转换为 <mark>HTML 元素。

例如,以下markdown文本…

The ==quick brown fox== jumps over the lazy dog.

… 转换为以下HTML。

<p>The <mark>quick brown fox</mark> jumps over the lazy dog.</p>

安装

您可以通过composer安装此包

composer require wnx/commonmark-mark-extension

使用

创建一个自定义的CommonMark环境,并注册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==');

如果您在Markdown中使用除=之外的字符来高亮文本,您可以向扩展传递一个character配置。

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

变更日志

有关最近更改的更多信息,请参阅CHANGELOG

贡献

有关详细信息,请参阅CONTRIBUTING

安全漏洞

有关如何报告安全漏洞,请参阅我们的安全策略

鸣谢

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件