2022-05-08 19:31:17 +02:00
|
|
|
|
---
|
|
|
|
|
weight: 5
|
|
|
|
|
title: "Theme Documentation - mermaid Shortcode"
|
|
|
|
|
date: 2020-03-03T15:29:41+08:00
|
|
|
|
|
lastmod: 2020-03-03T15:29:41+08:00
|
|
|
|
|
draft: false
|
|
|
|
|
author: "Dillon"
|
|
|
|
|
authorLink: "https://dillonzq.com"
|
|
|
|
|
description: "The mermaid shortcode supports diagrams in Hugo with Mermaid library."
|
2022-05-12 21:41:37 +02:00
|
|
|
|
images: []
|
2022-05-08 19:31:17 +02:00
|
|
|
|
resources:
|
|
|
|
|
- name: "featured-image"
|
|
|
|
|
src: "featured-image.png"
|
|
|
|
|
|
|
|
|
|
tags: ["shortcodes"]
|
|
|
|
|
categories: ["documentation"]
|
|
|
|
|
|
|
|
|
|
hiddenFromHomePage: true
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
The `mermaid` shortcode supports diagrams in Hugo with [Mermaid](https://mermaidjs.github.io/) library.
|
|
|
|
|
|
|
|
|
|
<!--more-->
|
|
|
|
|
|
|
|
|
|
**Mermaid** is a library helping you to generate diagram and flowcharts from text, in a similar manner as Markdown.
|
|
|
|
|
|
|
|
|
|
Just insert your mermaid code in the `mermaid` shortcode and that’s it.
|
|
|
|
|
|
2022-05-11 21:30:30 +02:00
|
|
|
|
## Flowchart {#flowchart}
|
2022-05-08 19:31:17 +02:00
|
|
|
|
|
|
|
|
|
Example **flowchart** `mermaid` input:
|
|
|
|
|
|
|
|
|
|
```markdown
|
|
|
|
|
{{</* mermaid */>}}
|
|
|
|
|
graph LR;
|
|
|
|
|
A[Hard edge] -->|Link text| B(Round edge)
|
|
|
|
|
B --> C{Decision}
|
|
|
|
|
C -->|One| D[Result one]
|
|
|
|
|
C -->|Two| E[Result two]
|
|
|
|
|
{{</* /mermaid */>}}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
The rendered output looks like this:
|
|
|
|
|
|
|
|
|
|
{{< mermaid >}}
|
|
|
|
|
graph LR;
|
|
|
|
|
A[Hard edge] -->|Link text| B(Round edge)
|
|
|
|
|
B --> C{Decision}
|
|
|
|
|
C -->|One| D[Result one]
|
|
|
|
|
C -->|Two| E[Result two]
|
|
|
|
|
{{< /mermaid >}}
|
|
|
|
|
|
2022-05-11 21:30:30 +02:00
|
|
|
|
## Sequence Diagram {#sequence-diagram}
|
2022-05-08 19:31:17 +02:00
|
|
|
|
|
|
|
|
|
Example **sequence diagram** `mermaid` input:
|
|
|
|
|
|
|
|
|
|
```markdown
|
|
|
|
|
{{</* mermaid */>}}
|
|
|
|
|
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 <br/>prevail...
|
|
|
|
|
John-->Alice: Great!
|
|
|
|
|
John->Bob: How about you?
|
|
|
|
|
Bob-->John: Jolly good!
|
|
|
|
|
{{</* /mermaid */>}}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
The rendered output looks like this:
|
|
|
|
|
|
|
|
|
|
{{< mermaid >}}
|
|
|
|
|
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 <br/>prevail...
|
|
|
|
|
John-->Alice: Great!
|
|
|
|
|
John->Bob: How about you?
|
|
|
|
|
Bob-->John: Jolly good!
|
|
|
|
|
{{< /mermaid >}}
|
|
|
|
|
|
2022-05-11 21:30:30 +02:00
|
|
|
|
## Gantt {#gantt}
|
2022-05-08 19:31:17 +02:00
|
|
|
|
|
2022-05-11 21:30:30 +02:00
|
|
|
|
Example **Gantt** `mermaid` input:
|
2022-05-08 19:31:17 +02:00
|
|
|
|
|
|
|
|
|
```markdown
|
|
|
|
|
{{</* mermaid */>}}
|
|
|
|
|
gantt
|
2022-05-11 21:30:30 +02:00
|
|
|
|
dateFormat YYYY-MM-DD
|
|
|
|
|
title Adding GANTT diagram to mermaid
|
|
|
|
|
excludes weekdays 2014-01-10
|
|
|
|
|
|
|
|
|
|
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
|
2022-05-08 19:31:17 +02:00
|
|
|
|
{{</* /mermaid */>}}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
The rendered output looks like this:
|
|
|
|
|
|
|
|
|
|
{{< mermaid >}}
|
|
|
|
|
gantt
|
2022-05-11 21:30:30 +02:00
|
|
|
|
dateFormat YYYY-MM-DD
|
|
|
|
|
title Adding GANTT diagram to mermaid
|
|
|
|
|
excludes weekdays 2014-01-10
|
|
|
|
|
|
|
|
|
|
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
|
2022-05-08 19:31:17 +02:00
|
|
|
|
{{< /mermaid >}}
|
|
|
|
|
|
2022-05-11 21:30:30 +02:00
|
|
|
|
## Class Diagram {#class-diagram}
|
2022-05-08 19:31:17 +02:00
|
|
|
|
|
|
|
|
|
Example **class diagram** `mermaid` input:
|
|
|
|
|
|
|
|
|
|
```markdown
|
|
|
|
|
{{</* mermaid */>}}
|
|
|
|
|
classDiagram
|
2022-05-11 21:30:30 +02:00
|
|
|
|
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()
|
|
|
|
|
}
|
2022-05-08 19:31:17 +02:00
|
|
|
|
{{</* /mermaid */>}}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
The rendered output looks like this:
|
|
|
|
|
|
|
|
|
|
{{< mermaid >}}
|
|
|
|
|
classDiagram
|
2022-05-11 21:30:30 +02:00
|
|
|
|
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()
|
|
|
|
|
}
|
2022-05-08 19:31:17 +02:00
|
|
|
|
{{< /mermaid >}}
|
|
|
|
|
|
2022-05-11 21:30:30 +02:00
|
|
|
|
## State Diagram {#state-diagram}
|
2022-05-08 19:31:17 +02:00
|
|
|
|
|
|
|
|
|
Example **state diagram** `mermaid` input:
|
|
|
|
|
|
|
|
|
|
```markdown
|
|
|
|
|
{{</* mermaid */>}}
|
2022-05-11 21:30:30 +02:00
|
|
|
|
stateDiagram-v2
|
2022-05-08 19:31:17 +02:00
|
|
|
|
[*] --> Still
|
|
|
|
|
Still --> [*]
|
|
|
|
|
Still --> Moving
|
|
|
|
|
Moving --> Still
|
|
|
|
|
Moving --> Crash
|
|
|
|
|
Crash --> [*]
|
|
|
|
|
{{</* /mermaid */>}}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
The rendered output looks like this:
|
|
|
|
|
|
|
|
|
|
{{< mermaid >}}
|
2022-05-11 21:30:30 +02:00
|
|
|
|
stateDiagram-v2
|
2022-05-08 19:31:17 +02:00
|
|
|
|
[*] --> Still
|
|
|
|
|
Still --> [*]
|
|
|
|
|
Still --> Moving
|
|
|
|
|
Moving --> Still
|
|
|
|
|
Moving --> Crash
|
|
|
|
|
Crash --> [*]
|
|
|
|
|
{{< /mermaid >}}
|
|
|
|
|
|
2022-05-11 21:30:30 +02:00
|
|
|
|
## Git Graph {#git-graph}
|
2022-05-08 19:31:17 +02:00
|
|
|
|
|
|
|
|
|
Example **git graph** `mermaid` input:
|
|
|
|
|
|
|
|
|
|
```markdown
|
|
|
|
|
{{</* mermaid */>}}
|
|
|
|
|
gitGraph
|
|
|
|
|
commit
|
|
|
|
|
commit
|
|
|
|
|
branch develop
|
|
|
|
|
checkout develop
|
|
|
|
|
commit
|
|
|
|
|
commit
|
|
|
|
|
checkout main
|
|
|
|
|
merge develop
|
|
|
|
|
commit
|
|
|
|
|
commit
|
|
|
|
|
{{</* /mermaid */>}}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
The rendered output looks like this:
|
|
|
|
|
|
|
|
|
|
{{< mermaid >}}
|
|
|
|
|
gitGraph
|
|
|
|
|
commit
|
|
|
|
|
commit
|
|
|
|
|
branch develop
|
|
|
|
|
checkout develop
|
|
|
|
|
commit
|
|
|
|
|
commit
|
|
|
|
|
checkout main
|
|
|
|
|
merge develop
|
|
|
|
|
commit
|
|
|
|
|
commit
|
|
|
|
|
{{< /mermaid >}}
|
|
|
|
|
|
2022-05-11 21:30:30 +02:00
|
|
|
|
## Entity Relationship Diagram {#entity-relationship-diagram}
|
2022-05-08 19:31:17 +02:00
|
|
|
|
|
2022-05-11 21:30:30 +02:00
|
|
|
|
Example **entity-relationship diagram** `mermaid` input:
|
|
|
|
|
|
|
|
|
|
```markdown
|
|
|
|
|
{{</* mermaid */>}}
|
|
|
|
|
erDiagram
|
|
|
|
|
CUSTOMER ||--o{ ORDER : places
|
|
|
|
|
ORDER ||--|{ LINE-ITEM : contains
|
|
|
|
|
CUSTOMER }|..|{ DELIVERY-ADDRESS : uses
|
|
|
|
|
{{</* /mermaid */>}}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
The rendered output looks like this:
|
|
|
|
|
|
|
|
|
|
{{< mermaid >}}
|
|
|
|
|
erDiagram
|
|
|
|
|
CUSTOMER ||--o{ ORDER : places
|
|
|
|
|
ORDER ||--|{ LINE-ITEM : contains
|
|
|
|
|
CUSTOMER }|..|{ DELIVERY-ADDRESS : uses
|
|
|
|
|
{{< /mermaid >}}
|
|
|
|
|
|
|
|
|
|
## User Journey {#user-journey}
|
|
|
|
|
|
|
|
|
|
Example **user journey** `mermaid` input:
|
|
|
|
|
|
|
|
|
|
```markdown
|
|
|
|
|
{{</* mermaid */>}}
|
|
|
|
|
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
|
|
|
|
|
{{</* /mermaid */>}}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
The rendered output looks like this:
|
|
|
|
|
|
|
|
|
|
{{< mermaid >}}
|
|
|
|
|
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
|
|
|
|
|
{{< /mermaid >}}
|
|
|
|
|
|
|
|
|
|
## Pie Chart {#pie-chart}
|
|
|
|
|
|
|
|
|
|
Example **pie chart** `mermaid` input:
|
2022-05-08 19:31:17 +02:00
|
|
|
|
|
|
|
|
|
```markdown
|
|
|
|
|
{{</* mermaid */>}}
|
|
|
|
|
pie
|
|
|
|
|
"Dogs" : 386
|
|
|
|
|
"Cats" : 85
|
|
|
|
|
"Rats" : 15
|
|
|
|
|
{{</* /mermaid */>}}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
The rendered output looks like this:
|
|
|
|
|
|
|
|
|
|
{{< mermaid >}}
|
|
|
|
|
pie
|
|
|
|
|
"Dogs" : 386
|
|
|
|
|
"Cats" : 85
|
|
|
|
|
"Rats" : 15
|
|
|
|
|
{{< /mermaid >}}
|
2022-05-11 21:30:30 +02:00
|
|
|
|
|
|
|
|
|
## Requirement Diagram {#requirement-diagram}
|
|
|
|
|
|
|
|
|
|
Example **requirement diagram** `mermaid` input:
|
|
|
|
|
|
|
|
|
|
```markdown
|
|
|
|
|
{{</* mermaid */>}}
|
|
|
|
|
requirementDiagram
|
|
|
|
|
|
|
|
|
|
requirement test_req {
|
|
|
|
|
id: 1
|
|
|
|
|
text: the test text.
|
|
|
|
|
risk: high
|
|
|
|
|
verifymethod: test
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
element test_entity {
|
|
|
|
|
type: simulation
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
test_entity - satisfies -> test_req
|
|
|
|
|
{{</* /mermaid */>}}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
The rendered output looks like this:
|
|
|
|
|
|
|
|
|
|
{{< mermaid >}}
|
|
|
|
|
requirementDiagram
|
|
|
|
|
|
|
|
|
|
requirement test_req {
|
|
|
|
|
id: 1
|
|
|
|
|
text: the test text.
|
|
|
|
|
risk: high
|
|
|
|
|
verifymethod: test
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
element test_entity {
|
|
|
|
|
type: simulation
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
test_entity - satisfies -> test_req
|
|
|
|
|
{{< /mermaid >}}
|