项目作者: Moxio

项目描述 :
Extension for the league/commonmark Markdown parser to support definition lists.
高级语言: PHP
项目地址: git://github.com/Moxio/commonmark-ext-definition-list.git
创建时间: 2020-09-18T12:33:49Z
项目社区:https://github.com/Moxio/commonmark-ext-definition-list

开源协议:MIT License

下载


Continuous Integration
Latest Stable Version
Buy us a tree

moxio/commonmark-ext-definition-list

Extension for the league/commonmark Markdown parser to support definition lists.

Uses unofficial markdown syntax based on the syntax supported by
PHP Markdown Extra,
Pandoc and
markdown-it. See the
section Syntax below for details.

Requirements

This library requires PHP version 7.4 or higher and a 1.x release of
league/commonmark.

Installation

Install as a dependency using composer:

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

Usage

Add DefinitionListExtension as an extension to your CommonMark environment
instance and you’re good to go:

  1. use League\CommonMark\CommonMarkConverter;
  2. use League\CommonMark\Environment;
  3. use Moxio\CommonMark\Extension\DefinitionList\DefinitionListExtension;
  4. $environment = Environment::createCommonMarkEnvironment();
  5. $environment->addExtension(new DefinitionListExtension());
  6. // Use $environment when building your CommonMarkConverter
  7. $converter = new CommonMarkConverter([], $environment);
  8. echo $converter->convertToHtml('
  9. Term 1
  10. : Definition of term 1.
  11. Term 2
  12. : Definition of term 2.
  13. ');

See the CommonMark documentation
for more information about using extensions.

Syntax

The supported markdown syntax is based on the one used by
PHP Markdown Extra,
Pandoc and
markdown-it.
Since there are subtle differences between the syntaxes understood by these
libraries and there is no formally defined standard, 100% compatibility
with any of the aforementioned libraries cannot be guaranteed. The use
of the tilde (~) as a definition list marker (as understood by Pandoc)
is also supported.

A simple example:

  1. Apple
  2. : Pomaceous fruit of plants of the genus Malus in
  3. the family Rosaceae.
  4. Orange
  5. : The fruit of an evergreen tree of the genus Citrus.

The will yield HTML output like:

  1. <dl>
  2. <dt>Apple</dt>
  3. <dd>Pomaceous fruit of plants of the genus Malus in
  4. the family Rosaceae.</dd>
  5. <dt>Orange</dt>
  6. <dd>The fruit of an evergreen tree of the genus Citrus.</dd>
  7. </dl>

A more complex example:

  1. Term 1
  2. : This is a definition with two paragraphs. Lorem ipsum
  3. dolor sit amet, consectetuer adipiscing elit. Aliquam
  4. hendrerit mi posuere lectus.
  5. Vestibulum enim wisi, viverra nec, fringilla in, laoreet
  6. vitae, risus.
  7. : Second definition for term 1, also wrapped in a paragraph
  8. because of the blank line preceding it.
  9. Term 2
  10. : This definition has a code block, a blockquote and a list.
  11. code block.
  12. > block quote
  13. > on two lines.
  14. 1. first list item
  15. 2. second list item

Versioning

This project adheres to Semantic Versioning.

Contributing

Contributions to this project are more than welcome. When reporting an issue,
please include the input to reproduce the issue, along with the expected
output. When submitting a PR, please include tests with your changes.

License

This project is released under the MIT license.

Treeware

This package is Treeware. If you use it in production,
then we’d appreciate it if you buy the world a tree
to thank us for our work. By contributing to the Treeware forest you’ll be creating
employment for local families and restoring wildlife habitats.


Made with love, coffee and fun by the Moxio team from
Delft, The Netherlands. Interested in joining our awesome team? Check out our
vacancies (in Dutch).