diff --git a/layouts/_default/_markup/render-codeblock-echarts.html b/layouts/_default/_markup/render-codeblock-echarts.html new file mode 100644 index 00000000..00c669c2 --- /dev/null +++ b/layouts/_default/_markup/render-codeblock-echarts.html @@ -0,0 +1 @@ +{{- dict "Options" .Attributes "Inner" .Inner | partial "plugin/echarts.html" -}} diff --git a/layouts/partials/assets.html b/layouts/partials/assets.html index 0d77ad3c..0d370f53 100644 --- a/layouts/partials/assets.html +++ b/layouts/partials/assets.html @@ -124,7 +124,7 @@ {{- end -}} {{- /* ECharts */ -}} -{{- if .HasShortcode "echarts" -}} +{{- if .Store.Get "hasEcharts" -}} {{- $source := $cdn.echartsJS | default "lib/echarts/echarts.min.js" -}} {{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}} {{- $lightTheme := resources.Get "lib/echarts/theme/light.yml" | transform.Unmarshal -}} diff --git a/layouts/partials/plugin/echarts.html b/layouts/partials/plugin/echarts.html new file mode 100644 index 00000000..df6a2718 --- /dev/null +++ b/layouts/partials/plugin/echarts.html @@ -0,0 +1,7 @@ +{{- /* Echarts support for code fences extended and shortcodes. */ -}} +{{- $width := .Options.width | default "100%" -}} +{{- $height := .Options.height | default "30rem" -}} +{{- $attrs := printf `style="width: %v; height: %v;"` $width $height -}} +
+{{ .Inner | transform.Unmarshal | jsonify }} +{{- page.Store.Set "hasEcharts" true -}} diff --git a/layouts/shortcodes/echarts.html b/layouts/shortcodes/echarts.html index f3ce6e9f..3ce66b61 100644 --- a/layouts/shortcodes/echarts.html +++ b/layouts/shortcodes/echarts.html @@ -1,7 +1,3 @@ -{{- $content := .Inner | transform.Unmarshal | jsonify -}} -{{- $width := cond .IsNamedParams (.Get "width") (.Get 0) | default "100%" -}} -{{- $height := cond .IsNamedParams (.Get "height") (.Get 1) | default "30rem" -}} -{{- $attrs := printf `style="width: %v; height: %v;"` $width $height -}} - -{{ $content }} -{{- /* EOF */ -}} +{{- $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" -}}