sphinx-rustdoc-postprocess¶
Post-process sphinxcontrib-rust RST output, converting leftover markdown fragments (code fences, tables, links, headings, inline code) to proper RST via pandoc.
The problem¶
sphinxcontrib-rust generates RST files from Rust crates, but rustdoc doc-comments are written in markdown. The generated RST ends up with markdown fragments embedded verbatim inside directive bodies, which Sphinx cannot render correctly.
For example, given Rust doc-comments with a markdown table and heading:
//! ## Module Overview
//!
//! | Module | Purpose |
//! |--------|---------|
//! | [`types`] | `#[repr(C)]` data structures |
sphinxcontrib-rust produces RST like:
.. py:module:: my_crate
## Module Overview
| Module | Purpose |
|--------|---------|
| [`types`] | `#[repr(C)]` data structures |
After this extension runs, the output becomes valid RST:
.. py:module:: my_crate
**Module Overview**
+----------+------------------------------+
| Module | Purpose |
+==========+==============================+
| ``types``| ``#[repr(C)]`` data structures|
+----------+------------------------------+
For a real-world example, see rgpot (source), which uses this extension to document its Rust core library alongside C++ API docs.