Render Mermaid diagrams as Unicode box-drawing art in the terminal
Project description
mermaid-term
[!WARNING] This is a vibe-coded port: the Claude Fable 5 AI model translated the upstream Rust module to Python with minimal human review. The ported test suite passes, but read the code with that in mind.
Render Mermaid diagrams as Unicode box-drawing art in your terminal. No browser, no Node, no image files.
This is a Python port of the terminal Mermaid renderer from
xai-org/grok-build
(crates/codegen/xai-grok-markdown/src/mermaid.rs), including its test suite.
The diagram source for this demo is in docs/flow.mmd.
Supported diagram types
graph/flowchart(all directions, subgraphs,&fan-out, edge labels, dotted/thick lines, circle/cross/arrow heads, self-loops)stateDiagram/stateDiagram-v2classDiagram(compartments, annotations, generics, cardinalities)erDiagram(attributes, cardinalities)sequenceDiagram(notes, dividers, autonumber, self-messages)
Anything else (gantt, pie, ...) renders as the raw source in a framed box.
Install / run
Run without installing, via uv:
uvx mermaid-term diagram.mmd
Or install as a persistent tool:
uv tool install mermaid-term
Works on Windows, macOS, and Linux (pure Python, one small dependency).
Usage
mermaid-term diagram.mmd # render a file
cat diagram.mmd | mermaid-term # or read stdin
mermaid-term --markdown README.md # render every ```mermaid fence in a Markdown file
mermaid-term -w 60 diagram.mmd # cap the diagram width at 60 columns
mermaid-term -w 0 diagram.mmd # no width limit
mermaid-term --color always diagram.mmd | less -R
--widthdefaults to the terminal width when stdout is a terminal and unlimited otherwise. Diagrams that exceed the width limit fall back to the framed source with a hint.--colorisautoby default: ANSI styling on a terminal, plain text when piped.NO_COLORis respected.
Library use
from mermaid_term import render, MermaidStyles
art = render("graph TD\n A --> B", MermaidStyles.plain(), max_width=80)
print("\n".join(art.plain_lines)) # plain text
print("\n".join(l.to_ansi() for l in art.styled_lines)) # ANSI-styled
render returns None for blank input. Unsupported or oversized diagrams
return the framed-source fallback rather than raising.
Development
uv sync
uv run pytest
The test suite is ported from the upstream Rust module and pins parser behavior and rendered output; new rendering changes should keep it green.
License
Apache-2.0, the same license as the upstream project this is ported from.
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_term-0.1.0.tar.gz.
File metadata
- Download URL: mermaid_term-0.1.0.tar.gz
- Upload date:
- Size: 34.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a51632eaded26ef25d94bff61452febe53b62e4e0c152c78866dd745ce0d930f
|
|
| MD5 |
a0f90a3b5cfb9cfe98acb7c19a8ee567
|
|
| BLAKE2b-256 |
99fafea3ddcc9dd8d60f24ecf7f9be31e80177ed38e5d3110667654842d3e32b
|
File details
Details for the file mermaid_term-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mermaid_term-0.1.0-py3-none-any.whl
- Upload date:
- Size: 44.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d509411e41d2fb18ad605b7f867946919c55bf50c724eaf22bd4312d07f953f
|
|
| MD5 |
f37496be9541a2634049e44deb0ff60a
|
|
| BLAKE2b-256 |
c966099dd6d2fbb96a5bf6f92555be7aedad4c453ac30c42d9ba5bb457a095e4
|