/marko

A markdown parser with high extensibility.

Primary LanguagePythonMIT LicenseMIT

𝓜𝓪𝓻𝓴𝓸

A markdown parser with high extensibility.

PyPI PyPI - Python Version Documentation Status CommonMark Spec

Build Status codecov Codacy Badge

Marko is a pure Python markdown parser that adheres to the specifications of CommonMark's spec v0.31.2. It has been designed with high extensibility in mind, as detailed in the Extensions section.

Marko requires Python 3.8 or higher.

Why Marko

Of all the Python markdown parsers available, a common issue is the difficulty for users to add their own features. Additionally, both Python-Markdown and mistune do not comply with CommonMark specifications. This has prompted me to develop a new markdown parser.

Marko's compliance with the complex CommonMark specification can impact its performance. However, using a parser that does not adhere to this spec may result in unexpected rendering outcomes. According to benchmark results, Marko is three times slower than Python-Markdown but slightly faster than Commonmark-py and significantly slower than mistune. If prioritizing performance over spec compliance is crucial for you, it would be best to opt for another parser.

Use Marko

The installation is very simple:

$ pip install marko

And to use it:

import marko

print(marko.convert(text))

Marko also provides a simple CLI, for example, to render a document and output to a html file:

$ cat my_article.md | marko > my_article.html

Extensions

It is super easy to use an extension:

from marko import Markdown
from marko.ext.footnote import make_extension
# Add footnote extension
markdown = Markdown(extensions=[make_extension()])
# Or you can just:
markdown = Markdown(extensions=['footnote'])
# Alternatively you can register an extension later
markdown.use(make_extension())

An example of using an extension with the command-line version of Marko:

$ cat this_has_footnote.txt | marko -e footnote > hi_world.html

Marko is shipped with 4 extensions: 'footnote', 'toc' 'pangu', 'codehilite'. They are not included in CommonMark's spec but are common in other markdown parsers.

Marko also provides a Github flavored markdown parser which can be found at marko.ext.gfm.gfm.

Please refer to Extend Marko about how to write your own extension.

License

Marko is released under MIT License