Skip to main content

PRs Welcome Conventional Commits Github Actions PyPI Package latest release PyPI Package download count (per month) Supported versions

markdown-mermaidjs

Python-Markdown extension to add Mermaid graph

Getting Started

Prerequisites

Installation

For pip installation (only python version >=3.x) :

pip install markdown-mermaidjs

Usage

With Python Script

import markdown


text = """
# Title

Some text.

​```mermaid
graph TB
    A --> B
    B --> C
​```

Some other text.

​```mermaid
graph TB
    D --> E
    E --> F
​```
"""

html = markdown.markdown(text, extensions=["markdown-mermaidjs"])

print(html)

Expected output

<h1>Title</h1>
<p>Some text.</p>
<pre class="mermaid">
graph TB
    A --> B
    B --> C
</pre>

<p>Some other text.</p>
<pre class="mermaid">
graph TB
    D --> E
    E --> F
</pre>

<script type="module">
    import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs';
    mermaid.initialize({ startOnLoad: true });
</script>

Adding Custom Icon Packs

Some newer MermaidJS diagram types (most notably Architecture), support referencing custom icon packs that are registered (i.e. https://mermaid.js.org/config/icons.html).

To register packs, you can add them to the extension config with a structure of icon_packs: {"pack_name" : "pack_url" }, i.e.:

import markdown

html = markdown.markdown(
    text,
    extensions=["markdown-mermaidjs"],
    extension_configs={
        "markdown_mermaidjs": {
            "icon_packs": {
                "logos": "https://unpkg.com/@iconify-json/logos@1/icons.json",
                "hugeicons": "https://unpkg.com/@iconify-json/hugeicons@1/icons.json",
            }
        }
    },
)

The resulting HTML should be nearly identical, but the icon packs should be registered, e.g.:

<script type="module">
    import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs';
    mermaid.registerIconPacks([
        { name: 'logos', loader: () => fetch('https://unpkg.com/@iconify-json/logos@1/icons.json').then((res) => res.json()) },
        { name: 'hugeicons', loader: () => fetch('https://unpkg.com/@iconify-json/hugeicons@1/icons.json').then((res) => res.json()) }
    ]);
    mermaid.initialize({ startOnLoad: true });
</script>

Use it with Pelican

Add "markdown_mermaidjs": {} to MARKDOWN["extension_configs"] in your pelicanconf.py. For the default MARKDOWN configuration, it will look like the string below:

MARKDOWN = {
    "extension_configs": {
        "markdown.extensions.codehilite": {"css_class": "highlight"},
        "markdown.extensions.extra": {},
        "markdown.extensions.meta": {},
        "markdown_mermaidjs": {},  # <------ Our addition!
    },
    "output_format": "html5",
}

Icon Packs via Pelican

Similarly, with the extension config, you can add it in the pelicanconf.py.

MARKDOWN = {
    "extension_configs": {
        "markdown_mermaidjs": {
            "icon_packs": {
                "logos": "https://unpkg.com/@iconify-json/logos@1/icons.json",
                "hugeicons": "https://unpkg.com/@iconify-json/hugeicons@1/icons.json",
            }
        },
    },
}

Contributing

See Contributing

Authors

Wei Lee weilee.rx@gmail.com

This is a forked project of oruelle/md_mermaid

Created from Lee-W/cookiecutter-python-template version 3.0.0

Metadata

Release files for markdown-mermaidjs 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for markdown-mermaidjs 2.0.0
File Size Uploaded
markdown_mermaidjs-2.0.0.tar.gz 87.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for markdown-mermaidjs 2.0.0
File Interpreter ABI Platform
markdown_mermaidjs-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 104.7 kB

Release files / markdown_mermaidjs-2.0.0.tar.gz

Download URL markdown_mermaidjs-2.0.0.tar.gz
Size 87.9 kB
Tags Source
SHA-256 checksum
How to use checksums
96e875437a16cc936f04a3a007b65dbecd8d31e7dff36d5ad2aa7aefe64bb969
BLAKE2b-256 checksum
How to use checksums
7b1e1373dc6b128d80b479f7d902218b53b6828fcb9230194af3ae3ed052e05b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Release files / markdown_mermaidjs-2.0.0-py3-none-any.whl

Download URL markdown_mermaidjs-2.0.0-py3-none-any.whl
Size 16.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5590143c43d017ef2b325769331e3c095dea272ea06cdeead7ca4191e77099e8
BLAKE2b-256 checksum
How to use checksums
999c83475905bfb297f4a907c78d4e8baf7825ef422764d43be61fa731b3287a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page