Improve consistency of handling shrotcode attributes
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
Tabs let you organize content by context, for example installation instructions for each supported platform.
|
Tabs let you organize content by context, for example installation instructions for each supported platform.
|
||||||
|
|
||||||
```tpl
|
```tpl
|
||||||
{{</* tabs "id" */>}}
|
{{</* tabs */>}}
|
||||||
{{%/* tab "MacOS" */%}} # MacOS Content {{%/* /tab */%}}
|
{{%/* tab "MacOS" */%}} # MacOS Content {{%/* /tab */%}}
|
||||||
{{%/* tab "Linux" */%}} # Linux Content {{%/* /tab */%}}
|
{{%/* tab "Linux" */%}} # Linux Content {{%/* /tab */%}}
|
||||||
{{%/* tab "Windows" */%}} # Windows Content {{%/* /tab */%}}
|
{{%/* tab "Windows" */%}} # Windows Content {{%/* /tab */%}}
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
{{- range $key, $value := . -}} {{- $key | htmlEscape -}}="{{- $value | safeHTMLAttr -}}" {{- end -}}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
{{- /*
|
||||||
|
This is generic function the helps modifying and merging dictionaries, usually used for html attributes
|
||||||
|
Logic is executed in order defined below.
|
||||||
|
partial "docs/text/mapper" (dict
|
||||||
|
"attributes" (cond .IsNamedParams .Params dict)
|
||||||
|
"keep" (slice "id" "class" "tabindex" "alt" "title" "loading")
|
||||||
|
"set" (dict "href" "https://")
|
||||||
|
"merge" (dict "class" "a-class")
|
||||||
|
"delimiter" " " // Used when merging values
|
||||||
|
"delete" (slice "src")
|
||||||
|
)
|
||||||
|
*/ -}}
|
||||||
|
|
||||||
|
{{- $store := newScratch -}}
|
||||||
|
{{- $allowlist := or (.keep) (slice "id" "class" "tabindex" "dir")}}
|
||||||
|
{{- range $key, $value := .attributes -}}
|
||||||
|
{{- if in $allowlist $key -}}
|
||||||
|
{{- $store.Set $key $value -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- range $key, $value := .set -}}
|
||||||
|
{{- $store.Set $key (print $value) -}}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- range $key, $value := .merge -}}
|
||||||
|
{{- $merged := (slice) | append $value | append (or (index $.attributes $key) (slice)) -}}
|
||||||
|
{{- $delimiter := or ($.delimiter) (" ") }}
|
||||||
|
{{- $store.Set $key (delimit $merged $delimiter) -}}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- range $key := .delete -}}
|
||||||
|
{{- $store.Delete $key -}}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- return $store.Values -}}
|
||||||
@@ -7,10 +7,18 @@
|
|||||||
<script defer src="{{ "asciinema/asciinema-auto.js" | relURL }}"></script>
|
<script defer src="{{ "asciinema/asciinema-auto.js" | relURL }}"></script>
|
||||||
{{- .Page.Store.Set "asciinema" true -}}
|
{{- .Page.Store.Set "asciinema" true -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
{{- $href := (partial "docs/links/portable-image" (dict "Page" .Page "Destination" (.Get "cast"))) -}}
|
||||||
{{- with (partial "docs/links/portable-image" (dict "Page" .Page "Destination" (index .Params "cast"))) -}}
|
{{- .Store.Set "asciinema" .Params -}}
|
||||||
{{- $opts := newScratch -}}
|
{{- .Store.DeleteInMap "asciinema" "cast" -}}
|
||||||
{{- $opts.Set "asciinema" $.Params -}}
|
{{- $attributes := partial "docs/text/mapper" (dict
|
||||||
{{- $opts.DeleteInMap "asciinema" "cast" -}}
|
"attributes" (dict)
|
||||||
<div class="asciinema book-asciinema" id="asciinema-{{ $.Ordinal }}" x-data-cast="{{ . | safeHTMLAttr }}" x-data-opts="{{ $opts.Get "asciinema" | jsonify | safeHTMLAttr }}"></div>
|
"set" (dict
|
||||||
{{- end -}}
|
"id" (printf "asciinema-%d" .Ordinal)
|
||||||
|
"x-data-cast" $href
|
||||||
|
"x-data-opts" (.Store.Get "asciinema" | jsonify)
|
||||||
|
)
|
||||||
|
"merge" (dict
|
||||||
|
"class" (slice "asciinema" "book-asciinema")
|
||||||
|
)
|
||||||
|
) -}}
|
||||||
|
<div {{ partial "docs/html-attrs" $attributes | safeHTMLAttr }}></div>
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
{{- $style := default "default" (.Get "style") -}}
|
{{- $style := or (.Get "style") (.Get 0) "default" -}}
|
||||||
<span class="book-badge {{ $style }}">
|
{{- $attributes := partial "docs/text/mapper" (dict
|
||||||
{{- with .Get "title" -}}<span class="book-badge-title">{{ . | plainify }}</span>{{- end -}}
|
"attributes" (cond .IsNamedParams .Params dict)
|
||||||
{{- with .Get "value" -}}<span class="book-badge-value">{{ . | plainify }}</span>{{- end -}}
|
"merge" (dict
|
||||||
|
"class" (slice "book-badge" $style)
|
||||||
|
)
|
||||||
|
) -}}
|
||||||
|
<span {{ partial "docs/html-attrs" $attributes | safeHTMLAttr }}>
|
||||||
|
{{- with or (.Get "title") (.Get 1) -}}<span class="book-badge-title">{{ . | plainify }}</span>{{- end -}}
|
||||||
|
{{- with or (.Get "value") (.Get 2) -}}<span class="book-badge-value">{{ . | plainify }}</span>{{- end -}}
|
||||||
</span>
|
</span>
|
||||||
{{- /* remove whitespaces */ -}}
|
{{- /* remove whitespaces */ -}}
|
||||||
|
|||||||
@@ -1,6 +1,18 @@
|
|||||||
{{- $href := partial "docs/links/portable-link" (dict "Page" .Page "Destination" (.Get "href")) -}}
|
{{- $href := partial "docs/links/portable-link" (dict "Page" .Page "Destination" (.Get "href")) -}}
|
||||||
{{- $isRemote := (urls.Parse $href).IsAbs -}}
|
{{- $isRemote := (urls.Parse $href).IsAbs -}}
|
||||||
<a {{ with $href }}href="{{ $href }}"{{ end }} {{ with $isRemote }}target="_blank" rel="noopener"{{ end }} class="book-btn{{ with .Get "class" }} {{ . }}{{ end }}">
|
{{- $attributes := partial "docs/text/mapper" (dict
|
||||||
|
"attributes" (cond .IsNamedParams .Params dict)
|
||||||
|
"set" (dict
|
||||||
|
"href" $href
|
||||||
|
"target" "_blank"
|
||||||
|
"rel" "noopener"
|
||||||
|
)
|
||||||
|
"merge" (dict
|
||||||
|
"class" "book-btn"
|
||||||
|
)
|
||||||
|
"delete" (cond $isRemote (slice) (slice "target" "rel"))
|
||||||
|
) -}}
|
||||||
|
<a {{ partial "docs/html-attrs" $attributes | safeHTMLAttr }}>
|
||||||
{{- .InnerDeindent -}}
|
{{- .InnerDeindent -}}
|
||||||
</a>
|
</a>
|
||||||
{{- /* remove whitespaces */ -}}
|
{{- /* remove whitespaces */ -}}
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
{{- $ratio := (split (.Get "ratio") ":") -}}
|
{{- $ratio := (split (.Get "ratio") ":") -}}
|
||||||
{{- if strings.Contains .InnerDeindent "<--->" -}}
|
{{- if strings.Contains .InnerDeindent "<--->" -}}
|
||||||
{{- warnf "Columns shortcode seprator '<--->' is deprecated, use markdown list instead." -}}
|
{{- warnf "Columns shortcode seprator '<--->' is deprecated, use markdown list instead." -}}
|
||||||
<div class="book-columns flex flex-wrap{{ with .Get "class" }} {{ . }}{{ end }}">
|
{{- $attributes := partial "docs/text/mapper" (dict
|
||||||
|
"attributes" (cond .IsNamedParams .Params dict)
|
||||||
|
"merge" (dict
|
||||||
|
"class" (slice "book-columns" "flex" "flex-wrap")
|
||||||
|
)
|
||||||
|
) -}}
|
||||||
|
<div {{ partial "docs/html-attrs" $attributes | safeHTMLAttr }}>
|
||||||
{{- range $index, $content := split .InnerDeindent "<--->" -}}
|
{{- range $index, $content := split .InnerDeindent "<--->" -}}
|
||||||
{{- $grow := default 1 (index $ratio $index) -}}
|
{{- $grow := default 1 (index $ratio $index) -}}
|
||||||
<div class="flex-even markdown-inner" style="flex-grow: {{ $grow }};">
|
<div class="flex-even markdown-inner" style="flex-grow: {{ $grow }};">
|
||||||
@@ -15,7 +21,13 @@
|
|||||||
flex-grow: {{ default 1 $grow }};
|
flex-grow: {{ default 1 $grow }};
|
||||||
}
|
}
|
||||||
{{- end -}}</style>{{- end -}}
|
{{- end -}}</style>{{- end -}}
|
||||||
<div class="book-columns book-columns-{{ .Ordinal }}{{ with .Get "class" }} {{ . }}{{ end }}">
|
{{- $attributes := partial "docs/text/mapper" (dict
|
||||||
|
"attributes" (cond .IsNamedParams .Params dict)
|
||||||
|
"merge" (dict
|
||||||
|
"class" (slice "book-columns")
|
||||||
|
)
|
||||||
|
) -}}
|
||||||
|
<div {{ partial "docs/html-attrs" $attributes | safeHTMLAttr }}>
|
||||||
{{ .Inner | safeHTML -}}
|
{{ .Inner | safeHTML -}}
|
||||||
</div>
|
</div>
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
{{- /* remove whitespaces */ -}}
|
{{- $attributes := partial "docs/text/mapper" (dict
|
||||||
<details {{ if or (.Get "open") (in .Params "open") }}open{{ end }}>
|
"attributes" (cond .IsNamedParams .Params dict)
|
||||||
|
"merge" (dict
|
||||||
|
"open" (cond .IsNamedParams (.Get "open") (in .Params "open"))
|
||||||
|
)
|
||||||
|
) -}}
|
||||||
|
<details {{ partial "docs/html-attrs" $attributes | safeHTMLAttr }}>
|
||||||
{{- $summary := cond .IsNamedParams (.Get "title") (.Get 0) -}}
|
{{- $summary := cond .IsNamedParams (.Get "title") (.Get 0) -}}
|
||||||
<summary>{{ $summary | .Page.RenderString }}</summary>
|
<summary>{{ $summary | .Page.RenderString }}</summary>
|
||||||
{{- /* remove whitespaces */ -}}
|
{{- /* remove whitespaces */ -}}
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
{{- /* remove whitespaces */ -}}
|
{{- warnf "Hint shortcode is deprecated, use markdown alerts format: '> [!NOTE] ...'" -}}
|
||||||
<blockquote class="book-hint {{ default "default" (.Get 0) }}">
|
{{- $attributes := partial "docs/text/mapper" (dict
|
||||||
|
"attributes" (cond .IsNamedParams .Params dict)
|
||||||
|
"merge" (dict
|
||||||
|
"class" (slice "book-hint" (or (.Get 0) "default"))
|
||||||
|
)
|
||||||
|
) -}}
|
||||||
|
<blockquote {{ partial "docs/html-attrs" $attributes | safeHTMLAttr }}>
|
||||||
{{ .Inner | safeHTML -}}
|
{{ .Inner | safeHTML -}}
|
||||||
</blockquote>
|
</blockquote>
|
||||||
{{- /* remove whitespaces */ -}}
|
{{- /* remove whitespaces */ -}}
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
{{- $destination := partial "docs/links/portable-image" (dict "Page" .Page "Destination" (.Get "src")) -}}
|
{{- $destination := partial "docs/links/portable-image" (dict "Page" .Page "Destination" (.Get "src")) -}}
|
||||||
|
{{- $attributes := partial "docs/text/mapper" (dict
|
||||||
|
"attributes" (cond .IsNamedParams .Params dict)
|
||||||
|
"keep" (slice "id" "class" "tabindex" "alt" "title" "loading")
|
||||||
|
) -}}
|
||||||
<label class="book-image" for="book-image-toggle-{{ .Ordinal }}">
|
<label class="book-image" for="book-image-toggle-{{ .Ordinal }}">
|
||||||
<input class="hidden toggle" type="checkbox" id="book-image-toggle-{{ .Ordinal }}" />
|
<input class="hidden toggle" type="checkbox" id="book-image-toggle-{{ .Ordinal }}" />
|
||||||
<img src="{{ $destination | safeURL }}"
|
<img src="{{ $destination | safeURL }}" {{ partial "docs/html-attrs" $attributes | safeHTMLAttr }} />
|
||||||
{{- with .Get "alt"}} alt="{{ . }}"{{ end -}}
|
|
||||||
{{- with .Get "title"}} title="{{ . }}"{{ end -}}
|
|
||||||
{{- with .Get "loading"}} loading="{{ . }}"{{ end -}}
|
|
||||||
{{- with .Get "class"}} class="{{ . }}"{{ end -}}
|
|
||||||
/>
|
|
||||||
</label>
|
</label>
|
||||||
{{- /* remove whitespaces */ -}}
|
{{- /* remove whitespaces */ -}}
|
||||||
@@ -1,8 +1,14 @@
|
|||||||
|
{{- $attributes := partial "docs/text/mapper" (dict
|
||||||
|
"attributes" (cond .IsNamedParams .Params dict)
|
||||||
|
"merge" (dict
|
||||||
|
"class" "book-katex"
|
||||||
|
)
|
||||||
|
) -}}
|
||||||
{{- if .Inner -}}
|
{{- if .Inner -}}
|
||||||
{{- if .Get "display" -}}
|
{{- if .Get "display" -}}
|
||||||
<div>{{ printf "\\[ %s \\]" .Inner }}</div>
|
<div {{ partial "docs/html-attrs" $attributes | safeHTMLAttr }}>{{ printf "\\[ %s \\]" .Inner }}</div>
|
||||||
{{- else -}}
|
{{- else -}}
|
||||||
<span>{{ printf "\\( %s \\)" .Inner }}</span>
|
<span {{ partial "docs/html-attrs" $attributes | safeHTMLAttr }}>{{ printf "\\( %s \\)" .Inner }}</span>
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- if not (.Page.Store.Get "katex") -}}
|
{{- if not (.Page.Store.Get "katex") -}}
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
{{- /* remove whitespaces */ -}}
|
{{- $attributes := partial "docs/text/mapper" (dict
|
||||||
<pre class="mermaid{{ with .Get "class" }} {{ . }}{{ end }}">
|
"attributes" (cond .IsNamedParams .Params dict)
|
||||||
|
"merge" (dict
|
||||||
|
"class" "mermaid"
|
||||||
|
)
|
||||||
|
) -}}
|
||||||
|
<pre {{ partial "docs/html-attrs" $attributes | safeHTMLAttr }}>
|
||||||
{{- .Inner | htmlEscape | safeHTML -}}
|
{{- .Inner | htmlEscape | safeHTML -}}
|
||||||
</pre>
|
</pre>
|
||||||
{{- if not (.Page.Store.Get "mermaid") -}}
|
{{- if not (.Page.Store.Get "mermaid") -}}
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
{{- /* remove whitespaces */ -}}
|
{{- $attributes := partial "docs/text/mapper" (dict
|
||||||
<div class="book-steps {{ with .Get "class" }}{{ . }}{{ end }}">
|
"attributes" (cond .IsNamedParams .Params dict)
|
||||||
|
"merge" (dict
|
||||||
|
"class" "book-steps"
|
||||||
|
)
|
||||||
|
) -}}
|
||||||
|
<div {{ partial "docs/html-attrs" $attributes | safeHTMLAttr }}>
|
||||||
{{ .Inner -}}
|
{{ .Inner -}}
|
||||||
</div>
|
</div>
|
||||||
{{- /* remove whitespaces */ -}}
|
{{- /* remove whitespaces */ -}}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{{- $group := printf "tabs-%v" (default .Parent.Ordinal (.Parent.Get 0)) -}}
|
{{- $group := printf "tabs-%v" .Parent.Ordinal -}}
|
||||||
{{- $tab := printf "%s-%d" $group .Ordinal -}}
|
{{- $tab := printf "%s-%d" $group .Ordinal -}}
|
||||||
<input type="radio" class="toggle" name="{{ $group }}" id="{{ $tab }}" {{ if not .Ordinal }}checked="checked"{{ end }} />
|
<input type="radio" class="toggle" name="{{ $group }}" id="{{ $tab }}" {{ if not .Ordinal }}checked="checked"{{ end }} />
|
||||||
{{- /* remove whitespaces */ -}}
|
{{- /* remove whitespaces */ -}}
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
{{- /* remove whitespaces */ -}}
|
{{- $attributes := partial "docs/text/mapper" (dict
|
||||||
<div class="book-tabs">
|
"attributes" (cond .IsNamedParams .Params dict)
|
||||||
|
"merge" (dict
|
||||||
|
"class" "book-tabs"
|
||||||
|
)
|
||||||
|
) -}}
|
||||||
|
<div {{ partial "docs/html-attrs" $attributes | safeHTMLAttr }}>
|
||||||
{{- .Inner -}}
|
{{- .Inner -}}
|
||||||
</div>
|
</div>
|
||||||
{{- /* remove whitespaces */ -}}
|
{{- /* remove whitespaces */ -}}
|
||||||
|
|||||||
Reference in New Issue
Block a user