markdown-diagrams
Extract and render Mermaid diagrams from Markdown files to PNG, SVG, and PDF.
Features
- Extract Mermaid diagrams from any Markdown file
- Render diagrams to PNG, SVG, and PDF formats
- Automatically name output files based on bold-text titles or document headings
- Support for 19 diagram types (flowchart, sequence, ER, class, state, gantt, and more)
- Extensible architecture for additional diagram types
Prerequisites
Rendering requires the Mermaid CLI:
npm install -g @mermaid-js/mermaid-cli
Installation
From PyPI
pip install markdown-diagrams
From source
git clone https://github.com/bryankemp/markdown-diagrams.git
cd markdown-diagrams
pip install -e .
Usage
Extract and render all diagrams
markdown-diagrams extract document.md
Specify an output directory
markdown-diagrams extract document.md -o ./output
Filter by diagram type
markdown-diagrams extract document.md -t mermaid -t flowchart
Choose an output format
# PNG (default)
markdown-diagrams extract document.md -f png
# SVG
markdown-diagrams extract document.md -f svg
# PDF
markdown-diagrams extract document.md -f pdf
Custom dimensions and theme
markdown-diagrams extract document.md -w 1000 -H 800 -T dark
Validate diagrams
# Check all diagrams for syntax errors
markdown-diagrams validate document.md
# Auto-fix common issues (whitespace, unquoted labels)
markdown-diagrams validate document.md --fix
# Preview fixes without writing
markdown-diagrams validate document.md --dry-run
Supported Diagram Types
mermaid · flowchart · sequence · graph · gantt · pie · mindmap ·
quadrantDiagram · er · class · state · journey · gitGraph ·
userJourney · requirement · c4 · entityRelationship · component · active
Filename strategy
When a bold-text title (e.g. **Flowchart – License Injection**) appears
directly above a code fence, it is used as the output filename. Otherwise
the nearest #-heading is used. This means documents that follow the
common pattern of a generic ### Diagrams heading with descriptive bold
titles per diagram will get meaningful filenames automatically.
Python API
from markdown_diagrams import extract_diagrams, render_mermaid_diagram
from pathlib import Path
# Extract diagrams
diagrams = extract_diagrams(Path("document.md"))
for diagram_type, items in diagrams.items():
for item in items:
print(f"[{diagram_type}] {item['heading']}: {len(item['content'])} chars")
# Render a single diagram
render_mermaid_diagram(items[0]["content"], output_dir="./output")
Examples
See examples/all_diagram_types.md for a
complete reference with every supported diagram type.
Development
pip install -e ".[dev]"
pytest
black --check .
ruff check .
Documentation
Full documentation is available at markdown-diagrams.readthedocs.io.
Contributing
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
License
BSD 3-Clause License — see LICENSE for details.
Metadata
Release files for markdown-diagrams 1.0.0
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_diagrams-1.0.0.tar.gz | 24.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| markdown_diagrams-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 42.2 kB
Release files / markdown_diagrams-1.0.0.tar.gz
| Download URL | markdown_diagrams-1.0.0.tar.gz |
|---|---|
| Size | 24.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
15371e9c7629386aeab43033c81065d0310cab22a11b6ba743b78c4a36fd2a33
|
|
BLAKE2b-256 checksum How to use checksums |
e1c4a792d5784f47463b2413780564dd2ae81e48139ba3540480b0fa91e894f7
|
| 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 Mar 16, 2026.
Transparency logRelease files / markdown_diagrams-1.0.0-py3-none-any.whl
| Download URL | markdown_diagrams-1.0.0-py3-none-any.whl |
|---|---|
| Size | 18.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f28403d40d96051b4cbe01e60c600fd90eda08516e025656ae79225c433a1598
|
|
BLAKE2b-256 checksum How to use checksums |
651237dac289d9dc59b32a078640c3d3e48e64ab8502b45ce5eb4330d6b330c4
|
| 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 Mar 16, 2026.
Transparency log