Skip to content

Commit

Permalink
mermaid: support Markdown attributes #795
Browse files Browse the repository at this point in the history
  • Loading branch information
McShelby committed Mar 11, 2024
1 parent 345de23 commit a9e7e8a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
7 changes: 4 additions & 3 deletions layouts/_default/_markup/render-codeblock-mermaid.html
@@ -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")
) }}
27 changes: 24 additions & 3 deletions layouts/partials/shortcodes/mermaid.html
Expand Up @@ -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 }}
5 changes: 0 additions & 5 deletions static/css/theme.css
Expand Up @@ -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;
}

0 comments on commit a9e7e8a

Please sign in to comment.