Plugins

Mdformat offers an extensible plugin system for code fence content formatting, Markdown parser extensions (like GFM tables), and modifying/adding other functionality. This document explains how to use plugins. If you want to create a new plugin, refer to the contributing docs.

Code formatter plugins

Mdformat features a plugin system to support formatting of Markdown code blocks where the coding language has been labeled. For instance, if mdformat-black plugin is installed in the environment, mdformat CLI will automatically format Python code blocks with Black.

For stability, mdformat Python API behavior will not change simply due to a plugin being installed. Code formatters will have to be explicitly enabled in addition to being installed:

import mdformat

unformatted = "```python\n'''black converts quotes'''\n```\n"
# Pass in `codeformatters` here! It is an iterable of coding languages
# that should be formatted
formatted = mdformat.text(unformatted, codeformatters={"python"})
assert formatted == '```python\n"""black converts quotes"""\n```\n'

Existing plugins

This is a curated list of popular code formatter plugins. The list is not exhaustive. Explore mdformat's GitHub topic for more.

Parser extension plugins

By default, mdformat only parses and renders CommonMark. Installed plugins can add extensions to the syntax, such as footnotes, tables, and other document elements.

For stability, mdformat Python API behavior will not change simply due to a plugin being installed. Extensions will have to be explicitly enabled in addition to being installed:

import mdformat

unformatted = "content...\n"
# Pass in `extensions` here! It is an iterable of extensions that should be loaded
formatted = mdformat.text(unformatted, extensions={"tables"})

Existing plugins

This is a curated list of popular parser extension plugins. The list is not exhaustive. Explore mdformat's GitHub topic for more.

Other misc plugins

Existing plugins

This is a curated list of other plugins that don‘t fit the above categories. The list is not exhaustive. Explore mdformat’s GitHub topic for more.