Markdown-Include is a Python-Markdown extension that enables the inclusion of content from other Markdown files within a main document. It facilitates modular documentation by replacing a special syntax, `{!filename!}`, with the contents of the specified file. The library is currently at version 0.8.1 and is actively maintained, with its last release in February 2023.
pip install markdown-include markdownVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to set up `markdown-include` to process a main Markdown file that includes another partial Markdown file. It creates temporary files, initializes the Markdown parser with the `MarkdownInclude` extension, and converts the content to HTML, showing how the `base_path` configuration is used to resolve included file paths.
Update all include statements in your Markdown files from the old `!INCLUDE "file.md"!` style to the new `{!file.md!}` syntax.Always explicitly set the `base_path` configuration option for the `MarkdownInclude` extension to the directory where your Markdown files reside, or ensure your script execution context matches the intended base path. Example: `MarkdownInclude(configs={'base_path':'./docs/'})`.Structure your include dependencies carefully to avoid circular references. The library itself should prevent infinite loops, but logical errors in content structure might still occur. Always test your generated output.