markdown-mermaid-cli


Namemarkdown-mermaid-cli JSON
Version 0.2.2 PyPI version JSON
download
home_pageNone
SummaryMermaid extension for Python-Markdown using mermaid-cli.
upload_time2025-08-14 23:36:47
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseNone
keywords markdown mermaid mkdocs
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # [markdown-mermaid-cli](https://hkato.github.io/markdown-mermaid-cli/)

[![PyPI version](https://img.shields.io/pypi/v/markdown-mermaid-cli)](https://pypi.org/project/markdown-mermaid-cli/)
![License](https://img.shields.io/pypi/l/markdown-mermaid-cli)
![Python versions](https://img.shields.io/pypi/pyversions/markdown-mermaid-cli)

[Mermaid][mermaid] extension for [Python-Markdown][python-markdown] using [Mermaid-CLI][mermaid-cli].

This extension converts Mermaid diagram code blocks into Base64 encoded [data: URI][data-uri].
This enables PDF generation with tools like [MkDocs to PDF][mkdocs-to-pdf]/[WeasyPrint][wasyprint]
without requiring client-side JavaScript.

## Install

```sh
pip install markdown-mermaid-cli
```

## Requirements

### Mermaid CLI

> Chrome or Chromium is required to run Mermaid-CLI.

```sh
npm install @mermaid-js/mermaid-cli
```

or

```sh
npm install --global @mermaid-js/mermaid-cli
```

## Usage

- code block start with <code>```mermaid</code>
- code block end with <code>```</code>

options:

```markdown
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][mkdocs] Integration

```yaml
# mkdocs.yml
markdown_extensions:
  - markdown_mermaid_cli
```

### [Pelican][pelican] Integration

```py
# pelicanconf.py
MARKDOWN = {
    'extension_configs': {
        'markdown.extensions.codehilite': {'css_class': 'highlight'},
        'markdown.extensions.extra': {},
        'markdown_mermaid_cli': {},             # Add this
    },
    'output_format': 'html5',
}
```

### Python code

````python
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)
````

```html
<p><img src="data:image/svg+xml;base64,PHN2ZyBhcmlhLXJvbGVkZXNjcmlwdGlvbj0ic2VxdWVuY2UiIHJvbGU
9ImdyYXBoaWNzLWRvY3VtZW50IGRvY3VtZW50IiB2aWV3Qm94PSItNTAgLTEwIDc1MCA1NzQiIHN0eWxlPSJtYXgtd2lkd
Gg6IDc1MHB4OyBiYWNrZ3JvdW5kLWNvbG9yOiB3aGl0ZTsiIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk
...
...
...
IHgxPSIyNzYiLz48L3N2Zz4=" ></p>
```

## Process flow

```mermaid
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
```

[mermaid]: https://mermaid.js.org/
[python-markdown]: https://python-markdown.github.io/
[mermaid-cli]: https://github.com/mermaid-js/mermaid-cli
[data-uri]: https://developer.mozilla.org/en-US/docs/Web/URI/Reference/Schemes/data
[mkdocs-to-pdf]: https://mkdocs-to-pdf.readthedocs.io/
[wasyprint]: https://weasyprint.org/
[mkdocs]: https://www.mkdocs.org/
[pelican]: https://getpelican.com/

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "markdown-mermaid-cli",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "markdown, mermaid, mkdocs",
    "author": null,
    "author_email": "Hideyuki KATO <hideyuki@kato.jp>",
    "download_url": "https://files.pythonhosted.org/packages/81/73/3c9b77be191a417b074063ff1d3c80fc46aff540e776a81727ebade7906f/markdown_mermaid_cli-0.2.2.tar.gz",
    "platform": null,
    "description": "# [markdown-mermaid-cli](https://hkato.github.io/markdown-mermaid-cli/)\n\n[![PyPI version](https://img.shields.io/pypi/v/markdown-mermaid-cli)](https://pypi.org/project/markdown-mermaid-cli/)\n![License](https://img.shields.io/pypi/l/markdown-mermaid-cli)\n![Python versions](https://img.shields.io/pypi/pyversions/markdown-mermaid-cli)\n\n[Mermaid][mermaid] extension for [Python-Markdown][python-markdown] using [Mermaid-CLI][mermaid-cli].\n\nThis extension converts Mermaid diagram code blocks into Base64 encoded [data: URI][data-uri].\nThis enables PDF generation with tools like [MkDocs to PDF][mkdocs-to-pdf]/[WeasyPrint][wasyprint]\nwithout requiring client-side JavaScript.\n\n## Install\n\n```sh\npip install markdown-mermaid-cli\n```\n\n## Requirements\n\n### Mermaid CLI\n\n> Chrome or Chromium is required to run Mermaid-CLI.\n\n```sh\nnpm install @mermaid-js/mermaid-cli\n```\n\nor\n\n```sh\nnpm install --global @mermaid-js/mermaid-cli\n```\n\n## Usage\n\n- code block start with <code>```mermaid</code>\n- code block end with <code>```</code>\n\noptions:\n\n```markdown\nformant=[svg|png] {img attribute}=\"value\" {cli option}=\"value\"`\n```\n\n- format (optional): Output image format (defaults to svg)\n- img attribute (optional): alt, width, height, class, id, style, title\n- cli option (optional): theme, width, height, backgroundColor, svgId, scale (refer to `mmdc -h`)\n\n### [MkDocs][mkdocs] Integration\n\n```yaml\n# mkdocs.yml\nmarkdown_extensions:\n  - markdown_mermaid_cli\n```\n\n### [Pelican][pelican] Integration\n\n```py\n# pelicanconf.py\nMARKDOWN = {\n    'extension_configs': {\n        'markdown.extensions.codehilite': {'css_class': 'highlight'},\n        'markdown.extensions.extra': {},\n        'markdown_mermaid_cli': {},             # Add this\n    },\n    'output_format': 'html5',\n}\n```\n\n### Python code\n\n````python\nimport markdown\nfrom markdown_mermaid_cli import MermaidExtension\n\nmarkdown_text = \"\"\"```mermaid\nsequenceDiagram\n    participant Alice\n    participant Bob\n    Bob->>Alice: Hi Alice\n    Alice->>Bob: Hi Bob\n```\"\"\"\n\nhtml_output = markdown.markdown(\n    markdown_text, extensions=[MermaidExtension()]\n)\n\nprint(html_output)\n````\n\n```html\n<p><img src=\"data:image/svg+xml;base64,PHN2ZyBhcmlhLXJvbGVkZXNjcmlwdGlvbj0ic2VxdWVuY2UiIHJvbGU\n9ImdyYXBoaWNzLWRvY3VtZW50IGRvY3VtZW50IiB2aWV3Qm94PSItNTAgLTEwIDc1MCA1NzQiIHN0eWxlPSJtYXgtd2lkd\nGg6IDc1MHB4OyBiYWNrZ3JvdW5kLWNvbG9yOiB3aGl0ZTsiIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk\n...\n...\n...\nIHgxPSIyNzYiLz48L3N2Zz4=\" ></p>\n```\n\n## Process flow\n\n```mermaid\nsequenceDiagram\n    participant application as Application<br/>(eg MkDocs)\n    participant markdown as Python Markdown\n    participant extension as MermaidDataURIExtension\n    participant engine as Mermaid CLI\n\n    application->>markdown: Markdown + Mermaid\n    markdown->>extension: Preprocessor\n    extension->>engine: Mermaid\n    engine-->>engine: Convert\n    engine-->>extension: Image Data\n    extension-->>extension: Base64 encode\n    extension-->>markdown: Markdown + data URI image\n    markdown-->>application: HTML + data URI image\n```\n\n[mermaid]: https://mermaid.js.org/\n[python-markdown]: https://python-markdown.github.io/\n[mermaid-cli]: https://github.com/mermaid-js/mermaid-cli\n[data-uri]: https://developer.mozilla.org/en-US/docs/Web/URI/Reference/Schemes/data\n[mkdocs-to-pdf]: https://mkdocs-to-pdf.readthedocs.io/\n[wasyprint]: https://weasyprint.org/\n[mkdocs]: https://www.mkdocs.org/\n[pelican]: https://getpelican.com/\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Mermaid extension for Python-Markdown using mermaid-cli.",
    "version": "0.2.2",
    "project_urls": {
        "Changelog": "https://github.com/hkato/markdown-mermaid-cli/blob/main/CHANGELOG.md",
        "Documentation": "https://hkato.github.io/markdown-mermaid-cli/",
        "Homepage": "https://github.com/hkato/markdown-mermaid-cli",
        "Issues": "https://github.com/hkato/markdown-mermaid-cli/issues",
        "Repository": "https://github.com/hkato/markdown-mermaid-cli"
    },
    "split_keywords": [
        "markdown",
        " mermaid",
        " mkdocs"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "397c44512397e573dacd1e047a2425f2ca2ed84b39db96fe8d530aa8d047103c",
                "md5": "26faf74ec009b34d86b73f883529c4e4",
                "sha256": "3dbf7a14d94b74c476d710a02e3816d8b5a31b3d7d2e5ac9e29f12a304265eb4"
            },
            "downloads": -1,
            "filename": "markdown_mermaid_cli-0.2.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "26faf74ec009b34d86b73f883529c4e4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 6228,
            "upload_time": "2025-08-14T23:36:46",
            "upload_time_iso_8601": "2025-08-14T23:36:46.299931Z",
            "url": "https://files.pythonhosted.org/packages/39/7c/44512397e573dacd1e047a2425f2ca2ed84b39db96fe8d530aa8d047103c/markdown_mermaid_cli-0.2.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "81733c9b77be191a417b074063ff1d3c80fc46aff540e776a81727ebade7906f",
                "md5": "b6529486c2afc15bfc6e59e63bc1df20",
                "sha256": "3915f622284fb04ac2d748116d1198f3a15e93b19559de913de3b835e557129d"
            },
            "downloads": -1,
            "filename": "markdown_mermaid_cli-0.2.2.tar.gz",
            "has_sig": false,
            "md5_digest": "b6529486c2afc15bfc6e59e63bc1df20",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 74522,
            "upload_time": "2025-08-14T23:36:47",
            "upload_time_iso_8601": "2025-08-14T23:36:47.864998Z",
            "url": "https://files.pythonhosted.org/packages/81/73/3c9b77be191a417b074063ff1d3c80fc46aff540e776a81727ebade7906f/markdown_mermaid_cli-0.2.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-14 23:36:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hkato",
    "github_project": "markdown-mermaid-cli",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "markdown-mermaid-cli"
}
        
Elapsed time: 0.83359s