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 The following examples demonstrate the range of diagrams you can create with GoAT.
81
82 ### Graphics
83
84 ```goat
85 .
86 0 3 P * Eye / ^ /
87 *-------* +y \ +) \ / Reflection
88 1 /| 2 /| ^ \ \ \ v
89 *-------* | | v0 \ v3 --------*--------
90 | |4 | |7 | *----\-----*
91 | *-----|-* +-----> +x / v X \ .-.<-------- o
92 |/ |/ / / o \ | / | Refraction / \
93 *-------* v / \ +-' / \
94 5 6 +z v1 *------------------* v2 | o-----o
95 v
96
97 ```
98
99 ### Complex
100
101 ```goat
102 +-------------------+ ^ .---.
103 | A Box |__.--.__ __.--> | .-. | |
104 | | '--' v | * |<--- | |
105 +-------------------+ '-' | |
106 Round *---(-. |
107 .-----------------. .-------. .----------. .-------. | | |
108 | Mixed Rounded | | | / Diagonals \ | | | | | |
109 | & Square Corners | '--. .--' / \ |---+---| '-)-' .--------.
110 '--+------------+-' .--. | '-------+--------' | | | | / Search /
111 | | | | '---. | '-------' | '-+------'
112 |<---------->| | | | v Interior | ^
113 ' <---' '----' .-----------. ---. .--- v |
114 .------------------. Diag line | .-------. +---. \ / . |
115 | if (a > b) +---. .--->| | | | | Curved line \ / / \ |
116 | obj->fcn() | \ / | '-------' |<--' + / \ |
117 '------------------' '--' '--+--------' .--. .--. | .-. +Done?+-'
118 .---+-----. | ^ |\ | | /| .--+ | | \ /
119 | | | Join \|/ | | Curved | \| |/ | | \ | \ /
120 | | +----> o --o-- '-' Vertical '--' '--' '-- '--' + .---.
121 <--+---+-----' | /|\ | | 3 |
122 v not:line 'quotes' .-' '---'
123 .-. .---+--------. / A || B *bold* | ^
124 | | | Not a dot | <---+---<-- A dash--is not a line v |
125 '-' '---------+--' / Nor/is this. ---
126
127 ```
128
129 ### Process
130
131 ```goat
132 .
133 .---------. / \
134 | START | / \ .-+-------+-. ___________
135 '----+----' .-------. A / \ B | |COMPLEX| | / \ .-.
136 | | END |<-----+CHOICE +----->| | | +--->+ PREPARATION +--->| X |
137 v '-------' \ / | |PROCESS| | \___________/ '-'
138 .---------. \ / '-+---+---+-'
139 / INPUT / \ /
140 '-----+---' '
141 | ^
142 v |
143 .-----------. .-----+-----. .-.
144 | PROCESS +---------------->| PROCESS |<------+ X |
145 '-----------' '-----------' '-'
146 ```
147
148 ### File tree
149
150 Created from <https://arthursonzogni.com/Diagon/#Tree>
151
152 ```goat {width=300 color="orange"}
153 ───Linux─┬─Android
154 ├─Debian─┬─Ubuntu─┬─Lubuntu
155 │ │ ├─Kubuntu
156 │ │ ├─Xubuntu
157 │ │ └─Xubuntu
158 │ └─Mint
159 ├─Centos
160 └─Fedora
161 ```
162
163 ### Sequence diagram
164
165 <https://arthursonzogni.com/Diagon/#Sequence>
166
167 ```goat {class="w-40"}
168 ┌─────┐ ┌───┐
169 │Alice│ │Bob│
170 └──┬──┘ └─┬─┘
171 │ │
172 │ Hello Bob! │
173 │───────────>│
174 │ │
175 │Hello Alice!│
176 │<───────────│
177 ┌──┴──┐ ┌─┴─┐
178 │Alice│ │Bob│
179 └─────┘ └───┘
180
181 ```
182
183 ### Flowchart
184
185 <https://arthursonzogni.com/Diagon/#Flowchart>
186
187 ```goat
188 _________________
189 ╱ ╲ ┌─────┐
190 ╱ DO YOU UNDERSTAND ╲____________________________________________________│GOOD!│
191 ╲ FLOW CHARTS? ╱yes └──┬──┘
192 ╲_________________╱ │
193 │no │
194 _________▽_________ ______________________ │
195 ╱ ╲ ╱ ╲ ┌────┐ │
196 ╱ OKAY, YOU SEE THE ╲________________╱ ... AND YOU CAN SEE ╲___│GOOD│ │
197 ╲ LINE LABELED 'YES'? ╱yes ╲ THE ONES LABELED 'NO'? ╱yes└──┬─┘ │
198 ╲___________________╱ ╲______________________╱ │ │
199 │no │no │ │
200 ________▽_________ _________▽__________ │ │
201 ╱ ╲ ┌───────────┐ ╱ ╲ │ │
202 ╱ BUT YOU SEE THE ╲___│WAIT, WHAT?│ ╱ BUT YOU JUST ╲___ │ │
203 ╲ ONES LABELED 'NO'? ╱yes└───────────┘ ╲ FOLLOWED THEM TWICE? ╱yes│ │ │
204 ╲__________________╱ ╲____________________╱ │ │ │
205 │no │no │ │ │
206 ┌───▽───┐ │ │ │ │
207 │LISTEN.│ └───────┬───────┘ │ │
208 └───┬───┘ ┌──────▽─────┐ │ │
209 ┌─────▽────┐ │(THAT WASN'T│ │ │
210 │I HATE YOU│ │A QUESTION) │ │ │
211 └──────────┘ └──────┬─────┘ │ │
212 ┌────▽───┐ │ │
213 │SCREW IT│ │ │
214 └────┬───┘ │ │
215 └─────┬─────┘ │
216 │ │
217 └─────┬─────┘
218 ┌───────▽──────┐
219 │LET'S GO DRING│
220 └───────┬──────┘
221 ┌─────────▽─────────┐
222 │HEY, I SHOULD TRY │
223 │INSTALLING FREEBSD!│
224 └───────────────────┘
225
226 ```
227
228 ### Table
229
230 <https://arthursonzogni.com/Diagon/#Table>
231
232 ```goat {class="w-80 dark-blue"}
233 ┌────────────────────────────────────────────────┐
234 │ │
235 ├────────────────────────────────────────────────┤
236 │SYNTAX = { PRODUCTION } . │
237 ├────────────────────────────────────────────────┤
238 │PRODUCTION = IDENTIFIER "=" EXPRESSION "." . │
239 ├────────────────────────────────────────────────┤
240 │EXPRESSION = TERM { "|" TERM } . │
241 ├────────────────────────────────────────────────┤
242 │TERM = FACTOR { FACTOR } . │
243 ├────────────────────────────────────────────────┤
244 │FACTOR = IDENTIFIER │
245 ├────────────────────────────────────────────────┤
246 │ | LITERAL │
247 ├────────────────────────────────────────────────┤
248 │ | "[" EXPRESSION "]" │
249 ├────────────────────────────────────────────────┤
250 │ | "(" EXPRESSION ")" │
251 ├────────────────────────────────────────────────┤
252 │ | "{" EXPRESSION "}" . │
253 ├────────────────────────────────────────────────┤
254 │IDENTIFIER = letter { letter } . │
255 ├────────────────────────────────────────────────┤
256 │LITERAL = """" character { character } """" .│
257 └────────────────────────────────────────────────┘
258 ```
259
260 [GoAT]: https://github.com/bep/goat
261 [code block render hook]: /render-hooks/code-blocks/
262 [embedded code block render hook]: <{{% eturl render-codeblock-goat %}}>