Skip to main content

mkdocs-code-validator

Checks Markdown code blocks in a MkDocs site against user-defined actions

PyPI License GitHub Workflow Status

pip install mkdocs-code-validator

Usage

Activate the plugin in mkdocs.yml. The identifiers config is mandatory. And the plugin doesn't work without pymdownx.superfences:

plugins:
  - search
  - code-validator:
      identifiers:
        bash:
          validators:
            - grep a
markdown_extensions:
  - pymdownx.superfences

The above contrived config checks that every ```bash code block in the Markdown files of this MkDocs site must contain the letter "a", otherwise a warning will appear.

The content of each code block is piped as stdin to the command. The exit code of the command is what's checked: a non-zero code will produce a warning (which in MkDocs you can make fatal with the --strict flag). The output of the command is not used in any way, only preserved on the screen as part of a warning.

You can add any number of identifiers, and within them any number of validators commands, each of them has the ability to produce a warning.

If stdin is not usable with your command, the input can be passed as a temporary file instead -- that is done if the command contains the exact argument $< (which is then replaced with a file path). For the above example, changing the command to grep a $< would be equivalent (other than technicalities).

The commands do not allow freeform shell syntax, it's just one subprocess to call with its arguments. To explicitly opt into a shell, just run it as (e.g.) sh -c 'if grep a; then exit 1; fi'. Or, with a temporary file: sh -c 'if grep a "$1"; then exit 1; fi' $<.

The definition of what a code block is is all according to the pymdownx.superfences extension. It must be enabled; the plugin won't do anything without it.

Metadata

Release files for mkdocs-code-validator 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mkdocs-code-validator 0.1.1
File Size Uploaded
mkdocs-code-validator-0.1.1.tar.gz 5.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mkdocs-code-validator 0.1.1
File Interpreter ABI Platform
mkdocs_code_validator-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 10.9 kB

Release files / mkdocs-code-validator-0.1.1.tar.gz

Download URL mkdocs-code-validator-0.1.1.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b27a13bbc99abc5cde8da491ed323f26d154d5274a4b5ce0fa6ba956b1361e56
BLAKE2b-256 checksum
How to use checksums
96cb5d351772e92e867958cc706ed88a651dfd6a83c05663edba133baff401f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/3.9.6 Linux/5.13.10-arch1-1

Release files / mkdocs_code_validator-0.1.1-py3-none-any.whl

Download URL mkdocs_code_validator-0.1.1-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
529573bc990e2ea2a9255608efd145cb522f95e6e223146ab75d57e41270d29e
BLAKE2b-256 checksum
How to use checksums
eca5a35893b12ae096bd2e8653f84283e79a909b2f9c716ad5d1fc97f85352ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/3.9.6 Linux/5.13.10-arch1-1

Release history Release notifications | RSS feed

0.2.1

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page