Skip to main content

Markdown-Include 🚀

Welcome to Markdown-Include v1.0.0! 🎉

This is an extension to Python-Markdown which provides an "include" function, similar to that found in LaTeX (and also the C pre-processor and Fortran). I originally wrote it for my FORD Fortran auto-documentation generator.

✨ New in v1.0.0: Optional annotated line comments for included lines using the annotated_comments config option! 📝


📦 Installation

Install with pip:

pip install markdown-include-annotated

🧪 Tests

Run the tests with:

python -m unittest discover unittests/

🚦 Usage

Use in your Python code:

import markdown
html = markdown.markdown(source, extensions=['markdown_include.include'])

Or in MkDocs:

markdown_extensions:
    - markdown_include.include:
        base_path: docs

🔗 Include Syntax

Use {!filename!} in your Markdown files to include content from another file. Works recursively! 🪄

  • Line Ranges:
    {!filename!lines=1 3 8-10 2}
    
    • This includes lines 1, 3, 8, 9, 10, and 2 (in that order) from filename.
    • You can mix single lines and ranges, and even change the order!

⚙️ Configuration

You can specify these settings when initializing the plugin:

  • base_path: 📁 Default location for relative paths (default: run-directory)
  • encoding: 🔤 File encoding (default: utf-8)
  • inheritHeadingDepth: 🔢 Inherit heading depth from parent (default: False)
  • headingOffset: ➕ Offset heading depth (default: 0)
  • throwException: 🚨 Throw if file not found (default: False)
  • annotated_comments: 📝 NEW! Add a comment with the filename and line number before each included line when using lines (default: False)

💡 Examples

Basic usage:

import markdown
from markdown_include.include import MarkdownInclude

markdown_include = MarkdownInclude(
    configs={'base_path':'/srv/content/', 'encoding': 'iso-8859-1'}
)
html = markdown.markdown(source, extensions=[markdown_include])

Enable annotated comments:

import markdown
from markdown_include.include import MarkdownInclude

markdown_include = MarkdownInclude(
    configs={'base_path':'/srv/content/', 'annotated_comments': True}
)
html = markdown.markdown(source, extensions=[markdown_include])

Or in mkdocs.yml:

markdown_extensions:
    - markdown_include.include:
        base_path: docs
        annotated_comments: true

📝 ChangeLog

  • v1.0.0: Annotated line comments feature! 🎉
  • v0.7.0: Python-Markdown 3.4 support
  • v0.6.0: Header offset, throw exception option, bugfixes
  • v0.5.1: Syntax error fix
  • v0.5: Encoding support, code tidy
  • v0.4: Config passing fix
  • v0.3: Python 3 support
  • v0.2: Safer API
  • v0.1: Initial release

Enjoy documenting with Markdown-Include-annotated! 😃

Metadata

Release files for markdown-include-annotated 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for markdown-include-annotated 1.0.2
File Size Uploaded
markdown_include_annotated-1.0.2.tar.gz 21.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for markdown-include-annotated 1.0.2
File Interpreter ABI Platform
markdown_include_annotated-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 40.0 kB

Release files / markdown_include_annotated-1.0.2.tar.gz

Download URL markdown_include_annotated-1.0.2.tar.gz
Size 21.7 kB
Tags Source
SHA-256 checksum
How to use checksums
04a7ed40445b1ad32a46ad89e2a8f9405bee70fb3b1dbf3fd8ab0854ad6331b7
BLAKE2b-256 checksum
How to use checksums
518245d920062cf19f2d2f23bdb8b070a3deb0d19dedae11cbaa5e3d56a6c14e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.4

Release files / markdown_include_annotated-1.0.2-py3-none-any.whl

Download URL markdown_include_annotated-1.0.2-py3-none-any.whl
Size 18.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e6c84711ad10d0a0cad19119c61c057cc95d9798669849a4179eb7efddf6d241
BLAKE2b-256 checksum
How to use checksums
dfe96220da2c5edf04c70a5d08a6757687ecadf7b3c78c8ba315f7b4092356d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.4

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page