From 915477e52753317cf857aba1f27ced344800c1b6 Mon Sep 17 00:00:00 2001 From: Alex Shpak Date: Fri, 26 Sep 2025 17:28:08 +0200 Subject: [PATCH] Review and update whitespaces in mermaid and KaTeX to improve shortcode nesting --- .../content.en/docs/shortcodes/mermaid.md | 96 +++++++++---------- layouts/_markup/render-blockquote.html | 12 +-- layouts/_markup/render-codeblock-katex.html | 24 ++--- layouts/_markup/render-codeblock-mermaid.html | 22 ++--- layouts/_partials/docs/languages.html | 1 - layouts/_shortcodes/asciinema.html | 3 +- layouts/_shortcodes/katex.html | 24 ++--- layouts/_shortcodes/mermaid.html | 19 ++-- 8 files changed, 91 insertions(+), 110 deletions(-) diff --git a/exampleSite/content.en/docs/shortcodes/mermaid.md b/exampleSite/content.en/docs/shortcodes/mermaid.md index bc40fab..cde6866 100644 --- a/exampleSite/content.en/docs/shortcodes/mermaid.md +++ b/exampleSite/content.en/docs/shortcodes/mermaid.md @@ -11,63 +11,55 @@ create a `mermaid.json` file in your `assets` folder! ## Example {{% columns %}} +- ````tpl + ```mermaid + stateDiagram-v2 + State1: The state with a note + note right of State1 + Important information! You can write + notes. + end note + State1 --> State2 + note left of State2 : This is the note to the left. + ``` + ```` -````tpl -```mermaid -stateDiagram-v2 - State1: The state with a note - note right of State1 - Important information! You can write - notes. - end note - State1 --> State2 - note left of State2 : This is the note to the left. -``` -```` - -<---> - -```mermaid -stateDiagram-v2 - State1: The state with a note - note right of State1 - Important information! You can write - notes. - end note - State1 --> State2 - note left of State2 : This is the note to the left. -``` - +- ```mermaid + stateDiagram-v2 + State1: The state with a note + note right of State1 + Important information! You can write + notes. + end note + State1 --> State2 + note left of State2 : This is the note to the left. + ``` {{% /columns %}} {{% columns %}} +- ```tpl + {{}} + stateDiagram-v2 + State1: The state with a note + note right of State1 + Important information! You can write + notes. + end note + State1 --> State2 + note left of State2 : This is the note to the left. + {{< /mermaid */>}} + ``` -```tpl -{{}} -stateDiagram-v2 - State1: The state with a note - note right of State1 - Important information! You can write - notes. - end note - State1 --> State2 - note left of State2 : This is the note to the left. -{{< /mermaid */>}} -``` - -<---> - -{{< mermaid >}} -stateDiagram-v2 - State1: The state with a note - note right of State1 - Important information! You can write - notes. - end note - State1 --> State2 - note left of State2 : This is the note to the left. -{{< /mermaid >}} - +- {{< mermaid >}} + stateDiagram-v2 + State1: The state with a note + note right of State1 + Important information! You can write + notes. + end note + State1 --> State2 + note left of State2 : This is the note to the left. + {{< /mermaid >}} {{% /columns %}} ## Diagrams diff --git a/layouts/_markup/render-blockquote.html b/layouts/_markup/render-blockquote.html index 88809a1..2ca3763 100644 --- a/layouts/_markup/render-blockquote.html +++ b/layouts/_markup/render-blockquote.html @@ -1,9 +1,9 @@ -{{- $attributes := .Attributes }} -{{- $class := printf "book-hint %s" ($.AlertType | lower) }} -{{- if isset $attributes "class" }} - {{ $class = printf "%s %s" $class (index $attributes "class") }} +{{- $attributes := .Attributes -}} +{{- $class := printf "book-hint %s" ($.AlertType | lower) -}} +{{- if isset $attributes "class" -}} + {{- $class = printf "%s %s" $class (index $attributes "class") -}} {{ end -}} -{{- $attributes = merge $attributes (dict "class" $class) }} +{{- $attributes = merge $attributes (dict "class" $class) -}}
- {{ .Text }} +{{ .Text -}}
\ No newline at end of file diff --git a/layouts/_markup/render-codeblock-katex.html b/layouts/_markup/render-codeblock-katex.html index 94bcb55..5a49b25 100644 --- a/layouts/_markup/render-codeblock-katex.html +++ b/layouts/_markup/render-codeblock-katex.html @@ -1,13 +1,13 @@ -{{- if not (.Page.Store.Get "katex") -}} - - - -{{ with resources.Get "katex.json" }} - -{{ end }} -{{- .Page.Store.Set "katex" true -}} -{{- end -}} - -{{- with .Inner }} +{{- with .Inner -}} \[ {{ .| htmlEscape | safeHTML }} \] -{{ end -}} +{{- end -}} +{{- if not (.Page.Store.Get "katex") -}} + {{- /* Include katex only first time */ -}} + + {{- /* remove whitespaces */ -}} + + {{- with resources.Get "katex.json" | minify -}} + + {{- end -}} + {{- .Page.Store.Set "katex" true -}} +{{- end -}} \ No newline at end of file diff --git a/layouts/_markup/render-codeblock-mermaid.html b/layouts/_markup/render-codeblock-mermaid.html index 097857a..6d04fe3 100644 --- a/layouts/_markup/render-codeblock-mermaid.html +++ b/layouts/_markup/render-codeblock-mermaid.html @@ -1,12 +1,10 @@ -{{ if not (.Page.Store.Get "mermaid") }} - - -{{ with resources.Get "mermaid.json" }} - -{{ end }} -{{ .Page.Store.Set "mermaid" true }} -{{ end }} - -
-  {{- .Inner -}}
-
+{{- /* remove whitespaces */ -}} +
{{ .Inner | htmlEscape | safeHTML -}}
+{{- if not (.Page.Store.Get "mermaid") -}} + {{- /* Include mermaid only first time */ -}} + + {{- with resources.Get "mermaid.json" | minify -}} + + {{- end -}} + {{- .Page.Store.Set "mermaid" true -}} +{{- end -}} \ No newline at end of file diff --git a/layouts/_partials/docs/languages.html b/layouts/_partials/docs/languages.html index cafa737..83557ab 100644 --- a/layouts/_partials/docs/languages.html +++ b/layouts/_partials/docs/languages.html @@ -1,4 +1,3 @@ - {{ $bookTranslatedOnly := default false .Site.Params.BookTranslatedOnly }} {{ $translations := dict }} {{ if (eq $bookTranslatedOnly false ) }} diff --git a/layouts/_shortcodes/asciinema.html b/layouts/_shortcodes/asciinema.html index 236c533..0d20e32 100644 --- a/layouts/_shortcodes/asciinema.html +++ b/layouts/_shortcodes/asciinema.html @@ -1,6 +1,5 @@ {{- if not (.Page.Store.Get "asciinema") -}} - - {{- /* remove whitespaces */ -}} + {{- /* Include asciinema player only first time */ -}} {{- /* remove whitespaces */ -}} diff --git a/layouts/_shortcodes/katex.html b/layouts/_shortcodes/katex.html index 4401156..14fe0b1 100644 --- a/layouts/_shortcodes/katex.html +++ b/layouts/_shortcodes/katex.html @@ -1,21 +1,17 @@ +{{- if .Inner -}} + {{- if .Get "display" -}} +
{{ printf "\\[ %s \\]" .Inner }}
+ {{- else -}} + {{ printf "\\( %s \\)" .Inner }} + {{- end -}} +{{- end -}} {{- if not (.Page.Store.Get "katex") -}} - - {{- /* remove whitespaces */ -}} + {{- /* Include katex only first time */ -}} {{- /* remove whitespaces */ -}} - {{- with resources.Get "katex.json" -}} - + {{- with resources.Get "katex.json" | minify -}} + {{- end -}} {{- .Page.Store.Set "katex" true -}} {{- end -}} - -{{- if .Inner -}} - - {{- if .Get "display" -}} - \[ {{ .Inner }} \] - {{- else -}} - \( {{ .Inner }} \) - {{- end -}} - -{{- end -}} diff --git a/layouts/_shortcodes/mermaid.html b/layouts/_shortcodes/mermaid.html index f5faa21..859b6b0 100644 --- a/layouts/_shortcodes/mermaid.html +++ b/layouts/_shortcodes/mermaid.html @@ -1,14 +1,11 @@ +{{- /* remove whitespaces */ -}} +
+  {{- .Inner | htmlEscape | safeHTML -}}
+
{{- if not (.Page.Store.Get "mermaid") -}} - - {{- /* remove whitespaces */ -}} - - {{- with resources.Get "mermaid.json" -}} - + {{- /* Include mermaid only first time */ -}} + {{- with resources.Get "mermaid.json" | minify -}} + {{- end -}} {{- .Page.Store.Set "mermaid" true -}} -{{- end -}} - -
-{{- .Inner | htmlEscape | safeHTML  -}}
-
-{{- /* remove whitespaces */ -}} +{{- end -}} \ No newline at end of file