skillfed

m2r2

Markdown and reStructuredText in a single file.

m2r2 v0.3.4 281.2K downloads/30d#8,103 on PyPI114
Permissive license MIT Active released

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 m2r2

uv

uv add m2r2

poetry

poetry add m2r2

Installing 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

Development Status :: 4 - BetaFramework :: Sphinx :: ExtensionIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseNatural Language :: EnglishProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Text Processing

Tags

markdown to rst convertersphinx markdown supportreStructuredText from markdownmarkdown rst hybridsphinx extension markdownconvert md to rstmarkdown documentation sphinx
sphinx-extensionmarkdown-conversiondocumentation-tooling

More Text Processing packages