Render mermaid diagrams in your terminal:
You can download the binary from Github releases:
# Get the latest release
$ curl -s https://api.github.com/repos/AlexanderGrooff/mermaid-ascii/releases/latest | grep "browser_download_url.*mermaid-ascii" | grep "$(uname)_$(uname -m)" | cut -d: -f2,3 | tr -d \" | wget -qi -
# Unzip it
$ tar xvzf mermaid-ascii_*.tar.gz
$ ./mermaid-ascii --helpYou can also build it yourself:
$ git clone
$ cd mermaid-ascii
$ go build
$ mermaid-ascii --helpOr using Nix:
$ git clone
$ cd mermaid-ascii
$ nix build
$ ./result/bin/mermaid-ascii --helpYou can render graphs directly from the command line or start a web interface to render them interactively.
$ cat test.mermaid
graph LR
A --> B & C
B --> C & D
D --> C
$ mermaid-ascii --file test.mermaid
βββββ βββββ βββββ
β β β β β β
β A ββββββΊβ B ββββββΊβ D β
β β β β β β
βββ¬ββ βββ¬ββ βββ¬ββ
β β β
β β β
β β β
β β β
β βΌ β
β βββββ β
β β β β
ββββββββΊβ C βββββββββ
β β
βββββ
# Increase horizontal spacing
$ mermaid-ascii --file test.mermaid -x 8
βββββ βββββ βββββ
β β β β β β
β A βββββββββΊβ B βββββββββΊβ D β
β β β β β β
βββ¬ββ βββ¬ββ βββ¬ββ
β β β
β β β
β β β
β β β
β βΌ β
β βββββ β
β β β β
βββββββββββΊβ C ββββββββββββ
β β
βββββ
# Increase box padding
$ mermaid-ascii -f ./test.mermaid -p 3
βββββββββ βββββββββ βββββββββ
β β β β β β
β β β β β β
β β β β β β
β A ββββββΊβ B ββββββΊβ D β
β β β β β β
β β β β β β
β β β β β β
βββββ¬ββββ βββββ¬ββββ βββββ¬ββββ
β β β
β β β
β β β
β β β
β βΌ β
β βββββββββ β
β β β β
β β β β
β β β β
ββββββββββΊβ C βββββββββββ
β β
β β
β β
βββββββββ
# Labeled edges
$ cat test.mermaid
graph LR
A --> B
A --> C
B --> C
B -->|example| D
D --> C
$ mermaid-ascii -f ./test.mermaid
βββββ βββββ βββββ
β β β β β β
β A ββββββΊβ B ββexampleβΊβ D β
β β β β β β
βββ¬ββ βββ¬ββ βββ¬ββ
β β β
β β β
β β β
β β β
β βΌ β
β βββββ β
β β β β
ββββββββΊβ C βββββββββββββ
β β
βββββ
# Top-down layout
$ cat test.mermaid
graph TD
A --> B
A --> C
B --> C
B -->|example| D
D --> C
$ mermaid-ascii -f ./test.mermaid
βββββββββββ
β β
β A βββββββββ
β β β
ββββββ¬βββββ β
β β
β β
β β
β β
βΌ βΌ
βββββββββββ βββββ
β β β β
β B ββββββΊβ C β
β β β β
ββββββ¬βββββ βββββ
β β²
β β
example β
β β
βΌ β
βββββββββββ β
β β β
β D βββββββββ
β β
βββββββββββ
# Read from stdin
$ cat test.mermaid | mermaid-ascii
βββββ βββββ βββββ
β β β β β β
β A ββββββΊβ B ββββββΊβ D β
β β β β β β
βββ¬ββ βββ¬ββ βββ¬ββ
β β β
β β β
β β β
β β β
β βΌ β
β βββββ β
β β β β
ββββββββΊβ C βββββββββ
β β
βββββ
# Only ASCII
$ cat test.mermaid | mermaid-ascii --ascii
+---+ +---+ +---+
| | | | | |
| A |---->| B |---->| D |
| | | | | |
+---+ +---+ +---+
| | |
| | |
| | |
| | |
| v |
| +---+ |
| | | |
------->| C |<-------
| |
+---+
# Using Docker
$ docker build -t mermaid-ascii .
$ echo 'sequenceDiagram
Alice->>Bob: Hello
Bob-->>Alice: Hi' | docker run -i mermaid-ascii -f -
βββββββββ βββββββ
β Alice β β Bob β
βββββ¬ββββ ββββ¬βββ
β β
β Hello β
βββββββββββββΊβ
β β
β Hi β
ββββββββββββββ€
β β
# Graph diagrams work too
$ echo 'graph LR
A-->B-->C' | docker run -i mermaid-ascii -f -
βββββ βββββ βββββ
β β β β β β
β A ββββββΊβ B ββββββΊβ C β
β β β β β β
βββββ βββββ βββββ
# Run web interface
$ docker run -p 3001:3001 mermaid-ascii web --port 3001
# Then visit http://localhost:3001Sequence diagrams are also fully supported! They visualize message flows between participants over time.
# Simple sequence diagram
$ cat sequence.mermaid
sequenceDiagram
Alice->>Bob: Hello Bob!
Bob-->>Alice: Hi Alice!
$ mermaid-ascii -f sequence.mermaid
βββββββββ βββββββ
β Alice β β Bob β
βββββ¬ββββ ββββ¬βββ
β β
β Hello Bob! β
βββββββββββββΊβ
β β
β Hi Alice! β
ββββββββββββββ€
β β
# Solid arrows (->>) and dotted arrows (-->>)
$ cat sequence.mermaid
sequenceDiagram
Client->>Server: Request
Server-->>Client: Response
$ mermaid-ascii -f sequence.mermaid
βββββββοΏ½οΏ½ββ ββββββββββ
β Client β β Server β
βββββ¬βββββ βββββ¬βββββ
β β
β Request β
βββββββββββββββΊβ
β β
β Response β
ββββββββββββββββ€
β β
# Multiple participants
$ cat sequence.mermaid
sequenceDiagram
Alice->>Bob: Hello!
Bob->>Charlie: Forward message
Charlie-->>Alice: Got it!
$ mermaid-ascii -f sequence.mermaid
βββββββββ βββββββ βββββββββββ
β Alice β β Bob β β Charlie β
βββββ¬ββββ ββββ¬βββ ββββββ¬βββββ
β β β
β Hello! β β
βββββββββββββΊβ β
β β β
β β Forward message
β βββββββββββββββΊβ
β β β
β Got it! β
βββββββββββββββββββββββββββββ€
β β β
# Self-messages
$ cat sequence.mermaid
sequenceDiagram
Alice->>Alice: Think
Alice->>Bob: Hello
$ mermaid-ascii -f sequence.mermaid
βββββββββ βββββββ
β Alice β β Bob β
βββββ¬ββββ ββββ¬βββ
β β
β Think β
ββββ β
β β β
ββββ β
β β
β Hello β
βββββββββββββΊβ
β β
# Explicit participant declarations with aliases
$ cat sequence.mermaid
sequenceDiagram
participant A as Alice
participant B as Bob
A->>B: Message from Alice
B-->>A: Reply to Alice
$ mermaid-ascii -f sequence.mermaid
βββββββββ βββββββ
β Alice β β Bob β
βββββ¬ββββ ββββ¬βββ
β β
β Message from Alice
βββββββββββββΊβ
β β
β Reply to Alice
ββββββββββββββ€
β β
# ASCII mode for sequence diagrams
$ cat sequence.mermaid | mermaid-ascii --ascii
+-------+ +-----+
| Alice | | Bob |
+---+---+ +--+--+
| |
| Hello Bob! |
+----------->|
| |
| Hi Alice! |
|<...........+
| |
$ mermaid-ascii --help
Generate ASCII diagrams from mermaid code.
Usage:
mermaid-ascii [flags]
mermaid-ascii [command]
Available Commands:
completion Generate the autocompletion script for the specified shell
help Help about any command
web HTTP server for rendering mermaid diagrams.
Flags:
-p, --borderPadding int Padding between text and border (default 1)
-c, --coords Show coordinates
-f, --file string Mermaid file to parse
-h, --help help for mermaid-ascii
-x, --paddingX int Horizontal space between nodes (default 5)
-y, --paddingY int Vertical space between nodes (default 5)
-v, --verbose Verbose output
Use "mermaid-ascii [command] --help" for more information about a command.
# And some ridiculous example
$ mermaid-ascii -f complex.mermaid
βββββ βββββ βββββ βββββ βββββ βββββ
β β β β β β β β β β β β
β A ββββββΊβ B ββββ¬ββΊβ E ββββ¬ββΊβ M ββββ¬ββΊβ U ββββ¬ββΊβ W β
β β β β β β β β β β β β β β β β
βββ¬ββ βββ¬ββ β βββ¬ββ β βββ¬ββ β βββ¬ββ β βββ¬ββ
β β β β β β β β² β β
β β β β β β β β β β
β ββββββ ββββββ β ββββββ ββββββΌβββββ
β β β β β β β
β β β β βΌ βΌ β
β β βββββ β βββββ β βββ΄ββ βββββ β βββββ
β β β β β β β β β β β β β β β
ββββββΌββΊβ C ββββΌββΊβ F β βββΊβ Q ββββββΊβ Y ββββΌββΊβ V β
β β β β β β β β β β β β β β β
β β βββ¬ββ β βββ¬ββ β βββββ βββββ β βββ¬ββ
β β β β β β β β²
β β β β β β β β
β ββββββΌβββββ€ ββββββ€ β β
β β β β β β
β βΌ β β β β
β βββ΄ββ β βββββ β βββββ βββββ β β
β β β β β β β β β β β β β
ββββββββΊβ D β βββΊβ G β βββΊβ L ββββ¬ββΊβ T ββββΌβββββ€
β β β β β β β β β β β β β
βββ¬ββ β βββ¬ββ β βββ¬ββ β βββ¬ββ β β
β β β β β β β² β β
β β β β β β β β β
β β ββββββΌβββββ β ββββββ€ β
β β β β β β β β
β β βΌ β β βΌ β β
β β βββ΄ββ β βββββ β βββββ β β
β β β β β β β β β β β β
β βββΊβ H β βββΊβ J β βββΊβ X ββββΌβββββ€
β β β β β β β β β β β β
β β βββ¬ββ β βββ¬ββ β βββββ β β
β β β β β β β β
β β β β β β β β
β ββββββΌβββββ€ ββββββ€ ββββββ€ β
β β β β β β β
β βΌ β β β β β
β βββ΄ββ β βββββ β βββ΄ββ β β
β β β β β β β β β β β
ββββββββΊβ I β βββΊβ K β βββΊβ R ββββΌβββββ
β β β β β β β β β
βββββ β βββ¬ββ β βββββ β
β β β β
β β β β
β ββββββΌβββββ¬βββββ€
β β β β β
β βΌ β β β
β βββ΄ββ β βββ΄ββ β
β β β β β β β
βββΊβ N β βββΊβ O β β
β β β β β β β
β βββββ β βββ¬ββ β
β β β β
β β β β
ββββββ¬βββββ€ ββββββ
β β β β
β βΌ β βΌ
β βββ΄ββ β βββ΄ββ
β β β β β β
βββΊβ P β βββΊβ S β
β β β β
βββββ βββββ
Colored output is also supported (given that your terminal supports it) using the classDef syntax:
graph LR
classDef example1 color:#ff0000
classDef example2 color:#00ff00
classDef example3 color:#0000ff
test1:::example1 --> test2
test2:::example2 --> test3:::example3This results in the following graph:
We parse a mermaid file into basic components in order to render a grid. The grid is used for mapping purposes, which is eventually converted to a drawing. The grid looks a bit like this:
There are three grid-points per node, and one in-between nodes.
These coords don't have to be the same size, as long as they
can be used for pathing purposes where we convert them to drawing
coordinates.
This allows us to navigate edges between nodes, like the arrow in this
drawing taking the path [(2,1), (3,1), (3,5), (4,5)].
0 1 2 3 4 5 6
| | | | | | |
v v v v v v v
0-> +-------------+ +-------------+
| | | |
1-> | Some text |--- | Some text |
| | | | |
2-> +-------------+ | +-------------+
|
3-> |
|
4-> +-------------+ | +-------------+
| | | | |
5-> | Some text | -->| Some text |
| | | |
6-> +-------------+ +-------------+
You can show these coords in your graph by enabling the --coords flag:
$ mermaid-ascii -f ./test.mermaid --coords
01 23 45 67 89 0
0123456789012345678901234567
0 0+---+ +---+ +--------+
1| | | | | |
1 2| A |-123>| B |-->| D |
3| | | | | |
2 4+---+ +---+ +--------+
5 | | |
3 6 | 2 |
7 | v 123456
4 8 | +---+ |
9 | | | |
510 ------->| C |<--------
11 | |
612 +---+Note that with --coords enabled, the grid-coords shown show the starting location of the coord, not the center of the coord. This is why (1,0) is next to (0,0) instead of in the center of the A node.
- Graph directions (
graph LRandgraph TD) - Labelled edges (like
A -->|label| B) - Multiple arrows on one line (like
A --> B --> C) -
A & Bsyntax -
classDefandclassfor colored output - Prevent arrows overlapping nodes
-
subgraphsupport - Shapes other than rectangles
- Diagonal arrows
- Basic message syntax (
A->>B: message) - Solid arrows (
->>) and dotted arrows (-->>) - Self-messages (
A->>A: think) - Participant declarations (
participant Alice) - Participant aliases (
participant A as Alice) - Unicode support (emojis, CJK characters, etc.)
- Both ASCII and Unicode rendering modes
- Activation boxes
- Notes (
Note left of Alice: text) - Loops, alt, opt blocks
The baseline components for Mermaid work, but there are a lot of things that are not supported yet. Here's a list of things that are not yet supported:
- Labelled edges (like
A -->|label| B) - Graph directions like
graph LRandgraph TD -
classDefandclass -
A & B - Multiple arrows on one line (like
A --> B --> C) -
subgraph - Shapes other than rectangles
- Whitespacing and comments
- Prevent arrows overlapping nodes
- Diagonal arrows
- Place nodes in a more compact way
- Prevent rendering more than X characters wide (like default 80 for terminal width)
- Activation boxes (activate/deactivate)
- Notes (
Note left of Alice: text) - Loops, alt, opt, and par blocks
- Support for more diagram types (class diagrams, state diagrams, etc.)
