recommonmark

0.7.1 · deprecated · verified Sat Apr 11

recommonmark provides a compatibility bridge to CommonMark, allowing users to write Markdown files within Docutils and Sphinx projects. It parses CommonMark-compliant Markdown into a Docutils abstract syntax tree, integrating it into the Sphinx build process. The library's last release was in December 2020, and it is officially deprecated in favor of MyST-Parser.

Warnings

Install

Imports

Quickstart

To integrate recommonmark with Sphinx, you primarily add it to your `extensions` list in `conf.py`. For advanced features like automatic table of contents generation or embedding reStructuredText within Markdown, you must also import and register `AutoStructify` with specific configurations. This example also demonstrates how to enable `autosectionlabel` and prevent common conflicts.

# conf.py

import os
import sys
sys.path.insert(0, os.path.abspath('.'))

# -- Project information -----------------------------------------------------
project = 'My Project'
copyright = '2026, Your Name'
author = 'Your Name'

# The full version, including alpha/beta/rc tags
release = '0.1.0'

# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
    'sphinx.ext.autodoc',
    'sphinx.ext.napoleon',
    'sphinx.ext.autosectionlabel',
    'recommonmark',
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# The suffix(es) of source filenames. You can specify multiple suffix as a list of string:
source_suffix = ['.rst', '.md']

# The master toctree document.
master_doc = 'index'

# -- Options for AutoStructify (recommonmark's advanced features) -----------
from recommonmark.transform import AutoStructify

def setup(app):
    app.add_config_value(
        'recommonmark_config',
        {
            'enable_auto_toc_tree': True,
            'enable_math': True,
            'enable_inline_math': True,
            'enable_eval_rst': True,
            'enable_auto_doc_ref': True,
        },
        True,
    )
    app.add_transform(AutoStructify)

# Ensure that autosectionlabel prefixes document path to avoid conflicts
autosectionlabel_prefix_document = True

# -- Options for HTML output -------------------------------------------------
html_theme = 'alabaster'

# -- Generate a dummy index.md for demonstration --
# This would typically be an actual .md file in your source directory
with open('index.md', 'w') as f:
    f.write('# Welcome to My Project\n\nThis is a Markdown file processed by recommonmark.\n\n## Features\n\n*   Easy integration\n*   Supports basic CommonMark\n*   Advanced features via AutoStructify\n')

# To build the docs, run `sphinx-build -b html . _build` in a terminal where this conf.py exists.

view raw JSON →