Debian Codegraph @

docs/content/en/content-management/diagrams.md

raw
1 ---
2 title: Diagrams
3 description: Use fenced code blocks and Markdown render hooks to include diagrams in your content.
4 categories: []
5 keywords: []
6 ---
7
8 ## GoAT diagrams (ASCII)
9
10 Hugo natively supports [GoAT][] diagrams with an [embedded code block render hook][]. This means that this code block:
11
12 ````txt
13 ```goat
14 . . . .--- 1 .-- 1 / 1
15 / \ | | .---+ .-+ +
16 / \ .---+---. .--+--. | '--- 2 | '-- 2 / \ 2
17 + + | | | | ---+ ---+ +
18 / \ / \ .-+-. .-+-. .+. .+. | .--- 3 | .-- 3 \ / 3
19 / \ / \ | | | | | | | | '---+ '-+ +
20 1 2 3 4 1 2 3 4 1 2 3 4 '--- 4 '-- 4 \ 4
21
22 ```
23 ````
24
25 Will be rendered as:
26
27 ```goat
28
29 . . . .--- 1 .-- 1 / 1
30 / \ | | .---+ .-+ +
31 / \ .---+---. .--+--. | '--- 2 | '-- 2 / \ 2
32 + + | | | | ---+ ---+ +
33 / \ / \ .-+-. .-+-. .+. .+. | .--- 3 | .-- 3 \ / 3
34 / \ / \ | | | | | | | | '---+ '-+ +
35 1 2 3 4 1 2 3 4 1 2 3 4 '--- 4 '-- 4 \ 4
36 ```
37
38 ## Mermaid diagrams
39
40 Hugo does not provide a built-in template for Mermaid diagrams. Create your own using a [code block render hook][]:
41
42 ```go-html-template {file="layouts/_markup/render-codeblock-mermaid.html" copy=true}
43 <pre class="mermaid">
44 {{ .Inner | htmlEscape | safeHTML }}
45 </pre>
46 {{ .Page.Store.Set "hasMermaid" true }}
47 ```
48
49 Then include this snippet at the _bottom_ of your _base_ template, before the closing `body` tag:
50
51 ```go-html-template {file="layouts/baseof.html" copy=true}
52 {{ if .Store.Get "hasMermaid" }}
53 <script type="module">
54 import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs';
55 mermaid.initialize({ startOnLoad: true });
56 </script>
57 {{ end }}
58 ```
59
60 With that you can use the `mermaid` language in Markdown code blocks:
61
62 ````md {file="content/example.md" copy=true}
63 ```mermaid
64 sequenceDiagram
65 participant Alice
66 participant Bob
67 Alice->>John: Hello John, how are you?
68 loop Healthcheck
69 John->>John: Fight against hypochondria
70 end
71 Note right of John: Rational thoughts <br/>prevail!
72 John-->>Alice: Great!
73 John->>Bob: How about you?
74 Bob-->>John: Jolly good!
75 ```
76 ````
77
78 ## Goat ASCII diagram examples
79
80 ### Graphics
81
82 ```goat
83 .
84 0 3 P * Eye / ^ /
85 *-------* +y \ +) \ / Reflection
86 1 /| 2 /| ^ \ \ \ v
87 *-------* | | v0 \ v3 --------*--------
88 | |4 | |7 | *----\-----*
89 | *-----|-* +-----> +x / v X \ .-.<-------- o
90 |/ |/ / / o \ | / | Refraction / \
91 *-------* v / \ +-' / \
92 5 6 +z v1 *------------------* v2 | o-----o
93 v
94
95 ```
96
97 ### Complex
98
99 ```goat
100 +-------------------+ ^ .---.
101 | A Box |__.--.__ __.--> | .-. | |
102 | | '--' v | * |<--- | |
103 +-------------------+ '-' | |
104 Round *---(-. |
105 .-----------------. .-------. .----------. .-------. | | |
106 | Mixed Rounded | | | / Diagonals \ | | | | | |
107 | & Square Corners | '--. .--' / \ |---+---| '-)-' .--------.
108 '--+------------+-' .--. | '-------+--------' | | | | / Search /
109 | | | | '---. | '-------' | '-+------'
110 |<---------->| | | | v Interior | ^
111 ' <---' '----' .-----------. ---. .--- v |
112 .------------------. Diag line | .-------. +---. \ / . |
113 | if (a > b) +---. .--->| | | | | Curved line \ / / \ |
114 | obj->fcn() | \ / | '-------' |<--' + / \ |
115 '------------------' '--' '--+--------' .--. .--. | .-. +Done?+-'
116 .---+-----. | ^ |\ | | /| .--+ | | \ /
117 | | | Join \|/ | | Curved | \| |/ | | \ | \ /
118 | | +----> o --o-- '-' Vertical '--' '--' '-- '--' + .---.
119 <--+---+-----' | /|\ | | 3 |
120 v not:line 'quotes' .-' '---'
121 .-. .---+--------. / A || B *bold* | ^
122 | | | Not a dot | <---+---<-- A dash--is not a line v |
123 '-' '---------+--' / Nor/is this. ---
124
125 ```
126
127 ### Process
128
129 ```goat
130 .
131 .---------. / \
132 | START | / \ .-+-------+-. ___________
133 '----+----' .-------. A / \ B | |COMPLEX| | / \ .-.
134 | | END |<-----+CHOICE +----->| | | +--->+ PREPARATION +--->| X |
135 v '-------' \ / | |PROCESS| | \___________/ '-'
136 .---------. \ / '-+---+---+-'
137 / INPUT / \ /
138 '-----+---' '
139 | ^
140 v |
141 .-----------. .-----+-----. .-.
142 | PROCESS +---------------->| PROCESS |<------+ X |
143 '-----------' '-----------' '-'
144 ```
145
146 ### File tree
147
148 Created from <https://arthursonzogni.com/Diagon/#Tree>
149
150 ```goat {width=300 color="orange"}
151 ───Linux─┬─Android
152 ├─Debian─┬─Ubuntu─┬─Lubuntu
153 │ │ ├─Kubuntu
154 │ │ ├─Xubuntu
155 │ │ └─Xubuntu
156 │ └─Mint
157 ├─Centos
158 └─Fedora
159 ```
160
161 ### Sequence diagram
162
163 <https://arthursonzogni.com/Diagon/#Sequence>
164
165 ```goat {class="w-40"}
166 ┌─────┐ ┌───┐
167 │Alice│ │Bob│
168 └──┬──┘ └─┬─┘
169 │ │
170 │ Hello Bob! │
171 │───────────>│
172 │ │
173 │Hello Alice!│
174 │<───────────│
175 ┌──┴──┐ ┌─┴─┐
176 │Alice│ │Bob│
177 └─────┘ └───┘
178
179 ```
180
181 ### Flowchart
182
183 <https://arthursonzogni.com/Diagon/#Flowchart>
184
185 ```goat
186 _________________
187 ╱ ╲ ┌─────┐
188 ╱ DO YOU UNDERSTAND ╲____________________________________________________│GOOD!│
189 ╲ FLOW CHARTS? ╱yes └──┬──┘
190 ╲_________________╱ │
191 │no │
192 _________▽_________ ______________________ │
193 ╱ ╲ ╱ ╲ ┌────┐ │
194 ╱ OKAY, YOU SEE THE ╲________________╱ ... AND YOU CAN SEE ╲___│GOOD│ │
195 ╲ LINE LABELED 'YES'? ╱yes ╲ THE ONES LABELED 'NO'? ╱yes└──┬─┘ │
196 ╲___________________╱ ╲______________________╱ │ │
197 │no │no │ │
198 ________▽_________ _________▽__________ │ │
199 ╱ ╲ ┌───────────┐ ╱ ╲ │ │
200 ╱ BUT YOU SEE THE ╲___│WAIT, WHAT?│ ╱ BUT YOU JUST ╲___ │ │
201 ╲ ONES LABELED 'NO'? ╱yes└───────────┘ ╲ FOLLOWED THEM TWICE? ╱yes│ │ │
202 ╲__________________╱ ╲____________________╱ │ │ │
203 │no │no │ │ │
204 ┌───▽───┐ │ │ │ │
205 │LISTEN.│ └───────┬───────┘ │ │
206 └───┬───┘ ┌──────▽─────┐ │ │
207 ┌─────▽────┐ │(THAT WASN'T│ │ │
208 │I HATE YOU│ │A QUESTION) │ │ │
209 └──────────┘ └──────┬─────┘ │ │
210 ┌────▽───┐ │ │
211 │SCREW IT│ │ │
212 └────┬───┘ │ │
213 └─────┬─────┘ │
214 │ │
215 └─────┬─────┘
216 ┌───────▽──────┐
217 │LET'S GO DRING│
218 └───────┬──────┘
219 ┌─────────▽─────────┐
220 │HEY, I SHOULD TRY │
221 │INSTALLING FREEBSD!│
222 └───────────────────┘
223
224 ```
225
226 ### Table
227
228 <https://arthursonzogni.com/Diagon/#Table>
229
230 ```goat {class="w-80 dark-blue"}
231 ┌────────────────────────────────────────────────┐
232 │ │
233 ├────────────────────────────────────────────────┤
234 │SYNTAX = { PRODUCTION } . │
235 ├────────────────────────────────────────────────┤
236 │PRODUCTION = IDENTIFIER "=" EXPRESSION "." . │
237 ├────────────────────────────────────────────────┤
238 │EXPRESSION = TERM { "|" TERM } . │
239 ├────────────────────────────────────────────────┤
240 │TERM = FACTOR { FACTOR } . │
241 ├────────────────────────────────────────────────┤
242 │FACTOR = IDENTIFIER │
243 ├────────────────────────────────────────────────┤
244 │ | LITERAL │
245 ├────────────────────────────────────────────────┤
246 │ | "[" EXPRESSION "]" │
247 ├────────────────────────────────────────────────┤
248 │ | "(" EXPRESSION ")" │
249 ├────────────────────────────────────────────────┤
250 │ | "{" EXPRESSION "}" . │
251 ├────────────────────────────────────────────────┤
252 │IDENTIFIER = letter { letter } . │
253 ├────────────────────────────────────────────────┤
254 │LITERAL = """" character { character } """" .│
255 └────────────────────────────────────────────────┘
256 ```
257
258 [GoAT]: https://github.com/bep/goat
259 [code block render hook]: /render-hooks/code-blocks/
260 [embedded code block render hook]: <{{% eturl render-codeblock-goat %}}>