m2r2
Markdown and reStructuredText in a single file.
What it is and what it does
M2R2 is a markdown-to-reStructuredText converter designed to let you write Sphinx documentation in markdown while preserving reStructuredText markup and Sphinx extensions that other converters drop. It extends the markdown parser mistune to handle inline and block-level rst constructs like directives, roles, and reference links, which would otherwise be lost in conversion. The package works both as a command-line tool and as a Sphinx extension that transparently converts .md files during documentation builds.
The core problem it solves is that standard markdown converters (pandoc, recommonmark) don't support many rst features—particularly reference links and Sphinx-specific directives—making them unsuitable for projects that rely on those capabilities. M2R2 is a maintained fork of the original m2r project, addressing issues that broke Sphinx 3 compatibility and keeping pace with modern Python versions (3.7–3.13).
Use it for:
- Write Sphinx documentation in markdown while keeping rst directives and cross-references intact for the build.
- Convert existing markdown README files to rst format for PyPI publication without losing formatting.
- Include markdown files directly in Sphinx projects using the mdinclude directive alongside rst files.
- Automate markdown-to-rst conversion in CI/CD pipelines for documentation generation.
- Render mermaid diagram blocks in Sphinx when sphinxcontrib.mermaid is available.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Converts markdown files with embedded reStructuredText markup to valid reStructuredText format, supporting Sphinx integration for building documentation directly from markdown sources.
Yes. M2R2 is actively maintained, has no known vulnerabilities, low install friction, and solves a real problem for projects that need markdown authoring with full reStructuredText and Sphinx feature support. Install it if you want to write Sphinx docs in markdown without losing rst markup or Sphinx extensions.
Install
m2r2 on PyPI
pip
pip install m2r2uv
uv add m2r2poetry
poetry add m2r2Installing m2r2
Before you install
Low install friction with only two runtime dependencies (mistune and docutils). Actively maintained with recent commits; last release was 470 days ago and repository remains active with 114 stars.
License in practice
MIT license permits commercial and private use with minimal restrictions; you must include the license text in distributions but face no copyleft obligations.
Quickstart
pip install m2r2
from m2r2 import convert
rst = convert('# Title\n\nSentence.')
print(rst)
Requires Python 3.7 or later.
Verify before relying
- Whether the package handles all reStructuredText directives and roles correctly in mixed markdown/rst documents.
- Performance characteristics when processing large markdown files or many files in batch.
- Compatibility with recent Sphinx versions beyond those in the classifier list.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.7) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — mistune, docutils |
| Maintenance | actively maintained — 470 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 281,198/month — #8,103 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: m2r2-0.3.4-py3-none-any.whl
Keywords: Markdown, reStructuredText, sphinx-extension
Tags
More Text Processing packages
A drop-in replacement for Python's standard…
permissive · top 100 on PyPI
pyparsingpyparsing provides a library for building text…
permissive · top 1,000 on PyPI
docutilsDocutils converts plaintext documentation in…
unclear · top 1,000 on PyPI
RapidFuzzRapidFuzz provides fast fuzzy string matching…
permissive · top 1,000 on PyPI
tinycss2tinycss2 parses CSS strings into token and…
permissive · top 1,000 on PyPI
llama-parseLlamaParse parses complex documents (PDFs,…
permissive · top 1,000 on PyPI
docstring-to-markdownConverts Python docstrings from…
copyleft · top 5,000 on PyPI
setuptools-markdownConverts Markdown files to reStructuredText…
permissive · top 15,000 on PyPI
sphinx_mdincludeSphinx extension that lets you include and…
permissive · top 15,000 on PyPI
sphinx-markdown-tablesAdds markdown table support to Sphinx…
copyleft · top 15,000 on PyPI
rich-rstRenders reStructuredText documents as Rich…
permissive · top 1,000 on PyPI
recommonmarkEnables Sphinx and Docutils projects to parse…
permissive · top 5,000 on PyPI
sphinx-markdown-builderA Sphinx extension that generates Markdown…
permissive · top 15,000 on PyPI
rst2pdfConverts reStructuredText documents directly to…
permissive · top 15,000 on PyPI
sphinxcontrib-confluencebuilderSphinx extension that converts reStructuredText…
permissive · top 15,000 on PyPI
esbonioA Language Server Protocol implementation for…
permissive · top 15,000 on PyPI