Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/google/docsy.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Deininger <adeininger@urbanonline.de>2022-10-13 13:30:22 +0300
committerGeri Ochoa <gerino@protonmail.com>2022-10-21 20:14:56 +0300
commitabb7307a311f04de5e97d0fda6cafa49c0d9ddf7 (patch)
tree1591139616654987e43feeb37ce94aab5ff76cdb
parent99eacb09ffb01d8d73f3367ea821e1412a572572 (diff)
Shortcodes for tabbed panes: improved whitespace handling
-rw-r--r--layouts/shortcodes/tab.html96
-rw-r--r--layouts/shortcodes/tabpane.html217
2 files changed, 155 insertions, 158 deletions
diff --git a/layouts/shortcodes/tab.html b/layouts/shortcodes/tab.html
index c947ac4..8ec7e09 100644
--- a/layouts/shortcodes/tab.html
+++ b/layouts/shortcodes/tab.html
@@ -1,52 +1,52 @@
-<!-- Make sure that we are enclosed within a tabpane shortcode block -->
-{{ with $.Parent }}
- {{- if ne $.Parent.Name "tabpane" -}}
- {{- errorf "shortcode 'tab' must be used within a 'tabpane' block" -}}
- {{- end -}}
-{{- end -}}
+{{- /* Make sure that we are enclosed within a tabpane shortcode block */ -}}
+{{ with $.Parent -}}
+{{ if ne $.Parent.Name "tabpane" -}}
+ {{ errorf "shortcode 'tab' must be used within a 'tabpane' block" -}}
+ {{ end -}}
+{{ end -}}
-{{ $header := "Tab" }}
-{{ if and (not .IsNamedParams) (.Get 0) }}
- {{ $header = (.Get 0) }}
-{{ else }}
- <!-- Prefill header if not given as named or unnamed parameter -->
- {{ $header = default (printf "Tab %v" ( add $.Ordinal 1)) (.Get "header") }}
-{{ end }}
+{{ $header := "Tab" -}}
+{{ if and (not .IsNamedParams) (.Get 0) -}}
+ {{ $header = (.Get 0) -}}
+{{ else -}}
+ {{/* Prefill header if not given as named or unnamed parameter */ -}}
+ {{ $header = default (printf "Tab %v" ( add $.Ordinal 1)) (.Get "header") -}}
+{{ end -}}
-<!-- store all tab info in dict tab -->
-{{ $tab := dict "header" $header }}
-{{ with $.Get "lang" }}
- {{ $tab = merge $tab (dict "language" ($.Get "lang")) }}
-{{ end }}
-{{ with $.Get "highlight" }}
- {{ $tab = merge $tab (dict "highlight" ($.Get "highlight")) }}
-{{ end }}
-{{ with $.Get "text" }}
- {{ if ne ( printf "%T" . ) "bool" }}
- {{- errorf "shortcode tab: parameter 'text' must be either true or false" -}}
- {{ end }}
- {{ $tab = merge $tab (dict "text" ($.Get "text")) }}
-{{ end }}
-{{ with $.Get "right" }}
- {{ if ne ( printf "%T" . ) "bool" }}
- {{- errorf "shortcode tab: parameter 'right' must be either true or false" -}}
- {{ end }}
- {{ $tab = merge $tab (dict "rightpush" ($.Get "right")) }}
-{{ end }}
-{{ with $.Get "disabled" }}
- {{ if ne ( printf "%T" . ) "bool" }}
- {{- errorf "shortcode tab: parameter 'disabled' must be either true or false" -}}
- {{ end }}
- {{ $tab = merge $tab (dict "disabled" ($.Get "disabled")) }}
-{{ end }}
+{{/* store all tab info in dict tab */ -}}
+{{ $tab := dict "header" $header -}}
+{{ with $.Get "lang" -}}
+ {{ $tab = merge $tab (dict "language" ($.Get "lang")) -}}
+{{ end -}}
+{{ with $.Get "highlight" -}}
+ {{ $tab = merge $tab (dict "highlight" ($.Get "highlight")) -}}
+{{ end -}}
+{{ with $.Get "text" -}}
+ {{ if ne ( printf "%T" . ) "bool" -}}
+ {{ errorf "shortcode tab: parameter 'text' must be either true or false" -}}
+ {{ end -}}
+ {{ $tab = merge $tab (dict "text" ($.Get "text")) -}}
+{{ end -}}
+{{ with $.Get "right" -}}
+ {{ if ne ( printf "%T" . ) "bool" -}}
+ {{ errorf "shortcode tab: parameter 'right' must be either true or false" -}}
+ {{ end -}}
+ {{ $tab = merge $tab (dict "rightpush" ($.Get "right")) -}}
+{{ end -}}
+{{ with $.Get "disabled" -}}
+ {{ if ne ( printf "%T" . ) "bool" -}}
+ {{ errorf "shortcode tab: parameter 'disabled' must be either true or false" -}}
+ {{ end -}}
+ {{ $tab = merge $tab (dict "disabled" ($.Get "disabled")) -}}
+{{ end -}}
-{{ with $.Inner }}
- <!-- Trim any leading and trailing newlines from .Inner, this avoids
- spurious lines during syntax highlighting -->
- {{ $tab = merge $tab (dict "content" $.Inner ) }}
-{{ end }}
+{{ with $.Inner -}}
+ {{/* Trim any leading and trailing newlines from .Inner, this avoids
+ spurious lines during syntax highlighting */ -}}
+ {{ $tab = merge $tab (dict "content" $.Inner) -}}
+{{ end -}}
-<!-- add dict tab to parent's scratchpad -->
-{{ with .Parent }}
- {{- $.Parent.Scratch.SetInMap "tabs" (printf "%02v" $.Ordinal) $tab -}}
-{{ end }}
+{{/* add dict tab to parent's scratchpad */ -}}
+{{ with .Parent -}}
+ {{ $.Parent.Scratch.SetInMap "tabs" (printf "%02v" $.Ordinal) $tab -}}
+{{ end -}}
diff --git a/layouts/shortcodes/tabpane.html b/layouts/shortcodes/tabpane.html
index 4836f62..a25aab1 100644
--- a/layouts/shortcodes/tabpane.html
+++ b/layouts/shortcodes/tabpane.html
@@ -1,130 +1,127 @@
-<!-- Check parameter types -->
-{{ with .Get "langEqualsHeader" }}
-{{ if ne ( printf "%T" . ) "bool" }}
-{{- errorf "shortcode tabpane: parameter 'langEqualsHeader' must be either true or false" -}}
-{{ end }}
-{{ end }}
-
-{{ with .Get "text" }}
-{{ if ne ( printf "%T" . ) "bool" }}
-{{- errorf "shortcode tabpane: parameter 'text' must be either true or false" -}}
-{{ end }}
-{{ end }}
-
-{{ with .Get "persistLang" }}
-{{ if ne ( printf "%T" . ) "bool" }}
-{{- errorf "shortcode tabpane: parameter 'persistLang' must be either true or false" -}}
-{{ end }}
-{{ end }}
-
-{{ with .Get "right" }}
-{{ if ne ( printf "%T" . ) "bool" }}
-{{- errorf "shortcode tabpane: parameter 'right' must be either true or false" -}}
-{{ end }}
-{{ end }}
-
-<!-- Set values given defined within tabpane -->
-{{- $langPane := default "" ($.Get "lang") -}}
-{{- $hloptionsPane := default "" ($.Get "highlight") -}}
-{{- $textPane := default false ($.Get "text") -}}
-{{- $langEqualsHeader := default false ($.Get "langEqualsHeader") -}}
-{{- $persistLang := default true ($.Get "persistLang") -}}
-{{- $rightPane := default false ($.Get "right") -}}
-{{- $disabled := false -}}
-{{- $rightpush := false -}}
-{{- $activeSet := false -}}
-
-<!-- Scratchpad gets populated through call to .Inner -->
+{{/* Check parameter types */ -}}
+{{ with .Get "langEqualsHeader" -}}
+{{ if ne ( printf "%T" . ) "bool" -}}
+{{ errorf "shortcode tabpane: parameter 'langEqualsHeader' must be either true or false" -}}
+{{ end -}}
+{{ end -}}
+
+{{ with .Get "text" -}}
+{{ if ne ( printf "%T" . ) "bool" -}}
+{{ errorf "shortcode tabpane: parameter 'text' must be either true or false" -}}
+{{ end -}}
+{{ end -}}
+
+{{ with .Get "persistLang" -}}
+{{ if ne ( printf "%T" . ) "bool" -}}
+{{ errorf "shortcode tabpane: parameter 'persistLang' must be either true or false" -}}
+{{ end -}}
+{{ end -}}
+
+{{ with .Get "right" -}}
+{{ if ne ( printf "%T" . ) "bool" -}}
+{{ errorf "shortcode tabpane: parameter 'right' must be either true or false" -}}
+{{ end -}}
+{{ end -}}
+
+{{/* Set values given defined within tabpane */ -}}
+{{ $langPane := default "" ($.Get "lang") -}}
+{{ $hloptionsPane := default "" ($.Get "highlight") -}}
+{{ $textPane := default false ($.Get "text") -}}
+{{ $langEqualsHeader := default false ($.Get "langEqualsHeader") -}}
+{{ $persistLang := default true ($.Get "persistLang") -}}
+{{ $rightPane := default false ($.Get "right") -}}
+{{ $disabled := false -}}
+{{ $rightpush := false -}}
+{{ $activeSet := false -}}
+{{- /* Scratchpad gets populated through call to .Inner */ -}}
{{- .Inner -}}
<ul class="nav nav-tabs{{ if $rightPane }} justify-content-end{{ end }}" id="tabs-{{- $.Ordinal -}}" role="tablist">
- {{- range $index, $element := $.Scratch.Get "tabs" -}}
-
- {{- $lang := $langPane -}}
- {{- if $langEqualsHeader -}}
- {{- $lang = $element.header -}}
- {{end}}
- {{- with $element.language -}}
- {{- $lang = $element.language -}}
- {{- end -}}
-
- {{- $disabled := false -}}
- {{- with $element.disabled -}}
- {{- $disabled = . }}
- {{- end -}}
-
- {{- $rightpush := false -}}
- {{- with $element.rightpush -}}
- {{- $rightpush = . }}
- {{- end -}}
-
- <!-- Replace space and +, not valid for css selectors -->
- {{- $lang := replaceRE "[\\s+]" "-" $lang -}}
-
- <li class="nav-item{{ if $rightpush }} ml-auto{{ end }}">
- <!-- Generate the IDs for the <a> and the <div> elements -->
- {{- $tabid := printf "tabs-%02v-%v-tab" $.Ordinal $index | anchorize -}}
- {{- $entryid := printf "tabs-%02v-%v" $.Ordinal $index | anchorize -}}
+ {{ range $index, $element := $.Scratch.Get "tabs" -}}
+
+ {{ $lang := $langPane -}}
+ {{ if $langEqualsHeader -}}
+ {{ $lang = $element.header -}}
+ {{ end -}}
+ {{ with $element.language -}}
+ {{ $lang = $element.language -}}
+ {{ end -}}
+
+ {{ $disabled := false -}}
+ {{ with $element.disabled -}}
+ {{ $disabled = . -}}
+ {{ end -}}
+
+ {{ $rightpush := false -}}
+ {{ with $element.rightpush -}}
+ {{ $rightpush = . -}}
+ {{ end -}}
+
+ {{/* Replace space and +, not valid for css selectors */ -}}
+ {{ $lang := replaceRE "[\\s+]" "-" $lang -}}
+ <li class="nav-item{{ if $rightpush }} ml-auto{{ end -}}">
+ {{/* Generate the IDs for the <a> and the <div> elements */ -}}
+ {{ $tabid := printf "tabs-%02v-%v-tab" $.Ordinal $index | anchorize -}}
+ {{ $entryid := printf "tabs-%02v-%v" $.Ordinal $index | anchorize -}}
<a class="nav-link{{ if and ( not $activeSet ) ( not $disabled ) }} active{{ end }}{{ if $disabled }} disabled{{ end }}{{ if ne $lang "" }}{{ if $persistLang }} persistLang-{{- $lang -}}{{ end }}{{ end }}"
- id="{{- $tabid -}}" data-toggle="tab" href="#{{ $entryid }}" role="tab"
- {{ if ne $lang "" }}{{- if $persistLang -}}onclick="persistLang({{- $lang -}});"{{end}}{{end}}
- aria-controls="{{- $entryid -}}" aria-selected="{{- and ( not $activeSet ) ( not $disabled ) "true" "false" -}}">
- {{- index . "header" | markdownify -}}
+ id="{{ $tabid }}" data-toggle="tab" href="#{{ $entryid }}" role="tab"
+ {{ if ne $lang "" }}{{ if $persistLang }}onclick="persistLang({{ $lang }});"{{ end }}{{ end -}}
+ aria-controls="{{- $entryid -}}" aria-selected="{{- and ( not $activeSet ) ( not $disabled ) "true" "false" -}}">
+ {{ index . "header" | markdownify }}
</a>
</li>
- {{ if not $disabled }}
- {{ $activeSet = true }}
- {{ end }}
+ {{- if not $disabled -}}
+ {{ $activeSet = true -}}
+ {{ end -}}
- {{- end -}}
+ {{- end }}
</ul>
-{{ $activeSet = false }}
+{{ $activeSet = false -}}
-<!-- Inner content -->
-<div class="tab-content" id="tabs-{{- $.Ordinal -}}-content">
+{{/* Inner content */ -}}
+<div class="tab-content" id="tabs-{{ $.Ordinal }}-content">
{{- range $index, $element := $.Scratch.Get "tabs" -}}
- {{- $lang := $langPane -}}
- {{- if $langEqualsHeader -}}
- {{- $lang = $element.header -}}
- {{end}}
- {{- with $element.language -}}
- {{- $lang = $element.language -}}
- {{- end -}}
-
- {{- $disabled := false -}}
- {{- with $element.disabled -}}
- {{- $disabled = . }}
- {{- end -}}
-
- {{- $hloptions := $hloptionsPane -}}
- {{- with $element.highlight -}}
- {{- $hloptions = $element.highlight -}}
- {{- end -}}
-
- {{- $text := $textPane -}}
- {{- with $element.text -}}
- {{- $text = . }}
- {{- end -}}
-
- {{- $tabid := printf "tabs-%02v-%v-tab" $.Ordinal $index | anchorize -}}
- {{- $entryid := printf "tabs-%02v-%v" $.Ordinal $index | anchorize -}}
-
+ {{ $lang := $langPane -}}
+ {{ if $langEqualsHeader -}}
+ {{ $lang = $element.header -}}
+ {{ end -}}
+ {{ with $element.language -}}
+ {{ $lang = $element.language -}}
+ {{ end -}}
+
+ {{ $disabled := false -}}
+ {{ with $element.disabled -}}
+ {{ $disabled = . -}}
+ {{ end -}}
+
+ {{ $hloptions := $hloptionsPane -}}
+ {{ with $element.highlight -}}
+ {{ $hloptions = $element.highlight -}}
+ {{ end -}}
+
+ {{ $text := $textPane -}}
+ {{ with $element.text -}}
+ {{ $text = . }}
+ {{ end -}}
+
+ {{ $tabid := printf "tabs-%02v-%v-tab" $.Ordinal $index | anchorize -}}
+ {{ $entryid := printf "tabs-%02v-%v" $.Ordinal $index | anchorize }}
<div class="{{ if $text }}tab-body {{end}}tab-pane fade{{ if and ( not $activeSet ) ( not $disabled ) }} show active{{ end }}"
id="{{ $entryid }}" role="tabpanel" aria-labelled-by="{{ $tabid }}">
- {{ if $text }}
- {{- index . "content" -}}
- {{- else -}}
- {{- highlight (trim (index . "content") "\n") $lang $hloptions -}}
- {{- end -}}
+ {{ if $text -}}
+ {{ index . "content" -}}
+ {{ else -}}
+ {{ highlight (trim (index . "content") "\n") $lang $hloptions -}}
+ {{ end }}
</div>
- {{ if not $disabled }}
- {{ $activeSet = true }}
- {{ end }}
+ {{- if not $disabled -}}
+ {{ $activeSet = true -}}
+ {{ end -}}
- {{ end }}
+ {{- end }}
</div>