Skip to main content

Keep markdown files up-to-date.

Project description

mdup

Build 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

Usage

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

options:
  -h, --help            show this help message and exit
  -i INPUT, --input INPUT
                        input markdown file
  -o OUTPUT, --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

Running mdup -i <input.md> -o <output.md> will replace the contents between each block given the appropriate action kind (see details below). 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 command-line 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.

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

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.

Examples

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.

[^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.3.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

mdup-0.2.3-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mdup-0.2.3.tar.gz
  • Upload date:
  • Size: 4.7 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.3.tar.gz
Algorithm Hash digest
SHA256 bb9cdaed392a044e6f8c195c75df8db24ca58f19b6f270b12429c0771d4eff9f
MD5 7d2a76f39e118f1c2a53e3c450c40a76
BLAKE2b-256 f7f8a6561e00c6fd8ec291ef0b355e7d11d05d9c8295538ea638c1e9070ff292

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mdup-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 5.2 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 787ad5c5c1afa79e7bea9e618534b89be681708622a5891d20890dceb45f7dcc
MD5 3420d77839a39af5d0d7e8f6619a934a
BLAKE2b-256 050974ce5b15dfc6976525344f72f17c060601c031dff7e2751292fbac6c24d9

See more details on using hashes here.

Supported by

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