Render Mermaid diagrams to ASCII/Unicode art
Project description
mermaid-ascii-diagrams
Render Mermaid diagrams to terminal-friendly text (ASCII/Unicode). This tool extracts fenced ```mermaid blocks from Markdown and renders them as Unicode box-drawing diagrams.
Features
- CLI to render Mermaid code blocks from Markdown
- Supports
flowchart/graphandsequenceDiagram - Parses
classDiagramandstateDiagram/stateDiagram-v2into a generic graph renderer (limited) - No browser / no JavaScript
Installation
pip install mermaid-ascii-diagrams
Requires Python 3.10+.
Command-line usage
Render all Mermaid blocks in a Markdown file:
mermaid-ascii diagram.md
Read Markdown from stdin:
cat diagram.md | mermaid-ascii -
Write output to a file:
mermaid-ascii diagram.md -o diagram.txt
Render only the first block:
mermaid-ascii --first diagram.md
Render a specific block (0-based index):
mermaid-ascii --index 1 diagram.md
Wrap each rendered diagram in a Markdown ```text fence:
mermaid-ascii --markdown diagram.md
Notes:
- When multiple Mermaid blocks are rendered, outputs are separated by a
--------------------divider. - If no Mermaid blocks are found (or
--indexis out of range), the CLI prints an error message and exits non-zero.
Example
Input (Markdown):
```mermaid
flowchart LR
A([Start]) --> B{Valid?}
B --> C[Continue]
B --> D[Error]
C --> E([End])
D --> E
```
Output (text):
╭───────╮ ╱──────╲ ┌──────────┐
│ Start ├──────► Valid? │──► Continue ├──┐
╰───────╯ ╲──────╱ └──────────┘ │
┌─────┴───╮
│ End │
╰─────────╯
┌───────┐ ▲
│ Error │─────────────┘
└───────┘
(Exact output depends on terminal width and diagram complexity.)
Supported syntax (current)
Flowcharts (flowchart / graph):
- Directions:
TB,BT,LR,RL - Edges:
-->,---,==> - Node shapes:
A[Label]boxA{Label}diamondA([Label])rounded/terminator
- Edge labels like
A -->|yes| Bare currently ignored (the edge is still drawn).
Sequence diagrams (sequenceDiagram):
participant Nameandparticipant Name as Label- Messages with arrows:
->,->>,-->,-->>, and--(line without arrowhead) activate Name/deactivate Name+/-receiver flags on messages (activate/deactivate the receiver)
Class/state diagrams:
classDiagram,stateDiagram/stateDiagram-v2are parsed into a generic graph and rendered with the flowchart renderer.- Many Mermaid features (styling, subgraphs, notes, etc.) are ignored.
Python usage
from mermaid_ascii import parse_mermaid, render_ascii
src = """
flowchart LR
A --> B
"""
diagram = parse_mermaid(src)
print(render_ascii(diagram))
License
MIT License
Contributing
Issues and pull requests are welcome.
If you're adding new syntax support or changing layout/routing, please include before/after rendered output examples (ideally from real Mermaid snippets).
Project details
Release history Release notifications | RSS feed
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 mermaid_ascii_diagrams-0.1.1.tar.gz.
File metadata
- Download URL: mermaid_ascii_diagrams-0.1.1.tar.gz
- Upload date:
- Size: 14.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0bd8dcf3b57361a37d9c10853b3190bf7916b7c8f12cec2dd37bfaad23de485
|
|
| MD5 |
fe209c246bac351e0d20c4c3d2ac7771
|
|
| BLAKE2b-256 |
bb173647eeae316dcb3ec8a6b4bf8290d898e838f4274577e6e7b13a1884ce99
|
File details
Details for the file mermaid_ascii_diagrams-0.1.1-py3-none-any.whl.
File metadata
- Download URL: mermaid_ascii_diagrams-0.1.1-py3-none-any.whl
- Upload date:
- Size: 16.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6098969993011fa989998ee6c7f6c8021f27ddf8f9556f6b5b82361039d2b4ad
|
|
| MD5 |
cdb206813ceacb15e46acef958152fe2
|
|
| BLAKE2b-256 |
eae6e42a90b54763c21d2072c6f2838400d1de2f6ce85a1d728c9141f167a501
|