Skip to main content

mkpatcher

PyPI - Status PyPI - Version PyPI - Downloads License - Apache-2.0 OR MIT Code style - black Say Thanks


mkpatcher is a Python-Markdown extension allowing arbitrary scripts to modify MkDocs input files.

Table of Contents

Installation

  1. pip install mkpatcher

  2. Include the extension in your mkdocs.yml config file:

    ...
    markdown_extensions:
      ...
      - mkpatcher:
          ...
    

Usage

This extension works as a pre-processor and will allow modifying the raw lines of Markdown before any other extension runs.

Raw script

The script option takes arbitrary Python code and will provide the Markdown lines as a variable named lines.

You can modify the lines directly:

...
markdown_extensions:
  ...
  - mkpatcher:
      script: |
        lines.extend(('', 'some footer', ''))

or you can shadow the variable:

...
markdown_extensions:
  ...
  - mkpatcher:
      script: |
        lines = ['entirely', 'new']
        lines.append('markdown')

Scripts on filesystem

The location option takes a path to either a single Python file or a directory containing multiple Python files. If the location refers to a directory, the scripts will be loaded and eventually executed in lexicographical order based on file names.

...
markdown_extensions:
  ...
  - mkpatcher:
      location: docs/.scripts

Each script must define a callable object named patch that accepts a single parameter which will be the Markdown lines.

You can modify the lines directly:

def patch(lines):
    lines.extend(('', 'some footer', ''))

or you can return new lines:

def patch(lines):
    new_lines = ['entirely', 'new']
    new_lines.append('markdown')
    return new_lines

License

mkpatcher is distributed under the terms of both

at your option.

Metadata

Release files for mkpatcher 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 mkpatcher 1.0.2
File Size Uploaded
mkpatcher-1.0.2.tar.gz 8.5 kB Details

Built distribution (wheel)

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

Total release size: 17.1 kB

Release files / mkpatcher-1.0.2.tar.gz

Download URL mkpatcher-1.0.2.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c431dd5ac03ccc84a7f866178170af2c97e465547b34a3f8d0fca9a400fffb56
BLAKE2b-256 checksum
How to use checksums
102a1786c9d4d55c2fc96793f665b1a6bb479e0158c327daaf19244e0fd6886c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1

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

Download URL mkpatcher-1.0.2-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b485475611b2b622a73e586e6f94d11c0e3861403f4d6580b95dc4fcf7861b7e
BLAKE2b-256 checksum
How to use checksums
56a84a3966cb57c62ad2ab01fe1c8396219184c6fc0537cf5adb30ed3d0b5575
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1

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