MkDocs Embed External Markdown Plugin
Mkdocs-embed-external-markdown is a MkDocs plugin that allows users to inject either entire external Markdown files or specific sections from external Markdown files into their MkDocs project using a Jinja2 macro. This enables the compilation of documentation from various remote sources, such as GitHub repositories. The plugin is actively maintained, with frequent updates addressing compatibility and feature enhancements.
Warnings
- breaking When upgrading from versions older than 2.x, the 'section name' argument for `external_markdown` now strictly requires the full Markdown header syntax (e.g., `## Section Name`) rather than just the plain text of the section.
- gotcha Markdown content being embedded that contains Jinja2-like delimiters (e.g., `{{ variable }}` or `{% block %}`) may be prematurely interpreted by the plugin's Jinja2 engine, leading to rendering errors or unexpected output.
- gotcha The plugin automatically removes the top-level header (H1, `#`) from full embedded content and the specified section header (e.g., `##`) from embedded sections. This is by design to allow users to provide their own contextual headers in the embedding page, but it can be unexpected.
Install
-
pip install mkdocs-embed-external-markdown
Imports
- external-markdown
plugins: - external-markdown
Quickstart
# mkdocs.yml
site_name: My Docs
plugins:
- external-markdown
# docs/index.md
# To be placed in docs/index.md
#
# # My Awesome Documentation
#
# This page embeds content from an external GitHub README.
#
# ## Features from MkDocs README
# {{ external_markdown('https://raw.githubusercontent.com/mkdocs/mkdocs/master/README.md', '## Features') }}
#
# ## Quick start from MkDocs Material README
# {{ external_markdown('https://raw.githubusercontent.com/squidfunk/mkdocs-material/master/README.md', '## Quick start') }}
# To run this example:
# 1. Create a directory (e.g., my-docs-project)
# 2. Inside, create mkdocs.yml and docs/index.md as shown above.
# 3. From the project root, run:
# mkdocs build
# mkdocs serve