layouts: add Graphviz support
Similar to TikZ support.
This commit is contained in:
parent
491041df09
commit
fc0479a1dc
|
@ -8,6 +8,7 @@ tags:
|
||||||
categories:
|
categories:
|
||||||
favorite: false
|
favorite: false
|
||||||
tikz: true
|
tikz: true
|
||||||
|
graphviz: true
|
||||||
---
|
---
|
||||||
|
|
||||||
## Test post please ignore
|
## Test post please ignore
|
||||||
|
@ -40,6 +41,16 @@ echo hello world | cut -d' ' -f 1
|
||||||
\end{tikzpicture}
|
\end{tikzpicture}
|
||||||
{{% /tikz %}}
|
{{% /tikz %}}
|
||||||
|
|
||||||
|
### Graphviz support
|
||||||
|
|
||||||
|
{{% graphviz %}}
|
||||||
|
graph {
|
||||||
|
a -- b
|
||||||
|
b -- c
|
||||||
|
c -- a
|
||||||
|
}
|
||||||
|
{{% /graphviz %}}
|
||||||
|
|
||||||
### Spoilers
|
### Spoilers
|
||||||
|
|
||||||
{{% spoiler "Don't open me" %}}
|
{{% spoiler "Don't open me" %}}
|
||||||
|
|
|
@ -3,6 +3,23 @@
|
||||||
<link rel="stylesheet" type="text/css" href="https://tikzjax.com/v1/fonts.css">
|
<link rel="stylesheet" type="text/css" href="https://tikzjax.com/v1/fonts.css">
|
||||||
<script async src="https://tikzjax.com/v1/tikzjax.js"></script>
|
<script async src="https://tikzjax.com/v1/tikzjax.js"></script>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
<!-- Graphviz support -->
|
||||||
|
{{ if (.Params.graphviz) }}
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/@viz-js/viz@3.7.0/lib/viz-standalone.min.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
(function() {
|
||||||
|
Viz.instance().then(function(viz) {
|
||||||
|
Array.prototype.forEach.call(document.querySelectorAll("pre.graphviz"), function(x) {
|
||||||
|
var svg = viz.renderSVGElement(x.innerText);
|
||||||
|
// Let CSS take care of the SVG size
|
||||||
|
svg.removeAttribute("width")
|
||||||
|
svg.setAttribute("height", "auto")
|
||||||
|
x.replaceChildren(svg)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
{{ end }}
|
||||||
{{ with .OutputFormats.Get "atom" -}}
|
{{ with .OutputFormats.Get "atom" -}}
|
||||||
{{ printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }}
|
{{ printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }}
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
|
|
16
layouts/shortcodes/graphviz.html
Normal file
16
layouts/shortcodes/graphviz.html
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
<pre class="graphviz">
|
||||||
|
{{ with .Get "file" }}
|
||||||
|
{{ if eq (. | printf "%.1s") "/" }}
|
||||||
|
{{/* Absolute path are from root of site. */}}
|
||||||
|
{{ $.Scratch.Set "filepath" . }}
|
||||||
|
{{ else }}
|
||||||
|
{{/* Relative paths are from page directory. */}}
|
||||||
|
{{ $.Scratch.Set "filepath" $.Page.File.Dir }}
|
||||||
|
{{ $.Scratch.Add "filepath" . }}
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
{{ $.Scratch.Get "filepath" | readFile }}
|
||||||
|
{{ else }}
|
||||||
|
{{.Inner}}
|
||||||
|
{{ end }}
|
||||||
|
</pre>
|
Loading…
Reference in a new issue