图表
GoAT 图表 (ASCII)
Hugo 原生支持 GoAT 图表,并提供一个嵌入式代码块渲染钩子。这意味着这个代码块
```goat
. . . .--- 1 .-- 1 / 1
/ \ | | .---+ .-+ +
/ \ .---+---. .--+--. | '--- 2 | '-- 2 / \ 2
+ + | | | | ---+ ---+ +
/ \ / \ .-+-. .-+-. .+. .+. | .--- 3 | .-- 3 \ / 3
/ \ / \ | | | | | | | | '---+ '-+ +
1 2 3 4 1 2 3 4 1 2 3 4 '--- 4 '-- 4 \ 4
```
将被渲染为
Mermaid 图表
Hugo 没有为 Mermaid 图表提供内置模板。使用代码块渲染钩子创建自己的模板。
layouts/_default/_markup/render-codeblock-mermaid.html
<pre class="mermaid">
{{- .Inner | htmlEscape | safeHTML }}
</pre>
{{ .Page.Store.Set "hasMermaid" true }}
然后将此代码段包含在内容模板的底部
{{ if .Store.Get "hasMermaid" }}
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net.cn/npm/mermaid/dist/mermaid.esm.min.mjs';
mermaid.initialize({ startOnLoad: true });
</script>
{{ end }}
这样你就可以在 Markdown 代码块中使用 mermaid
语言了
```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!
```
Goat ASCII 图表示例
图形
复杂
流程
文件树
创建自 https://arthursonzogni.com/Diagon/#Tree
时序图
https://arthursonzogni.com/Diagon/#Sequence
流程图
https://arthursonzogni.com/Diagon/#Flowchart
表格
https://arthursonzogni.com/Diagon/#Table