Skip to main content

A Python-Markdown extension which provides an 'include' function with optional annotated line comments.

Project description

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! 😃

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

markdown_include_annotated-1.0.2.tar.gz (21.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

markdown_include_annotated-1.0.2-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

Details for the file markdown_include_annotated-1.0.2.tar.gz.

File metadata

File hashes

Hashes for markdown_include_annotated-1.0.2.tar.gz
Algorithm Hash digest
SHA256 04a7ed40445b1ad32a46ad89e2a8f9405bee70fb3b1dbf3fd8ab0854ad6331b7
MD5 beb8fb8ec1c315838070d191ec32ce82
BLAKE2b-256 518245d920062cf19f2d2f23bdb8b070a3deb0d19dedae11cbaa5e3d56a6c14e

See more details on using hashes here.

File details

Details for the file markdown_include_annotated-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for markdown_include_annotated-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e6c84711ad10d0a0cad19119c61c057cc95d9798669849a4179eb7efddf6d241
MD5 511da8809b7741701eac22bfe7d2a2b3
BLAKE2b-256 dfe96220da2c5edf04c70a5d08a6757687ecadf7b3c78c8ba315f7b4092356d0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page