sphinx_rustdoc_postprocess

Post-process sphinxcontrib-rust RST output via pandoc.

sphinxcontrib-rust dumps rustdoc (markdown) doc-comments verbatim into RST directive bodies. This extension runs after sphinxcontrib_rust’s builder-inited handler (priority 600 > default 500), walks the generated .rst files, extracts the markdown content blocks, and converts them to proper RST through pandoc -f markdown -t rst.

Submodules

Attributes

Functions

_pandoc(→ str)

Convert a markdown fragment to RST via pandoc.

_convert_fences(→ str)

Convert markdown code fences to RST code-block directives.

_convert_tables(→ str)

Convert markdown tables to RST tables via pandoc.

_convert_links(→ str)

Convert markdown links to RST.

_convert_inline_code(→ str)

Convert markdown inline code to RST double-backtick literals.

_convert_headings(→ str)

Convert markdown ATX headings to bold labels.

postprocess_rst_files(→ None)

Walk generated RST files and convert markdown fragments.

inject_rust_toctree(→ None)

Append a toctree snippet to a target RST file.

_on_builder_inited(→ None)

builder-inited callback: postprocess then inject toctree.

setup(→ dict)

Register the extension with Sphinx.

Package Contents

sphinx_rustdoc_postprocess.__version__: str
sphinx_rustdoc_postprocess.__version_tuple__: VERSION_TUPLE
sphinx_rustdoc_postprocess._log
sphinx_rustdoc_postprocess._FENCE_RE
sphinx_rustdoc_postprocess._TABLE_RE
sphinx_rustdoc_postprocess._HEADING_RE
sphinx_rustdoc_postprocess._INLINE_CODE_RE
sphinx_rustdoc_postprocess._pandoc(markdown: str) str

Convert a markdown fragment to RST via pandoc.

Parameters

markdownstr

The markdown text to convert.

Returns

str

The converted RST text, or the original markdown if pandoc fails.

sphinx_rustdoc_postprocess._convert_fences(content: str) str

Convert markdown code fences to RST code-block directives.

Parameters

contentstr

RST file content potentially containing indented markdown code fences.

Returns

str

Content with code fences replaced by .. code-block:: directives.

sphinx_rustdoc_postprocess._convert_tables(content: str) str

Convert markdown tables to RST tables via pandoc.

Parameters

contentstr

RST file content potentially containing indented markdown tables.

Returns

str

Content with markdown tables replaced by RST grid tables.

Convert markdown links to RST.

Parameters

contentstr

RST file content potentially containing markdown-style links.

Returns

str

Content with [text](url) converted to `text <url>`_ and rustdoc intra-doc links [`name`] converted to ``name``.

sphinx_rustdoc_postprocess._convert_inline_code(content: str) str

Convert markdown inline code to RST double-backtick literals.

Parameters

contentstr

RST file content potentially containing markdown single-backtick code.

Returns

str

Content with single-backtick code converted to double-backtick literals.

sphinx_rustdoc_postprocess._convert_headings(content: str) str

Convert markdown ATX headings to bold labels.

RST section headings cannot appear inside directive bodies, so we convert ## Heading to **Heading** which renders as bold.

Parameters

contentstr

RST file content potentially containing markdown ATX headings.

Returns

str

Content with headings replaced by bold text.

sphinx_rustdoc_postprocess.postprocess_rst_files(app: sphinx.application.Sphinx) None

Walk generated RST files and convert markdown fragments.

Scans the directory specified by the rustdoc_postprocess_rst_dir config value (relative to app.srcdir) for .rst files and applies all markdown-to-RST conversions in sequence.

Parameters

appSphinx

The Sphinx application instance.

sphinx_rustdoc_postprocess.inject_rust_toctree(app: sphinx.application.Sphinx) None

Append a toctree snippet to a target RST file.

Reads the rustdoc_postprocess_toctree_target and rustdoc_postprocess_toctree_rst config values. If either is empty, the injection is skipped.

Parameters

appSphinx

The Sphinx application instance.

sphinx_rustdoc_postprocess._on_builder_inited(app: sphinx.application.Sphinx) None

builder-inited callback: postprocess then inject toctree.

sphinx_rustdoc_postprocess.setup(app: sphinx.application.Sphinx) dict

Register the extension with Sphinx.

Parameters

appSphinx

The Sphinx application instance.

Returns

dict

Extension metadata with version and parallel safety flags.