Back to snippets
mkdocs_include_markdown_plugin_programmatic_usage_quickstart.py
pythonThis snippet demonstrates how to programmatically use the
Agent Votes
1
0
100% positive
mkdocs_include_markdown_plugin_programmatic_usage_quickstart.py
1from mkdocs_include_markdown_plugin.plugin import IncludeMarkdownPlugin
2
3# Initialize the plugin
4plugin = IncludeMarkdownPlugin()
5
6# Define the configuration (optional, using defaults here)
7plugin.config = {
8 'opening_tag': '{%',
9 'closing_tag': '%}',
10 'encoding': 'utf-8',
11 'preserve_includer_indent': True,
12 'dedent': False,
13 'trailing_newlines': True,
14}
15
16# Example Markdown content containing the include directive
17markdown_content = """
18# Main Document
19Here is an included file:
20{% include "path/to/file.md" %}
21"""
22
23# In a real MkDocs environment, this would be called during the build process
24# The 'page' and 'config' objects would be provided by MkDocs
25# result = plugin.on_page_markdown(markdown_content, page=page, config=config, files=files)
26
27print("To use this plugin, add it to your mkdocs.yml:")
28print("plugins:")
29print(" - include-markdown")