Skip to main content

Keep markdown files up-to-date.

Project description

mdup

Build PyPI version

Keep markdown files up-to-date by injecting code, script or command output between special blocks.

mdup does not depend on anything apart from Python stdlib.

Install

pip install mdup

How does it work?

The blocks are defined using HTML comments. Specifically, the begin block is of the form:

<!-- MDUP:BEG ({KIND}:{CONTENTS}) -->

where {KIND} can be either:

  • SRC: to just include the contents of {CONTENTS}, e.g. from a path
  • RUN: to execute the script from {CONTENTS} and inject its stdout in the block
  • CMD: to execute the command from {CONTENTS} and inject its stdout in the block

Notes

  • For SRC and RUN commands, the {CONTENTS} must be a path, relative to the md file.
  • The blocks must be defined as the sole contents of the line, i.e. matching ^ and $ anchors.

For examples, see tests.

⚠️ Disclaimer

I created this tool primarily to meet my own needs -- it's very simple and ad-hoc. While I don't anticipate it gaining too much adoption, always beware when running mdup on markdown files of unknown origin (which can be malicious), e.g.:

<!-- MDUP:BEG (CMD:rm -rf /) -->
<!-- MDUP:END -->

This tool should only be used for simple tasks, e.g. keeping simple documentation up-to-date.

Usage

usage: mdup [-h] -i INPUT [-o OUTPUT]

options:
  -h, --help            show this help message and exit
  -i INPUT, --input INPUT
                        Input file.
  -o OUTPUT, --output OUTPUT
                        Output file. If not specified, it will edit in place.

Running mdup -i <input.md> -o <output.md> will replace the contents between each block with the appropriate action as defined above. This means that you can keep files up-to-date by simply rerunning mdup.

Omitting the -o option will edit the file in-place.

For example, the cmdline usage block above is automatically generated by defining:

<!-- MDUP:BEG (CMD:poetry run mdup --help) -->
<!-- MDUP:END -->

then running mdup -i README.md which executes poetry run mdup --help.

[^1]: Inspired by DavidWells/markdown-magic.

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

mdup-0.2.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

mdup-0.2.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file mdup-0.2.1.tar.gz.

File metadata

  • Download URL: mdup-0.2.1.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.10.10 Linux/5.15.108-1-MANJARO

File hashes

Hashes for mdup-0.2.1.tar.gz
Algorithm Hash digest
SHA256 9001e20cffdc2abcdc449d4c922937938a72a0cef8214f1c082b7f3e3c997eff
MD5 3d988023b54c26b90950acc69e2b2ac8
BLAKE2b-256 a01ec25a1b9875eeb5b9af62fcacda90f0d057b12ad0803f2b003f38b831c0f7

See more details on using hashes here.

File details

Details for the file mdup-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: mdup-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.10.10 Linux/5.15.108-1-MANJARO

File hashes

Hashes for mdup-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2553dd55aaadb3011c341ce18ff53aa22d7d570ed2af9a502a5bcd5e5fa87e72
MD5 09e8a959a74cd5288e168fcaadbdb9b2
BLAKE2b-256 d389617b38ffef6e9ae7f9087548f5f8cd7d62eae945a2976284fef947f69291

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