Built-in Extensions

Github flavored markdown

https://github.github.com/gfm

Unlike other extensions, GFM provides a self-contained subclass of Markdown with parser and renderer already set. User may also use the parser and renderer as bases for further extension.

Example usage:

from marko.ext.gfm import gfm
print(gfm(text))

TOC extension

Renders the TOC(Table Of Content) for a markdown document. This requires to install toc extras:

pip install marko[toc]
Arguments:
  • opening: the opening tag, defaults to <ul>

  • closing: the closing tag, defaults to </ul>

  • item_format: the toc item format, defaults to ‘<li><a href=”#{slug}”>{text}</a></li>’

Usage:

from marko import Markdown

markdown = Markdown(extensions=['toc'])

print(markdown(text))
print(markdown.renderer.render_toc())

Footnotes extension

Enable footnotes parsing and renderering in Marko.

Usage:

from marko import Markdown

text = 'Foo[^1]\n\n[^1]: This is a footnote.\n'
markdown = Markdown(extensions=['footnote'])
print(markdown(text))

Pangu Extension

Separate CJK characters with latin letters.

Reference: vinta’s pangu project

Example:

input: 中国有13亿人口
output: 中国有<span class="pangu"></span>13<span class="pangu"></span>亿人口

from marko import Markdown

markdown = Markdown(extensions=['pangu'])
print(markdown(text))

Code highlight extension

Enable code highlight using pygments. This requires to install codehilite extras:

pip install marko[codehilite]
Arguments:

All arguments are passed to pygments.formatters.html.HtmlFormatter.

Usage:

from marko import Markdown

markdown = Markdown(extensions=['codehilite'])
markdown.convert('```python filename="my_script.py"\nprint('hello world')\n```')