Skip to main content

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

Project description

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.

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

mkdocs-code-validator-0.1.2.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

mkdocs_code_validator-0.1.2-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file mkdocs-code-validator-0.1.2.tar.gz.

File metadata

  • Download URL: mkdocs-code-validator-0.1.2.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.9.9 Linux/5.15.6-arch2-1

File hashes

Hashes for mkdocs-code-validator-0.1.2.tar.gz
Algorithm Hash digest
SHA256 19005c5f6033a99be7144a1e63e1bdfaa27c656480441ee7a590a38c3bb50873
MD5 cfaee010d478caed29494b6ecfedb39e
BLAKE2b-256 2776a8d530a8f77e416e17c3c85475168e60f4ef4445b53d9b01092893350e5f

See more details on using hashes here.

Provenance

File details

Details for the file mkdocs_code_validator-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for mkdocs_code_validator-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 200307ab7f5e2c4cb54c0846d9d9b8bb319ec0c7e3b0561c7b6a443b5e93a522
MD5 9d433a2736a605da95f5d5b703b56d93
BLAKE2b-256 4fc8d1dfea3b0c2f5e9970d93a42c517c4f8cdb3f6a24054bcf4bb0fb158d5af

See more details on using hashes here.

Provenance

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