moxio/commonmark-ext-definition-list

league/commonmark的扩展,支持定义列表

安装次数: 10,234

依赖关系: 1

建议者: 0

安全性: 0

星星: 3

关注者: 11

分支: 2

开放问题: 0

类型:commonmark-extension

v1.1.0 2021-12-20 19:29 UTC

This package is auto-updated.

Last update: 2024-09-25 13:58:38 UTC


README

Continuous Integration Latest Stable Version Buy us a tree

moxio/commonmark-ext-definition-list

用于支持定义列表的league/commonmark Markdown解析器扩展。

使用基于PHP Markdown ExtraPandocmarkdown-it语法的非官方Markdown语法。有关详细信息,请参阅下面的语法部分。

要求

此库需要PHP版本7.4或更高版本,以及league/commonmark1.x版本。

安装

使用Composer将其作为依赖项安装

$ composer require --dev moxio/commonmark-ext-definition-list

用法

DefinitionListExtension添加为您的CommonMark环境实例的扩展,即可使用

use League\CommonMark\CommonMarkConverter;
use League\CommonMark\Environment;
use Moxio\CommonMark\Extension\DefinitionList\DefinitionListExtension;

$environment = Environment::createCommonMarkEnvironment();
$environment->addExtension(new DefinitionListExtension());

// Use $environment when building your CommonMarkConverter
$converter = new CommonMarkConverter([], $environment);
echo $converter->convertToHtml('
Term 1
: Definition of term 1.

Term 2
: Definition of term 2.
');

有关使用扩展的更多信息,请参阅CommonMark文档

语法

支持的Markdown语法基于PHP Markdown ExtraPandocmarkdown-it的语法。由于这些库之间理解的语法存在细微差别,且没有正式定义的标准,因此无法保证与上述任何库100%兼容。还支持使用波浪号(~)作为定义列表标记(如Pandoc所理解)。

一个简单的示例

Apple
:   Pomaceous fruit of plants of the genus Malus in
the family Rosaceae.

Orange
:   The fruit of an evergreen tree of the genus Citrus.

这将生成如下HTML输出

<dl>
  <dt>Apple</dt>
  <dd>Pomaceous fruit of plants of the genus Malus in
the family Rosaceae.</dd>
  <dt>Orange</dt>
  <dd>The fruit of an evergreen tree of the genus Citrus.</dd>
</dl>

一个更复杂的示例

Term 1

:   This is a definition with two paragraphs. Lorem ipsum
    dolor sit amet, consectetuer adipiscing elit. Aliquam
    hendrerit mi posuere lectus.

    Vestibulum enim wisi, viverra nec, fringilla in, laoreet
    vitae, risus.

:   Second definition for term 1, also wrapped in a paragraph
    because of the blank line preceding it.

Term 2

:   This definition has a code block, a blockquote and a list.

        code block.

    > block quote
    > on two lines.

    1.  first list item
    2.  second list item

版本控制

本项目遵循语义版本控制

贡献

欢迎对此项目做出贡献。在报告问题时,请包括重现问题的输入,以及预期的输出。提交PR时,请包括与您的更改相关的测试。

许可

本项目遵循MIT许可证。

实物赠品

此包是实物赠品。如果您在生产环境中使用它,那么我们希望您能为我们购买一棵树以感谢我们的工作。通过为实物赠品森林做出贡献,您将为当地家庭创造就业机会并恢复野生动物栖息地。

由荷兰代尔夫特的Moxio团队用爱和咖啡以及乐趣制作。有兴趣加入我们棒棒哒团队吗?请查看我们的职位空缺(荷兰语)。