M2R2 is a Python library designed to convert Markdown files, including embedded reStructuredText (RST) markups, into a valid RST format. It is a actively maintained fork of the original `m2r` library, specifically addressing compatibility issues with Sphinx 3+ and newer Python versions. M2R2 also functions as a Sphinx extension, enabling developers to write documentation in Markdown directly within Sphinx projects. The current version is 0.3.4, with a focused release cadence primarily for maintenance and compatibility updates.
pip install m2r2Verified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to programmatically convert a Markdown string to reStructuredText using the `convert` function. It also highlights the command-line utility and how to integrate `m2r2` as a Sphinx extension by adding 'm2r2' to your `conf.py` extensions list, allowing Sphinx to process `.md` files directly.
Upgrade your Python environment to 3.7 or higher, or downgrade m2r2 to a compatible version (e.g., <0.3.3).
Ensure you `pip install m2r2` and replace any `import m2r` with `from m2r2 import convert` or similar, and update Sphinx extensions from 'm2r' to 'm2r2'.
Add 'sphinxcontrib.mermaid' to your `conf.py` extensions list if you want to use Mermaid diagrams in your Markdown files via `m2r2`.
Uninstall `m2r` and install `m2r2`: `pip uninstall m2r && pip install m2r2`. Ensure your Sphinx `conf.py` uses `'m2r2'` in `extensions`.
Upgrade to `m2r2` by running `pip uninstall m2r && pip install m2r2`. Also, update your Sphinx `conf.py` to use `extensions = ['m2r2']` instead of `'m2r'`.