Skip to main content

Keep markdown files up-to-date.

Project description

mdup

Tests PyPI version

mdup is a command-line tool for keeping markdown files up-to-date by injecting code, script or command output between special blocks. One immediate use case is keeping documentation up-to-date without having to manually update markdown files with info from code snippets, scripts or command outputs [^1].

mdup does not depend on anything apart from Python stdlib.

Install

pip install mdup

or easier usage via uv:

uv tool run mdup

Usage

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

options:
  -h, --help           show this help message and exit
  -i, --input INPUT    input markdown file
  -o, --output OUTPUT  output markdown file; if not specified, the input file
                       will be edited in place
  -v, --version        show program's version number and exit

mdup will replace the contents between each block with the command output (see details below). You can keep files up-to-date by simply rerunning mdup.

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

For example, the command-line usage block above is automatically generated by defining the following block in the README.md:

<!-- MDUP:BEG uv run mdup --help -->
<!-- MDUP:END -->

then running mdup -i README.md which executes uv run mdup --help and injects the output inside the block.

Block definition

The blocks are defined using HTML comments.

Begin

<!-- MDUP:BEG (command) (; pre) -->

Examples:

<!-- MDUP:BEG cat ./mdup.py ; py -->
<!-- MDUP:BEG ls -lh -->

If you want to add a markdown language tag (pre, like py in the first example), then it must follow the command, separated by a semicolon.

Paths are relative to the markdown file containing the blocks.

End

<!-- MDUP:END -->

The blocks must be defined as the sole contents of the line, i.e. matching ^ and $ anchors.

Examples

For examples, see tests.

One real-world use case is my Advent of Code README.md, in which I use mdup to automatically update year progress badges.

⚠️ 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 rm -rf / -->
<!-- MDUP:END -->

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

[^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.3.0.tar.gz (4.6 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.3.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mdup-0.3.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.17

File hashes

Hashes for mdup-0.3.0.tar.gz
Algorithm Hash digest
SHA256 f642d621c4903a16e7d362da59fc53c07341425c99e65e91e301e756173022b9
MD5 ca8e7a27320151b5da006f957df872ac
BLAKE2b-256 aba1a2ac2121b80bd1e345dc1d64c51dc347d6c2a2a5ad227ae1d6f20a47b853

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mdup-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.17

File hashes

Hashes for mdup-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dddf60731b421065302fed73323f0a168f08fa15303e4cfb605607ae7f03324a
MD5 c49b820dd69aa0f7b1accd2a47289476
BLAKE2b-256 1300f7475c82ad778924dc68015fb43016fef54e14b0787314e72c1ed4af36e0

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