Mermaid extension for Python-Markdown using mermaid-cli.
Project description
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 JavaScript, even during web browsing.
Install
pip install markdown-mermaid-cli
Requirements
Mermaid CLI
npm install @mermaid-js/mermaid-cli
or
npm install --global @mermaid-js/mermaid-cli
Usage
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>
MkDocs Integration
# mkdocs.yml
markdown_extensions:
- markdown_mermaid_cli
Diagram
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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file markdown_mermaid_cli-0.1.0.tar.gz.
File metadata
- Download URL: markdown_mermaid_cli-0.1.0.tar.gz
- Upload date:
- Size: 68.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
443e449b986856aba92fb805d69957984fe1e7281ea41e9384fae1813d013dc1
|
|
| MD5 |
d0b15423abeb48720ed68dfd9fd4b1b5
|
|
| BLAKE2b-256 |
f2c445775369087f3192f06fa94d5f7f6379bd48d3d2af423c92c4800b7fc400
|
Provenance
The following attestation bundles were made for markdown_mermaid_cli-0.1.0.tar.gz:
Publisher:
publish-to-pypi.yml on hkato/markdown-mermaid-cli
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
markdown_mermaid_cli-0.1.0.tar.gz -
Subject digest:
443e449b986856aba92fb805d69957984fe1e7281ea41e9384fae1813d013dc1 - Sigstore transparency entry: 199877091
- Sigstore integration time:
-
Permalink:
hkato/markdown-mermaid-cli@1eecf126293c448000fec49c0d193ecd67e1d0b7 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/hkato
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@1eecf126293c448000fec49c0d193ecd67e1d0b7 -
Trigger Event:
push
-
Statement type:
File details
Details for the file markdown_mermaid_cli-0.1.0-py3-none-any.whl.
File metadata
- Download URL: markdown_mermaid_cli-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c5c246911a31522ceaf87eab5fcfedb150148ea8d516a9bb9d4426fce065c73
|
|
| MD5 |
9550ac9a09611bb95aa11bbcf3b8bc43
|
|
| BLAKE2b-256 |
d9cd5c5eee23560ec6591844c3fe6e5e6bb80a0eacaf498d83d293d6a52cac06
|
Provenance
The following attestation bundles were made for markdown_mermaid_cli-0.1.0-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on hkato/markdown-mermaid-cli
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
markdown_mermaid_cli-0.1.0-py3-none-any.whl -
Subject digest:
7c5c246911a31522ceaf87eab5fcfedb150148ea8d516a9bb9d4426fce065c73 - Sigstore transparency entry: 199877094
- Sigstore integration time:
-
Permalink:
hkato/markdown-mermaid-cli@1eecf126293c448000fec49c0d193ecd67e1d0b7 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/hkato
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@1eecf126293c448000fec49c0d193ecd67e1d0b7 -
Trigger Event:
push
-
Statement type: