Registry / web-framework / sphinx-mdinclude

sphinx-mdinclude

JSON →
library0.6.2pypypi✓ verified 22d ago

sphinx-mdinclude is a simple Sphinx extension that enables including Markdown documents from within reStructuredText. It provides the `.. mdinclude::` directive, and automatically converts the content of Markdown documents to reStructuredText format. It is a fork of `m2r` and `m2r2`, focused solely on providing a Sphinx extension. The current version is 0.6.2, and it is actively maintained as part of the Omnilib Project, with regular releases addressing compatibility and features.

pip install sphinx-mdinclude
INSTALL
IMPORT
SIG · SPHINX-MDINCLUDE
S
sphinx-mdinclude
web-frameworkpythonv0.6.2
Install
5.6s avg
Import
Disk
95MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.6.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 93.4MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 5.6s · import 0.000s · 94MB
95MB installed
● package 95MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

sphinx_mdinclude
# In conf.py extensions = [ # other extensions, 'sphinx_mdinclude' ]
sphinx-mdinclude is loaded as a Sphinx extension string, not a Python class import.

First, add `sphinx_mdinclude` to the `extensions` list in your `conf.py`. Then, within any reStructuredText file (e.g., `index.rst`), use the `.. mdinclude::` directive to embed Markdown content from `.md` files. You can specify a path relative to the current `.rst` file. Options like `:start-line:` and `:end-line:` can be used to include only a portion of the Markdown file.

# conf.py # Add 'sphinx_mdinclude' to your extensions list extensions = [ 'sphinx.ext.autodoc', 'sphinx.ext.napoleon', 'sphinx_mdinclude' ] # index.rst (or any .rst file) My Project Documentation ======================== .. mdinclude:: ../README.md :start-line: 1 :end-line: 10 This section continues with reStructuredText. .. mdinclude:: introduction.md
Debug
Known issues
gotchaHeader levels must be consistent across reStructuredText and included Markdown files. sphinx-mdinclude converts Markdown headings to reStructuredText headings using a fixed scheme (H1: `=`, H2: `-`, H3: `^`, H4: `~`, H5: `"`, H6: `#`). If your parent `.rst` file establishes a different hierarchy before an `.. mdinclude::` directive, the combined document might render incorrectly or produce warnings.
fix
Ensure Markdown file headings align with the implicit RST heading hierarchy generated by sphinx-mdinclude, or define explicit heading adornments in your RST files that match the expected conversion.
affects: All versions
gotchaMarkdown syntax is generally not processed when nested inside reStructuredText directives. Content within directives (e.g., `.. note::`, `.. code-block::`) should typically be written directly in reStructuredText.
fix
Write content within reStructuredText directives using reStructuredText syntax. If Markdown processing is required within a specific directive, check if the directive explicitly supports it (e.g., via a custom parser or option).
affects: All versions
gotchaTable column alignment in Markdown files included via `.. mdinclude::` is not supported, as this is a limitation inherited from reStructuredText's table capabilities.
fix
For complex tables requiring specific column alignment, consider using native reStructuredText table directives or alternative Sphinx extensions that provide more advanced table functionalities.
affects: All versions
gotchaRelative paths for images or links within included Markdown files may not resolve correctly in the final Sphinx output if the Markdown file is located outside the main Sphinx source directory (e.g., including `README.md` from the project root).
fix
Ensure that image and link paths in included Markdown files are correctly relative to the Sphinx build's expected asset location, or use absolute paths. For images, they often need to be copied to the `_static` directory or a similar location accessible by Sphinx.
affects: All versions
breakingsphinx-mdinclude is a fork of `m2r` and `m2r2` with a focused scope. Version 0.4.0 notably removed the command-line interface (CLI) and mermaid extension support, shifting focus entirely to being a Sphinx extension. Users migrating from `m2r` or `m2r2` should expect these features to be absent.
fix
Plan for `sphinx-mdinclude` as solely a Sphinx extension; do not expect CLI functionality. For mermaid, use a dedicated Sphinx extension.
affects: 0.4.0 and later
breakingDependency versions for `Sphinx`, `docutils`, and `mistune` have seen breaking changes and pinning adjustments across `sphinx-mdinclude` versions. For example, `mistune` support shifted from `<1.0` to `2.x`, then to `v3` (v0.6.0). Python 3.7 support was dropped in v0.5.4.
fix
Always check the `sphinx-mdinclude` changelog and `install_requires` for specific version compatibility with your Sphinx, Python, Docutils, and Mistune setup. Upgrade dependencies incrementally, testing after each major version bump.
affects: Various versions, consult changelog for specifics (e.g., v0.4.0, v0.5.4, v0.6.0)
Upgrade
Version history
0.6.2latest on PyPI · released Aug 3, 2024
Audit
Dependencies
SphinxrequiredCore documentation generation framework it extends.
mistunerequiredMarkdown parser used for conversion.
docutilsrequiredBase reStructuredText parsing library, a core Sphinx dependency.
PygmentsrequiredUsed for code block syntax highlighting.
Agent activity
3 hits · last 30 days
node
2
Resources
sphinx-mdinclude — pip install sphinx-mdinclude · libregistry