From f44d89a52a070e87f95e6b3a939054ecdd580112 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Sun, 21 Jul 2024 20:03:32 +0800 Subject: [PATCH] :recycle: Refactor: mermaid shortcode and codeblock render --- layouts/_default/_markup/render-codeblock-echarts.html | 1 + layouts/_default/_markup/render-codeblock-mermaid.html | 5 +---- layouts/partials/plugin/echarts.html | 2 +- layouts/partials/plugin/mermaid.html | 4 ++++ layouts/shortcodes/echarts.html | 1 + layouts/shortcodes/mermaid.html | 6 ++---- 6 files changed, 10 insertions(+), 9 deletions(-) create mode 100644 layouts/partials/plugin/mermaid.html diff --git a/layouts/_default/_markup/render-codeblock-echarts.html b/layouts/_default/_markup/render-codeblock-echarts.html index 00c669c2..1a519c8e 100644 --- a/layouts/_default/_markup/render-codeblock-echarts.html +++ b/layouts/_default/_markup/render-codeblock-echarts.html @@ -1 +1,2 @@ {{- dict "Options" .Attributes "Inner" .Inner | partial "plugin/echarts.html" -}} +{{- .Page.Store.Set "hasEcharts" true -}} diff --git a/layouts/_default/_markup/render-codeblock-mermaid.html b/layouts/_default/_markup/render-codeblock-mermaid.html index 79b23615..cb0afbc3 100644 --- a/layouts/_default/_markup/render-codeblock-mermaid.html +++ b/layouts/_default/_markup/render-codeblock-mermaid.html @@ -1,5 +1,2 @@ -
- {{- .Inner | safeHTML }}
-
-{{- .Inner | safeHTML }}
+{{- dict "Options" .Attributes "Inner" .Inner | partial "plugin/mermaid.html" -}}
{{- .Page.Store.Set "hasMermaid" true -}}
diff --git a/layouts/partials/plugin/echarts.html b/layouts/partials/plugin/echarts.html
index df6a2718..10b646c1 100644
--- a/layouts/partials/plugin/echarts.html
+++ b/layouts/partials/plugin/echarts.html
@@ -4,4 +4,4 @@
{{- $attrs := printf `style="width: %v; height: %v;"` $width $height -}}
{{ .Inner | transform.Unmarshal | jsonify }}
-{{- page.Store.Set "hasEcharts" true -}}
+{{- /* EOF */ -}}
diff --git a/layouts/partials/plugin/mermaid.html b/layouts/partials/plugin/mermaid.html
new file mode 100644
index 00000000..8f6f2ed6
--- /dev/null
+++ b/layouts/partials/plugin/mermaid.html
@@ -0,0 +1,4 @@
+{{- /* Mermaid support for code fences extended and shortcodes. */ -}}
+{{ .Inner | safeHTML }}
+{{ .Inner | safeHTML }}
+{{- /* EOF */ -}}
diff --git a/layouts/shortcodes/echarts.html b/layouts/shortcodes/echarts.html
index 3ce66b61..a250074e 100644
--- a/layouts/shortcodes/echarts.html
+++ b/layouts/shortcodes/echarts.html
@@ -1,3 +1,4 @@
{{- $options := .Get "width" | default (.Get 0) | dict "width" -}}
{{- $options = .Get "height" | default (.Get 1) | dict "height" | merge $options -}}
{{- dict "Options" $options "Inner" .Inner | partial "plugin/echarts.html" -}}
+{{- .Page.Store.Set "hasEcharts" true -}}
diff --git a/layouts/shortcodes/mermaid.html b/layouts/shortcodes/mermaid.html
index 79b23615..878e3b8c 100644
--- a/layouts/shortcodes/mermaid.html
+++ b/layouts/shortcodes/mermaid.html
@@ -1,5 +1,3 @@
-
- {{- .Inner | safeHTML }}
-
-{{- .Inner | safeHTML }}
+{{- $options := dict -}}
+{{- dict "Options" $options "Inner" .Inner | partial "plugin/mermaid.html" -}}
{{- .Page.Store.Set "hasMermaid" true -}}