Skip to main content

Python-Markdown extension allowing arbitrary scripts to modify MkDocs input files

Project description

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.

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

mkpatcher-1.0.2.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

mkpatcher-1.0.2-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mkpatcher-1.0.2.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for mkpatcher-1.0.2.tar.gz
Algorithm Hash digest
SHA256 c431dd5ac03ccc84a7f866178170af2c97e465547b34a3f8d0fca9a400fffb56
MD5 cfe6362ab23b3dbe23c976ca620e7928
BLAKE2b-256 102a1786c9d4d55c2fc96793f665b1a6bb479e0158c327daaf19244e0fd6886c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mkpatcher-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for mkpatcher-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b485475611b2b622a73e586e6f94d11c0e3861403f4d6580b95dc4fcf7861b7e
MD5 5e1d1ba5f4bd3dce283bedb1837c6c51
BLAKE2b-256 56a84a3966cb57c62ad2ab01fe1c8396219184c6fc0537cf5adb30ed3d0b5575

See more details on using hashes here.

Supported by

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