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.

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.1.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

mkpatcher-1.0.1-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mkpatcher-1.0.1.tar.gz
  • Upload date:
  • Size: 8.4 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.1.tar.gz
Algorithm Hash digest
SHA256 5a4a5bfdc606786d290902044aeab83bcc5916a49ca91be080a967fd1e78d8bd
MD5 0217fdccd7e49704474112b86d23dc0b
BLAKE2b-256 8287476fbfe5749433b3c34594699bb0f014258cb448549196c93acdba131a68

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mkpatcher-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.6 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cb149116051118ef8a4914567d36ff864876fe497a814d43bde3469aabf42958
MD5 52dfacf10da840e237ba27b518354bbf
BLAKE2b-256 b5939ecece88d2f61e6b07329ec4a56e511105faa4404d72cc76e54bc6169ccc

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