mdx-include

1.4.2 · active · verified Thu Apr 16

mdx-include is a Python Markdown extension that enables the inclusion of local or remote files directly into Markdown documents. It provides advanced features like recursive includes, file content slicing by line/column, caching of included files, and detection of circular inclusions. The current stable version is 1.4.2, with the last update released in July 2022, indicating an irregular release cadence.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `mdx-include` to embed content from one Markdown file (`include_me.md`) into another. The extension processes the `{! file_path !}` syntax to replace it with the target file's content.

import markdown
import os

# Create a dummy file to include
with open('include_me.md', 'w') as f:
    f.write('This content is from an included file.\n\n- Item 1\n- Item 2')

# Markdown content that includes the dummy file
markdown_content = """
# Main Document

This is the main content.

{! include_me.md !}

End of document.
"""

html = markdown.markdown(
    markdown_content,
    extensions=['mdx_include']
)

print(html)

# Clean up dummy file
os.remove('include_me.md')

view raw JSON →