markdown-mermaid-cli
Mermaid extension for Python-Markdown using Mermaid-CLI.
This extension converts Mermaid diagram code blocks into Base64 encoded data: URI. This enables PDF generation with tools like MkDocs to PDF/WeasyPrint without requiring client-side JavaScript.
Install
pip install markdown-mermaid-cli
Requirements
Mermaid CLI
Chrome or Chromium is required to run Mermaid-CLI.
npm install @mermaid-js/mermaid-cli
or
npm install --global @mermaid-js/mermaid-cli
Usage
- code block start with
```mermaid - code block end with
```
options:
formant=[svg|png] {img attribute}="value" {cli option}="value"`
- format (optional): Output image format (defaults to svg)
- img attribute (optional): alt, width, height, class, id, style, title
- cli option (optional): theme, width, height, backgroundColor, svgId, scale (refer to
mmdc -h)
MkDocs Integration
# mkdocs.yml
markdown_extensions:
- markdown_mermaid_cli
or with options:
# mkdocs.yml
markdown_extensions:
- markdown_mermaid_cli:
default_format: png # svg or png, default svg
Pelican Integration
# pelicanconf.py
MARKDOWN = {
'extension_configs': {
'markdown.extensions.codehilite': {'css_class': 'highlight'},
'markdown.extensions.extra': {},
'markdown_mermaid_cli': {}, # Add this
},
'output_format': 'html5',
}
Python code
import markdown
from markdown_mermaid_cli import MermaidExtension
markdown_text = """```mermaid
sequenceDiagram
participant Alice
participant Bob
Bob->>Alice: Hi Alice
Alice->>Bob: Hi Bob
```"""
html_output = markdown.markdown(
markdown_text, extensions=[MermaidExtension()]
)
print(html_output)
<p><img src="data:image/svg+xml;base64,PHN2ZyBhcmlhLXJvbGVkZXNjcmlwdGlvbj0ic2VxdWVuY2UiIHJvbGU
9ImdyYXBoaWNzLWRvY3VtZW50IGRvY3VtZW50IiB2aWV3Qm94PSItNTAgLTEwIDc1MCA1NzQiIHN0eWxlPSJtYXgtd2lkd
Gg6IDc1MHB4OyBiYWNrZ3JvdW5kLWNvbG9yOiB3aGl0ZTsiIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk
...
...
...
IHgxPSIyNzYiLz48L3N2Zz4=" ></p>
Process flow
sequenceDiagram
participant application as Application<br/>(eg MkDocs)
participant markdown as Python Markdown
participant extension as MermaidDataURIExtension
participant engine as Mermaid CLI
application->>markdown: Markdown + Mermaid
markdown->>extension: Preprocessor
extension->>engine: Mermaid
engine-->>engine: Convert
engine-->>extension: Image Data
extension-->>extension: Base64 encode
extension-->>markdown: Markdown + data URI image
markdown-->>application: HTML + data URI image
Metadata
Release files for markdown-mermaid-cli 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| markdown_mermaid_cli-0.3.1.tar.gz | 74.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| markdown_mermaid_cli-0.3.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 81.3 kB
Release files / markdown_mermaid_cli-0.3.1.tar.gz
| Download URL | markdown_mermaid_cli-0.3.1.tar.gz |
|---|---|
| Size | 74.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
03a729db97a5991e6e772dd0729b2097f7d573c2333b35c48fbc0468951bda7f
|
|
BLAKE2b-256 checksum How to use checksums |
b66e4ce81e1cda16511325eea1ca999de1e1b9b56e194026a2c9a29cacca9fe9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2025.
Transparency logRelease files / markdown_mermaid_cli-0.3.1-py3-none-any.whl
| Download URL | markdown_mermaid_cli-0.3.1-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
afff8a4c4886c88c3590cd8450b933a11a7a4163625a476521180663fa46e4a5
|
|
BLAKE2b-256 checksum How to use checksums |
85fa7cfc4a3847271401712399ff9828f67d58814b5374b200ddf46d06caa859
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2025.
Transparency log