mermaid: support Markdown attributes #795

This commit is contained in:
Sören Weber 2024-03-11 20:57:21 +01:00
parent 345de238c9
commit a9e7e8a492
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
3 changed files with 28 additions and 11 deletions

View file

@ -1,5 +1,6 @@
{{- partial "shortcodes/mermaid.html" (dict
"page" .Page
"content" .Inner
"align" (index .Attributes "align")
"page" .Page
"attributes" .Attributes
"content" .Inner
"align" (index .Attributes "align")
) }}

View file

@ -18,9 +18,30 @@
{{- $zoom = (eq . "true") }}
{{- end }}
{{- end }}
{{- /* separate shortcode attributes from rest */}}
{{- $attributes := .attributes | default dict }}
{{- $otherAttributes := dict }}
{{- range $k, $v := $attributes }}
{{- if eq $k "align" }}
{{- else if eq $k "zoom" }}
{{- else }}
{{- $otherAttributes = (dict $k $v) | merge $otherAttributes }}
{{- end }}
{{- end }}
{{- $attributes = $otherAttributes }}
{{- /* enrich attributes */}}
{{- $attributes = merge $attributes (dict "class" (delimit (append (index $attributes "class" | default slice) "mermaid" slice) " ")) }}
{{- $attributes = merge $attributes (dict "class" (delimit (append (index $attributes "class" | default slice) (printf "align-%s" $align) slice) " ")) }}
{{- $attributes = merge $attributes (dict "class" (delimit (append (index $attributes "class" | default slice) (printf "%s" (cond $zoom "zoomable" "")) slice) " ")) }}
{{- with $page }}
<pre class="mermaid align-{{ $align }}{{ if $zoom }} zoomable{{ end }}">
{{- replaceRE "&#39;" "'" ( replaceRE "&#34;" "\"" ( $content | safeHTML ) ) -}}
</pre>
<pre
{{- range $k, $v := $attributes }}
{{- if $v }}
{{- printf " %s=%q" $k $v | safeHTMLAttr }}
{{- end }}
{{- end }}>{{ replaceRE "&#39;" "'" ( replaceRE "&#34;" "\"" ( $content | safeHTML ) ) }}</pre>
{{- .Store.Set "hasMermaid" true }}
{{- end }}

View file

@ -2288,8 +2288,3 @@ html[dir="rtl"] #R-sidebar ul.collapsible-menu > li > label > i.fa-chevron-right
.term-list ul > li ~ li:before {
content: " | "
}
.red {
background-color: red !important;
border: 5px solid #d000d0 !important;
}