Skip to main content

Hide code blocks from the rendered markdown output, useful for running tests on your documentation.

Project description

markdown-hide-code

An small extension for Python's Markdown library that hides code blocks marked with hide from the markdown output. This is useful when developers want to include unit tests in their markdown documentation (e.g., using pytest-markdown-docs) but don't want those tests to be visible to documentation readers. I created this extension while developing Pyoframe.

```python {hide}
# This code block will be hidden in the rendered markdown.
```

Install

pip install markdown-hide-code

Usage with mkdocs

Add the extension to your mkdocs.yml configuration:

markdown_extensions:
  ...
  - pymdownx.superfences
  - attr_list
  - markdown_hide_code  # must appear after superfences and attr_list
    ...

[!WARNING] pymdownx.superfences and attr_list are required dependencies and must be listed BEFORE markdown-hide-code.

Then, to hide a code block simply add {hide}:

```python {hide}
# This code block will be hidden in the output
```

Usage directly with the Markdown library

Just add the extension to the list. Order matters (see above warning).

from markdown import Markdown

md = Markdown(extensions=["pymdownx.superfences", "attr_list", "markdown_hide_code"])
...

Notes for contributors (and myself)

Clone the repo and run uv sync and pre-commit install to get setup. The core code is all found in src/markdown_hide_code/main.py.

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

markdown_hide_code-0.1.1.tar.gz (20.5 kB view details)

Uploaded Source

Built Distribution

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

markdown_hide_code-0.1.1-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file markdown_hide_code-0.1.1.tar.gz.

File metadata

  • Download URL: markdown_hide_code-0.1.1.tar.gz
  • Upload date:
  • Size: 20.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for markdown_hide_code-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5cc359cd44fc93cbc4903d0a39189697d8e17f8fcb636234b7e7fd6ed559eb1e
MD5 dea496a626dbf3c99287dfeb4708613c
BLAKE2b-256 21dc026c7f49c225f1c9addd41dac63b1e3a86146642f8ddec3a3824b891732d

See more details on using hashes here.

Provenance

The following attestation bundles were made for markdown_hide_code-0.1.1.tar.gz:

Publisher: publish_to_pypi.yml on staadecker/markdown-hide-code

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

File details

Details for the file markdown_hide_code-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for markdown_hide_code-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7ed3bb577c77e9fc0d9ba4fed39144b85593bf2dbf2e2eef74cbb582c6397cb3
MD5 3a58db4c1392cfb8357422c4177e4d48
BLAKE2b-256 8dc24e6c76cfded3e231bfe19ec1948bcf8cbf3c8e8f86fedcad1664a3fdee31

See more details on using hashes here.

Provenance

The following attestation bundles were made for markdown_hide_code-0.1.1-py3-none-any.whl:

Publisher: publish_to_pypi.yml on staadecker/markdown-hide-code

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