Mermaid
Mermaid is library that helps you generate diagrams, flowcharts, and piecharts from text in a similar manner as markdown.
With compose theme, you can use mermaid using a custom shortcode as follows:
Sequence Diagrams
Snippet
1{{< mermaid >}}
2sequenceDiagram
3 participant Alice
4 participant Bob
5 Alice->>John: Hello John, how are you?
6 loop Healthcheck
7 John->>John: Fight against hypochondria
8 end
9 Note right of John: Rational thoughts<br/>prevail...
10 John-->>Alice: Great!
11 John->>Bob: How about you?
12 Bob-->>John: Jolly good!
13{{< /mermaid >}}
Result
sequenceDiagram
participant Alice
participant Bob
Alice->>John: Hello John, how are you?
loop Healthcheck
John->>John: Fight against hypochondria
end
Note right of John: Rational thoughts
prevail... John-->>Alice: Great! John->>Bob: How about you? Bob-->>John: Jolly good!
prevail... John-->>Alice: Great! John->>Bob: How about you? Bob-->>John: Jolly good!
Flow Charts
Snippet
1{{< mermaid >}}
2flowchart TB
3 c1-->a2
4 subgraph one
5 a1-->a2
6 end
7 subgraph two
8 b1-->b2
9 end
10 subgraph three
11 c1-->c2
12 end
13 one --> two
14 three --> two
15 two --> c2
16{{< /mermaid >}}
Result
flowchart TB
c1-->a2
subgraph one
a1-->a2
end
subgraph two
b1-->b2
end
subgraph three
c1-->c2
end
one --> two
three --> two
two --> c2
Graphs
Snippet
1{{< mermaid >}}
2graph TB
3 sq[Square shape] --> ci((Circle shape))
4
5 subgraph A
6 od>Odd shape]-- Two line<br/>edge comment --> ro
7 di{Diamond with <br/> line break} -.-> ro(Rounded<br>square<br>shape)
8 di==>ro2(Rounded square shape)
9 end
10
11 %% Notice that no text in shape are added here instead that is appended further down
12 e --> od3>Really long text with linebreak<br>in an Odd shape]
13
14 %% Comments after double percent signs
15 e((Inner / circle<br>and some odd <br>special characters)) --> f(,.?!+-*ز)
16
17 cyr[Cyrillic]-->cyr2((Circle shape Начало));
18
19 classDef green fill:#9f6,stroke:#333,stroke-width:2px;
20 classDef orange fill:#f96,stroke:#333,stroke-width:4px;
21 class sq,e green
22 class di orange
23{{< /mermaid >}}
Result
graph TB
sq[Square shape] --> ci((Circle shape))
subgraph A
od>Odd shape]-- Two line
edge comment --> ro di{Diamond with
line break} -.-> ro(Rounded
square
shape) di==>ro2(Rounded square shape) end %% Notice that no text in shape are added here instead that is appended further down e --> od3>Really long text with linebreak
in an Odd shape] %% Comments after double percent signs e((Inner / circle
and some odd
special characters)) --> f(,.?!+-*ز) cyr[Cyrillic]-->cyr2((Circle shape Начало)); classDef green fill:#9f6,stroke:#333,stroke-width:2px; classDef orange fill:#f96,stroke:#333,stroke-width:4px; class sq,e green class di orange
edge comment --> ro di{Diamond with
line break} -.-> ro(Rounded
square
shape) di==>ro2(Rounded square shape) end %% Notice that no text in shape are added here instead that is appended further down e --> od3>Really long text with linebreak
in an Odd shape] %% Comments after double percent signs e((Inner / circle
and some odd
special characters)) --> f(,.?!+-*ز) cyr[Cyrillic]-->cyr2((Circle shape Начало)); classDef green fill:#9f6,stroke:#333,stroke-width:2px; classDef orange fill:#f96,stroke:#333,stroke-width:4px; class sq,e green class di orange
Snippet
1{{< mermaid >}}
2graph LR
3 A[Hard edge] -->|Link text| B(Round edge)
4 B --> C{Decision}
5 C -->|One| D[Result one]
6 C -->|Two| E[Result two]
7{{< /mermaid >}}
Result
graph LR
A[Hard edge] -->|Link text| B(Round edge)
B --> C{Decision}
C -->|One| D[Result one]
C -->|Two| E[Result two]
Class Diagram
classDiagram
Animal <|-- Duck
Animal <|-- Fish
Animal <|-- Zebra
Animal : +int age
Animal : +String gender
Animal: +isMammal()
Animal: +mate()
class Duck{
+String beakColor
+swim()
+quack()
}
class Fish{
-int sizeInFeet
-canEat()
}
class Zebra{
+bool is_wild
+run()
}
State Diagram
stateDiagram-v2
[*] --> Active
state Active {
[*] --> NumLockOff
NumLockOff --> NumLockOn : EvNumLockPressed
NumLockOn --> NumLockOff : EvNumLockPressed
--
[*] --> CapsLockOff
CapsLockOff --> CapsLockOn : EvCapsLockPressed
CapsLockOn --> CapsLockOff : EvCapsLockPressed
--
[*] --> ScrollLockOff
ScrollLockOff --> ScrollLockOn : EvScrollLockPressed
ScrollLockOn --> ScrollLockOff : EvScrollLockPressed
}
stateDiagram-v2
State1: The state with a note
note right of State1
Important information! You can write
notes.
end note
State1 --> State2
note left of State2 : This is the note to the left.
Relationship Diagrams
Snippet
1{{< mermaid >}}
2erDiagram
3 CUSTOMER ||--o{ ORDER : places
4 ORDER ||--|{ LINE-ITEM : contains
5 CUSTOMER }|..|{ DELIVERY-ADDRESS : uses
6{{< /mermaid >}}
Result
erDiagram
CUSTOMER ||--o{ ORDER : places
ORDER ||--|{ LINE-ITEM : contains
CUSTOMER }|..|{ DELIVERY-ADDRESS : uses
User Journey
Snippet
1{{< mermaid >}}
2journey
3 title My working day
4 section Go to work
5 Make tea: 5: Me
6 Go upstairs: 3: Me
7 Do work: 1: Me, Cat
8 section Go home
9 Go downstairs: 5: Me
10 Sit down: 5: Me
11{{< /mermaid >}}
Result
journey
title My working day
section Go to work
Make tea: 5: Me
Go upstairs: 3: Me
Do work: 1: Me, Cat
section Go home
Go downstairs: 5: Me
Sit down: 5: Me
Gantt
Snippet
1{{< mermaid >}}
2gantt
3 dateFormat YYYY-MM-DD
4 title Adding GANTT diagram functionality to mermaid
5 excludes weekends
6 %% (`excludes` accepts specific dates in YYYY-MM-DD format, days of the week ("sunday") or "weekends", but not the word "weekdays".)
7
8 section A section
9 Completed task :done, des1, 2014-01-06,2014-01-08
10 Active task :active, des2, 2014-01-09, 3d
11 Future task : des3, after des2, 5d
12 Future task2 : des4, after des3, 5d
13
14 section Critical tasks
15 Completed task in the critical line :crit, done, 2014-01-06,24h
16 Implement parser and jison :crit, done, after des1, 2d
17 Create tests for parser :crit, active, 3d
18 Future task in critical line :crit, 5d
19 Create tests for renderer :2d
20 Add to mermaid :1d
21
22 section Documentation
23 Describe gantt syntax :active, a1, after des1, 3d
24 Add gantt diagram to demo page :after a1 , 20h
25 Add another diagram to demo page :doc1, after a1 , 48h
26
27 section Last section
28 Describe gantt syntax :after doc1, 3d
29 Add gantt diagram to demo page :20h
30 Add another diagram to demo page :48h
31{{< /mermaid >}}
Result
gantt
dateFormat YYYY-MM-DD
title Adding GANTT diagram functionality to mermaid
excludes weekends
%% (`excludes` accepts specific dates in YYYY-MM-DD format, days of the week ("sunday") or "weekends", but not the word "weekdays".)
section A section
Completed task :done, des1, 2014-01-06,2014-01-08
Active task :active, des2, 2014-01-09, 3d
Future task : des3, after des2, 5d
Future task2 : des4, after des3, 5d
section Critical tasks
Completed task in the critical line :crit, done, 2014-01-06,24h
Implement parser and jison :crit, done, after des1, 2d
Create tests for parser :crit, active, 3d
Future task in critical line :crit, 5d
Create tests for renderer :2d
Add to mermaid :1d
section Documentation
Describe gantt syntax :active, a1, after des1, 3d
Add gantt diagram to demo page :after a1 , 20h
Add another diagram to demo page :doc1, after a1 , 48h
section Last section
Describe gantt syntax :after doc1, 3d
Add gantt diagram to demo page :20h
Add another diagram to demo page :48h
Pie Chart
1{{< mermaid >}}
2pie
3 title Key elements in Product X
4 "Calcium" : 42.96
5 "Potassium" : 50.05
6 "Magnesium" : 10.01
7 "Iron" : 5
8{{< /mermaid >}}
Result
pie
title Key elements in Product X
"Calcium" : 42.96
"Potassium" : 50.05
"Magnesium" : 10.01
"Iron" : 5
Mindmap
Snippet
1{{< mermaid >}}
2mindmap
3 root((mindmap))
4 Origins
5 Long history
6 ::icon(fa fa-book)
7 Popularisation
8 British popular psychology author Tony Buzan
9 Research
10 On effectiveness<br/>and features
11 On Automatic creation
12 Uses
13 Creative techniques
14 Strategic planning
15 Argument mapping
16 Tools
17 Pen and paper
18 Mermaid
19
20{{< /mermaid >}}
Result
mindmap
root((mindmap))
Origins
Long history
::icon(fa fa-book)
Popularisation
British popular psychology author Tony Buzan
Research
On effectiveness
and features On Automatic creation Uses Creative techniques Strategic planning Argument mapping Tools Pen and paper Mermaid
and features On Automatic creation Uses Creative techniques Strategic planning Argument mapping Tools Pen and paper Mermaid
Timeline
Snippet I
1{{< mermaid >}}
2timeline
3 title History of Social Media Platform
4 2002 : LinkedIn
5 2004 : Facebook : Google
6 2005 : Youtube
7 2006 : Twitter
8{{< /mermaid >}}
Result I
timeline
title History of Social Media Platform
2002 : LinkedIn
2004 : Facebook : Google
2005 : Youtube
2006 : Twitter
Snippet II
1{{< mermaid >}}
2timeline
3 title MermaidChart 2023 Timeline
4 section 2023 Q1 <br> Release Personal Tier
5 Buttet 1 : sub-point 1a : sub-point 1b
6 : sub-point 1c
7 Bullet 2 : sub-point 2a : sub-point 2b
8 section 2023 Q2 <br> Release XYZ Tier
9 Buttet 3 : sub-point <br> 3a : sub-point 3b
10 : sub-point 3c
11 Bullet 4 : sub-point 4a : sub-point 4b
12
13{{< /mermaid >}}
Result II
timeline
title MermaidChart 2023 Timeline
section 2023 Q1
Release Personal Tier Buttet 1 : sub-point 1a : sub-point 1b : sub-point 1c Bullet 2 : sub-point 2a : sub-point 2b section 2023 Q2
Release XYZ Tier Buttet 3 : sub-point
3a : sub-point 3b : sub-point 3c Bullet 4 : sub-point 4a : sub-point 4b
Release Personal Tier Buttet 1 : sub-point 1a : sub-point 1b : sub-point 1c Bullet 2 : sub-point 2a : sub-point 2b section 2023 Q2
Release XYZ Tier Buttet 3 : sub-point
3a : sub-point 3b : sub-point 3c Bullet 4 : sub-point 4a : sub-point 4b
Gitgraph
Snippet
1{{< mermaid >}}
2---
3title: Example Git diagram
4---
5gitGraph
6 commit
7 commit
8 branch develop
9 checkout develop
10 commit
11 commit
12 checkout main
13 merge develop
14 commit
15 commit
16
17{{< /mermaid >}}
Result
---
title: Example Git diagram
---
gitGraph
commit
commit
branch develop
checkout develop
commit
commit
checkout main
merge develop
commit
commit
Requirement Diagram
Snippet
1{{< mermaid >}}
2 requirementDiagram
3
4 requirement test_req {
5 id: 1
6 text: the test text.
7 risk: high
8 verifymethod: test
9 }
10
11 element test_entity {
12 type: simulation
13 }
14
15 test_entity - satisfies -> test_req
16{{< /mermaid >}}
Result
requirementDiagram
requirement test_req {
id: 1
text: the test text.
risk: high
verifymethod: test
}
element test_entity {
type: simulation
}
test_entity - satisfies -> test_req
C4C Diagram
1{{< mermaid >}}
2 C4Context
3 title System Context diagram for Internet Banking System
4 Enterprise_Boundary(b0, "BankBoundary0") {
5 Person(customerA, "Banking Customer A", "A customer of the bank, with personal bank accounts.")
6 Person(customerB, "Banking Customer B")
7 Person_Ext(customerC, "Banking Customer C", "desc")
8
9 Person(customerD, "Banking Customer D", "A customer of the bank, <br/> with personal bank accounts.")
10
11 System(SystemAA, "Internet Banking System", "Allows customers to view information about their bank accounts, and make payments.")
12
13 Enterprise_Boundary(b1, "BankBoundary") {
14
15 SystemDb_Ext(SystemE, "Mainframe Banking System", "Stores all of the core banking information about customers, accounts, transactions, etc.")
16
17 System_Boundary(b2, "BankBoundary2") {
18 System(SystemA, "Banking System A")
19 System(SystemB, "Banking System B", "A system of the bank, with personal bank accounts. next line.")
20 }
21
22 System_Ext(SystemC, "E-mail system", "The internal Microsoft Exchange e-mail system.")
23 SystemDb(SystemD, "Banking System D Database", "A system of the bank, with personal bank accounts.")
24
25 Boundary(b3, "BankBoundary3", "boundary") {
26 SystemQueue(SystemF, "Banking System F Queue", "A system of the bank.")
27 SystemQueue_Ext(SystemG, "Banking System G Queue", "A system of the bank, with personal bank accounts.")
28 }
29 }
30 }
31
32 BiRel(customerA, SystemAA, "Uses")
33 BiRel(SystemAA, SystemE, "Uses")
34 Rel(SystemAA, SystemC, "Sends e-mails", "SMTP")
35 Rel(SystemC, customerA, "Sends e-mails to")
36
37 UpdateElementStyle(customerA, $fontColor="red", $bgColor="grey", $borderColor="red")
38 UpdateRelStyle(customerA, SystemAA, $textColor="blue", $lineColor="blue", $offsetX="5")
39 UpdateRelStyle(SystemAA, SystemE, $textColor="blue", $lineColor="blue", $offsetY="-10")
40 UpdateRelStyle(SystemAA, SystemC, $textColor="blue", $lineColor="blue", $offsetY="-40", $offsetX="-50")
41 UpdateRelStyle(SystemC, customerA, $textColor="red", $lineColor="red", $offsetX="-50", $offsetY="20")
42
43 UpdateLayoutConfig($c4ShapeInRow="3", $c4BoundaryInRow="1")
44{{< /mermaid >}}
Result
C4Context
title System Context diagram for Internet Banking System
Enterprise_Boundary(b0, "BankBoundary0") {
Person(customerA, "Banking Customer A", "A customer of the bank, with personal bank accounts.")
Person(customerB, "Banking Customer B")
Person_Ext(customerC, "Banking Customer C", "desc")
Person(customerD, "Banking Customer D", "A customer of the bank,
with personal bank accounts.") System(SystemAA, "Internet Banking System", "Allows customers to view information about their bank accounts, and make payments.") Enterprise_Boundary(b1, "BankBoundary") { SystemDb_Ext(SystemE, "Mainframe Banking System", "Stores all of the core banking information about customers, accounts, transactions, etc.") System_Boundary(b2, "BankBoundary2") { System(SystemA, "Banking System A") System(SystemB, "Banking System B", "A system of the bank, with personal bank accounts. next line.") } System_Ext(SystemC, "E-mail system", "The internal Microsoft Exchange e-mail system.") SystemDb(SystemD, "Banking System D Database", "A system of the bank, with personal bank accounts.") Boundary(b3, "BankBoundary3", "boundary") { SystemQueue(SystemF, "Banking System F Queue", "A system of the bank.") SystemQueue_Ext(SystemG, "Banking System G Queue", "A system of the bank, with personal bank accounts.") } } } BiRel(customerA, SystemAA, "Uses") BiRel(SystemAA, SystemE, "Uses") Rel(SystemAA, SystemC, "Sends e-mails", "SMTP") Rel(SystemC, customerA, "Sends e-mails to") UpdateElementStyle(customerA, $fontColor="red", $bgColor="grey", $borderColor="red") UpdateRelStyle(customerA, SystemAA, $textColor="blue", $lineColor="blue", $offsetX="5") UpdateRelStyle(SystemAA, SystemE, $textColor="blue", $lineColor="blue", $offsetY="-10") UpdateRelStyle(SystemAA, SystemC, $textColor="blue", $lineColor="blue", $offsetY="-40", $offsetX="-50") UpdateRelStyle(SystemC, customerA, $textColor="red", $lineColor="red", $offsetX="-50", $offsetY="20") UpdateLayoutConfig($c4ShapeInRow="3", $c4BoundaryInRow="1")
with personal bank accounts.") System(SystemAA, "Internet Banking System", "Allows customers to view information about their bank accounts, and make payments.") Enterprise_Boundary(b1, "BankBoundary") { SystemDb_Ext(SystemE, "Mainframe Banking System", "Stores all of the core banking information about customers, accounts, transactions, etc.") System_Boundary(b2, "BankBoundary2") { System(SystemA, "Banking System A") System(SystemB, "Banking System B", "A system of the bank, with personal bank accounts. next line.") } System_Ext(SystemC, "E-mail system", "The internal Microsoft Exchange e-mail system.") SystemDb(SystemD, "Banking System D Database", "A system of the bank, with personal bank accounts.") Boundary(b3, "BankBoundary3", "boundary") { SystemQueue(SystemF, "Banking System F Queue", "A system of the bank.") SystemQueue_Ext(SystemG, "Banking System G Queue", "A system of the bank, with personal bank accounts.") } } } BiRel(customerA, SystemAA, "Uses") BiRel(SystemAA, SystemE, "Uses") Rel(SystemAA, SystemC, "Sends e-mails", "SMTP") Rel(SystemC, customerA, "Sends e-mails to") UpdateElementStyle(customerA, $fontColor="red", $bgColor="grey", $borderColor="red") UpdateRelStyle(customerA, SystemAA, $textColor="blue", $lineColor="blue", $offsetX="5") UpdateRelStyle(SystemAA, SystemE, $textColor="blue", $lineColor="blue", $offsetY="-10") UpdateRelStyle(SystemAA, SystemC, $textColor="blue", $lineColor="blue", $offsetY="-40", $offsetX="-50") UpdateRelStyle(SystemC, customerA, $textColor="red", $lineColor="red", $offsetX="-50", $offsetY="20") UpdateLayoutConfig($c4ShapeInRow="3", $c4BoundaryInRow="1")