MyST Parser
MyST-Parser is an extended CommonMark compliant parser that enables writing MyST (Markedly Structured Text) Markdown in Sphinx and Docutils projects. It provides a Python library for parsing MyST Markdown to various output formats, including docutils, and a Sphinx extension for seamless integration. The current version is 5.0.0, and the project maintains an active release cadence, with several updates per year, focusing on compatibility and new features.
Warnings
- breaking MyST-Parser v5.0.0 drops support for Python <3.11. Ensure your environment meets the new minimum requirement.
- breaking MyST-Parser v5.0.0 significantly updates minimum Sphinx and Docutils versions. Old versions will not be compatible.
- breaking The underlying `markdown-it-py` parser was upgraded to `~=4.0` in v5.0.0 (from v3 in v2.0.0), potentially introducing subtle parsing behavior changes or requiring plugin updates.
- breaking Versions 4.0.0 also introduced breaking changes to minimum Python, Sphinx, and Docutils requirements.
- gotcha Direct API functions like `to_html` or `to_docutils` are mainly for testing/development. For full Sphinx-specific features (e.g., cross-references, custom directives), use the Sphinx build process or explicitly load Sphinx-specific renderers with `in_sphinx_env`.
- gotcha To use fenced code blocks as Sphinx directives (e.g., for Mermaid diagrams or other renderers), you must explicitly enable `myst_fence_as_directive` in your `conf.py`.
Install
-
pip install myst-parser -
conda install -c conda-forge myst-parser
Imports
- myst_parser (as Sphinx extension)
# in conf.py extensions = [ "myst_parser" ] - to_html / to_docutils / to_tokens
from myst_parser.main import to_html, to_docutils, to_tokens
Quickstart
# conf.py
extensions = [
"myst_parser",
"sphinx.ext.autodoc"
]
# Enable common MyST extensions
myst_enable_extensions = [
"colon_fence",
"deflist",
"fieldlist",
"html_admonition",
"html_image",
"linkify",
"replacements",
"smartquotes",
"strikethrough",
"substitution",
"tasklist"
]
# index.md
# MyST Project
This is some **MyST Markdown** content.
:::{note}
This is a MyST admonition.
:::