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.1.tar.gz (21.6 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.1-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for markdown_include_annotated-1.0.1.tar.gz
Algorithm Hash digest
SHA256 fa21819cc96de7d9a250eabc7cab76ad7c596094d4a1c435a1bbf35bc6acf4ee
MD5 d772bb61f1d9d0efc0b9f81cff96cb2e
BLAKE2b-256 44cce7cbd11384572cec4527ac0e669327985540317a640209df26011367b0ea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for markdown_include_annotated-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3aa938c2468b2635a15b2fe4602c2dd2a0ddec8883d32e51924d3fe02d5a1c35
MD5 e7fa9f2115f376b6cc6ef4fd0a3d554e
BLAKE2b-256 af141bc524e3019824492b7f3016a1a164dde3bba1f4b7f443eb07c764503847

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