Skip to content

Commit

Permalink
♻️ Refactor: mermaid shortcode and codeblock render
Browse files Browse the repository at this point in the history
  • Loading branch information
Lruihao committed Jul 21, 2024
1 parent 2a53dba commit f44d89a
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions layouts/_default/_markup/render-codeblock-echarts.html
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
{{- dict "Options" .Attributes "Inner" .Inner | partial "plugin/echarts.html" -}}
{{- .Page.Store.Set "hasEcharts" true -}}
5 changes: 1 addition & 4 deletions layouts/_default/_markup/render-codeblock-mermaid.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
<pre class="mermaid">
{{- .Inner | safeHTML }}
</pre>
<template>{{- .Inner | safeHTML }}</template>
{{- dict "Options" .Attributes "Inner" .Inner | partial "plugin/mermaid.html" -}}
{{- .Page.Store.Set "hasMermaid" true -}}
2 changes: 1 addition & 1 deletion layouts/partials/plugin/echarts.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
{{- $attrs := printf `style="width: %v; height: %v;"` $width $height -}}
<div class="echarts" {{ $attrs | safeHTMLAttr }}></div>
<template>{{ .Inner | transform.Unmarshal | jsonify }}</template>
{{- page.Store.Set "hasEcharts" true -}}
{{- /* EOF */ -}}
4 changes: 4 additions & 0 deletions layouts/partials/plugin/mermaid.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{- /* Mermaid support for code fences extended and shortcodes. */ -}}
<pre class="mermaid">{{ .Inner | safeHTML }}</pre>
<template>{{ .Inner | safeHTML }}</template>
{{- /* EOF */ -}}
1 change: 1 addition & 0 deletions layouts/shortcodes/echarts.html
Original file line number Diff line number Diff line change
@@ -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 -}}
6 changes: 2 additions & 4 deletions layouts/shortcodes/mermaid.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<pre class="mermaid">
{{- .Inner | safeHTML }}
</pre>
<template>{{- .Inner | safeHTML }}</template>
{{- $options := dict -}}
{{- dict "Options" $options "Inner" .Inner | partial "plugin/mermaid.html" -}}
{{- .Page.Store.Set "hasMermaid" true -}}

0 comments on commit f44d89a

Please sign in to comment.