Registry / serialization / markdown-include

markdown-include

JSON →
library0.8.1pypypiunverified

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 markdown
INSTALL
IMPORT
SIG · MARKDOWN-INCLUDE
M
markdown-include
serializationpythonv0.8.1
Install
1.7s avg
Import
142ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.8.1 · 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.920 runs
installs and imports cleanly · install 0.0s · import 0.147s · 18.6MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.7s · import 0.136s · 19MB
17MB installed
● package 17MB
Code
Verified usage

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

MarkdownInclude
from markdown_include.include import MarkdownInclude
markdown
import markdown

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.

import markdown from markdown_include.include import MarkdownInclude import os # Create a dummy base directory and included file if not os.path.exists('docs'): os.makedirs('docs') with open('docs/main.md', 'w') as f: f.write('# Main Document\n\nThis is the main content.\n\n{!partial.md!}\n\nEnd of document.') with open('docs/partial.md', 'w') as f: f.write('## Included Section\n\nThis content comes from `partial.md`.') # Configure the MarkdownInclude extension # base_path specifies the directory where included files are sought configs = { 'base_path': 'docs' } # Initialize Markdown with the extension md_instance = markdown.Markdown(extensions=[MarkdownInclude(configs=configs)]) # Read the main Markdown content with open('docs/main.md', 'r') as f: markdown_text = f.read() # Convert Markdown to HTML html = md_instance.convert(markdown_text) print(html) # Expected output (simplified): # <h1>Main Document</h1> # <p>This is the main content.</p> # <h2>Included Section</h2> # <p>This content comes from <code>partial.md</code>.</p> # <p>End of document.</p>
Debug
Known issues
breakingThe include syntax changed significantly in version 0.8.x from `!INCLUDE "filename.md"!` to `{!filename!}`. This was done to reduce conflicts with other Markdown elements like code blocks.
fix
Update all include statements in your Markdown files from the old `!INCLUDE "file.md"!` style to the new `{!file.md!}` syntax.
affects: >=0.8.0
gotchaBy default, included file paths are resolved relative to the directory from which the Python script (or `markdown.markdown` call) is executed, not relative to the Markdown file containing the include statement.
fix
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/'})`.
affects: All versions
gotchaThe extension supports recursive includes, meaning an included file can itself contain include statements. While powerful, this can lead to unexpected content duplication or infinite recursion if not managed carefully (e.g., circular dependencies).
fix
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.
affects: All versions
Upgrade
Version history
0.8.1latest on PyPI · released Feb 7, 2023
Audit
Dependencies
markdownrequiredmarkdown-include is an extension for the Python-Markdown library and requires it to function.
Agent activity
3 hits · last 30 days
node
2
Amazon
1
Resources
markdown-include — pip install markdown-include · libregistry