You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/syntax/diagrams.md
+79-20Lines changed: 79 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
-
# Diagram Directive
1
+
# Diagrams
2
2
3
3
The `diagram` directive allows you to render various types of diagrams using the [Kroki](https://kroki.io/) service. Kroki supports many diagram types including Mermaid, D2, Graphviz, PlantUML, and more.
4
4
5
-
## Basic Usage
5
+
## Basic usage
6
6
7
7
The basic syntax for the diagram directive is:
8
8
@@ -14,7 +14,7 @@ The basic syntax for the diagram directive is:
14
14
15
15
If no diagram type is specified, it defaults to `mermaid`.
16
16
17
-
## Supported Diagram Types
17
+
## Supported diagram types
18
18
19
19
The diagram directive supports the following diagram types:
20
20
@@ -35,8 +35,12 @@ The diagram directive supports the following diagram types:
35
35
36
36
## Examples
37
37
38
-
### Mermaid Flowchart (Default)
38
+
### Mermaid flowchart (default)
39
39
40
+
::::::{tab-set}
41
+
42
+
:::::{tab-item} Source
43
+
```markdown
40
44
::::{diagram}
41
45
flowchart LR
42
46
A[Start] --> B{Decision}
@@ -45,35 +49,101 @@ flowchart LR
45
49
C --> E[End]
46
50
D --> E
47
51
::::
52
+
```
53
+
:::::
54
+
55
+
:::::{tab-item} Rendered
56
+
::::{diagram}
57
+
flowchart LR
58
+
A[Start] --> B{Decision}
59
+
B -->|Yes| C[Action 1]
60
+
B -->|No| D[Action 2]
61
+
C --> E[End]
62
+
D --> E
63
+
::::
64
+
:::::
65
+
66
+
::::::
48
67
49
-
### Mermaid Sequence Diagram
68
+
### Mermaid sequence diagram
50
69
70
+
::::::{tab-set}
71
+
72
+
:::::{tab-item} Source
73
+
```markdown
74
+
::::{diagram} mermaid
75
+
sequenceDiagram
76
+
participant A as Alice
77
+
participant B as Bob
78
+
A->>B: Hello Bob, how are you?
79
+
B-->>A: Great!
80
+
::::
81
+
```
82
+
:::::
83
+
84
+
:::::{tab-item} Rendered
51
85
::::{diagram} mermaid
52
86
sequenceDiagram
53
87
participant A as Alice
54
88
participant B as Bob
55
89
A->>B: Hello Bob, how are you?
56
90
B-->>A: Great!
57
91
::::
92
+
:::::
93
+
94
+
::::::
58
95
59
-
### D2 Diagram
96
+
### D2 diagram
60
97
98
+
::::::{tab-set}
99
+
100
+
:::::{tab-item} Source
101
+
```markdown
61
102
::::{diagram} d2
62
103
x -> y: hello world
63
104
y -> z: nice to meet you
64
105
::::
106
+
```
107
+
:::::
65
108
66
-
### Graphviz Diagram
109
+
:::::{tab-item} Rendered
110
+
::::{diagram} d2
111
+
x -> y: hello world
112
+
y -> z: nice to meet you
113
+
::::
114
+
:::::
67
115
116
+
::::::
117
+
118
+
### Graphviz diagram
119
+
120
+
::::::{tab-set}
121
+
122
+
:::::{tab-item} Source
123
+
```markdown
68
124
::::{diagram} graphviz
69
125
digraph G {
70
126
rankdir=LR;
71
127
A -> B -> C;
72
128
A -> C;
73
129
}
74
130
::::
131
+
```
132
+
:::::
75
133
76
-
## How It Works
134
+
:::::{tab-item} Rendered
135
+
::::{diagram} graphviz
136
+
digraph G {
137
+
rankdir=LR;
138
+
A -> B -> C;
139
+
A -> C;
140
+
}
141
+
::::
142
+
:::::
143
+
144
+
::::::
145
+
146
+
## How it works
77
147
78
148
The diagram directive:
79
149
@@ -83,17 +153,6 @@ The diagram directive:
83
153
4.**Generates** a Kroki URL in the format: `https://kroki.io/{type}/svg/{encoded-content}`
84
154
5.**Renders** an HTML `<img>` tag that loads the diagram from Kroki
85
155
86
-
## Error Handling
156
+
## Error handling
87
157
88
158
If the diagram content is empty or the encoding fails, an error message will be displayed instead of the diagram.
89
-
90
-
## Implementation Details
91
-
92
-
The diagram directive is implemented using:
93
-
94
-
-**DiagramBlock**: Parses the directive and extracts content
95
-
-**DiagramEncoder**: Handles compression and encoding using the same algorithm as the Kroki documentation
96
-
-**DiagramView**: Renders the final HTML with the Kroki URL
97
-
-**Kroki Service**: External service that generates SVG diagrams from encoded content
98
-
99
-
The encoding follows the Kroki specification exactly, ensuring compatibility with all supported diagram types.
0 commit comments