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.2.1.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

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

mkdocs_code_validator-0.2.1-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mkdocs_code_validator-0.2.1.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mkdocs_code_validator-0.2.1.tar.gz
Algorithm Hash digest
SHA256 7ecf0fdf0b27464a12008ea835cfe5af9d18dbc8743fd892c88e759550eedeb4
MD5 390b49d058d355de95a0e8379dc4e4a1
BLAKE2b-256 1b9f170641aefa18d6bf860e14129fbb509ef4c840dab1938917f40229552987

See more details on using hashes here.

Provenance

The following attestation bundles were made for mkdocs_code_validator-0.2.1.tar.gz:

Publisher: deploy-release.yml on oprypin/mkdocs-code-validator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for mkdocs_code_validator-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e6874be1d7f396dfaab45e487bbcbcae2be387e8845ebf0d4bbea39486d982a3
MD5 529588db398bc2353a58806499b0c677
BLAKE2b-256 629492bdf3dc81735020b4c114b5e57770676e365aa7ad4b929bd7acfdd3307f

See more details on using hashes here.

Provenance

The following attestation bundles were made for mkdocs_code_validator-0.2.1-py3-none-any.whl:

Publisher: deploy-release.yml on oprypin/mkdocs-code-validator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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