add: mermaid support

This commit is contained in:
Junyi Hou 2024-04-09 15:20:53 +08:00
parent 775f4e9de0
commit ce5f1811c4
4 changed files with 122 additions and 2 deletions

View File

@ -167,8 +167,8 @@ th, td {
pre { pre {
max-width: 100%; max-width: 100%;
overflow: auto; overflow: auto;
margin-top: 0; /* margin-top: 0; */
margin-bottom: 0; /* margin-bottom: 0; */
} }
code, code,

View File

@ -0,0 +1,105 @@
+++
author = "Hugo Authors"
title = "Advanced Diagram Usage"
date = "2024-04-09"
description = "Guide to advanced usage of Anubis2"
tags = [
"emoji",
]
+++
## 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 Diagrams
Get more examples at [here](https://mermaid.js.org/intro/)
```mermaid
gitGraph:
commit "Ashish"
branch newbranch
checkout newbranch
commit id:"1111"
commit tag:"test"
checkout main
commit type: HIGHLIGHT
commit
merge newbranch
commit
branch b2
commit
```
```mermaid
gantt
title A Gantt Diagram
dateFormat YYYY-MM-DD
section Section
A task :a1, 2014-01-01, 30d
Another task :after a1, 20d
section Another
Task in Another :2014-01-12, 12d
another task :24d
```
```mermaid
stateDiagram
[*] --> Still
Still --> [*]
Still --> Moving
Moving --> Still
Moving --> Crash
Crash --> [*]
```
```mermaid
sankey-beta
Pumped heat,"Heating and cooling, ""homes""",193.026
Pumped heat,"Heating and cooling, ""commercial""",70.672
```
```mermaid
sequenceDiagram
loop Daily query
Alice->>Bob: Hello Bob, how are you?
alt is sick
Bob->>Alice: Not so good :(
else is well
Bob->>Alice: Feeling fresh like a daisy
end
opt Extra response
Bob->>Alice: Thanks for asking
end
end
```
```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!
```

View File

@ -0,0 +1,4 @@
<pre class="mermaid">
{{- .Inner | safeHTML }}
</pre>
{{ .Page.Store.Set "hasMermaid" true }}

View File

@ -41,4 +41,15 @@
{{ if not .Params.disableComments }} {{ if not .Params.disableComments }}
{{ partial "comments.html" . }} {{ partial "comments.html" . }}
{{ end }} {{ end }}
{{/* When you use ```mermaid``, render-codeblock-mermaid.html is called and
`.Store.Set "hasMermaid"` is executed.
`.Store.Get "hasMermaid"` will return true and mermaid.js will be loaded.
*/}}
{{ if .Store.Get "hasMermaid" }}
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs';
mermaid.initialize({ startOnLoad: true });
</script>
{{ end }}
{{ end }} {{ end }}