Utilities to execute code blocks in Markdown files.
Project description
Markdown Exec
Utilities to execute code blocks in Markdown files.
For example, you write a Python code block that computes some HTML, and this HTML is injected in place of the code block.
Installation
With pip
:
pip install markdown-exec[ansi]
The ansi
extra provides the necessary bits (pygments-ansi-color
and a CSS file)
to render ANSI colors in HTML code blocks. The CSS file is automatically added
to MkDocs' extra_css
when Markdown Exec is activated via plugins
(see below).
Configuration
This extension relies on the SuperFences extension of PyMdown Extensions.
To allow execution of code blocks, configure a custom fence from Python:
from markdown import Markdown
from markdown_exec import formatter, validator
Markdown(
extensions=["pymdownx.superfences"],
extension_configs={
"pymdownx.superfences": {
"custom_fences": [
{
"name": "python",
"class": "python",
"validator": validator,
"format": formatter,
}
# ...one fence for each language we support:
# bash, console, md, markdown, py, python, pycon, sh, tree
]
}
}
)
...or in MkDocs configuration file, as a Markdown extension:
# mkdocs.yml
markdown_extensions:
- pymdownx.superfences:
custom_fences:
- name: python
class: python
validator: !!python/name:markdown_exec.validator
format: !!python/name:markdown_exec.formatter
# ...one fence for each language we support:
# bash, console, md, markdown, py, python, pycon, sh, tree
...or in MkDocs configuration file, as a plugin:
# mkdocs.yml
plugins:
- search
- markdown-exec
Usage
You are now able to execute code blocks instead of displaying them:
```python exec="on"
print("Hello Markdown!")
```
The exec
option will be true for every possible value except 0
, no
, off
and false
(case insensitive).
See usage for more details, and the gallery for more examples!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for markdown_exec-1.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67d55ea5934b8a6194e43ea9b6e9243637991a29033956e5043e964276bfe92a |
|
MD5 | 9844b29d25944557d91c40ad280a3999 |
|
BLAKE2b-256 | cfc4fb6497f8cc666216578910ef5b30c06a9b36aafa442cfffa479c72cb9059 |