diff --git a/layouts/shortcodes/tabpane.html b/layouts/shortcodes/tabpane.html index c553383db0..d6689f2d65 100644 --- a/layouts/shortcodes/tabpane.html +++ b/layouts/shortcodes/tabpane.html @@ -11,9 +11,20 @@ {{ end -}} {{ end -}} -{{ with .Get "persistLang" -}} - {{ if ne ( printf "%T" . ) "bool" -}} - {{ errorf "Shortcode %q: boolean value expected for parameter %q, but got %s. Error position: %s" $.Name "persistLang" (printf "%T" .) $.Position -}} +{{ $_persistLang := .Get "persistLang" -}} +{{ if and (ne $_persistLang nil) (ne $_persistLang "") -}} + {{ if ne ( printf "%T" $_persistLang ) "bool" -}} + {{ errorf "Shortcode %q: boolean value expected for parameter %q, but got %s. Error position: %s" $.Name "persistLang" (printf "%T" $_persistLang) $.Position -}} + {{ else -}} + {{ warnf "Shortcode %q parameter `persistLang` is deprecated, use `persist` instead: %s" $.Name $.Position -}} + {{ end -}} +{{ end -}} + +{{ $_persist := .Get "persist" -}} +{{ with $_persist -}} + {{ $matched := findRE "^(header|lang|none)$" . -}} + {{ if not $matched -}} + {{ errorf "Shortcode %q: parameter %q should be one of 'header', 'lang', or 'none'; but got %s. Error position: %s" $.Name "persist" $_persist $.Position -}} {{ end -}} {{ end -}} @@ -28,15 +39,17 @@ {{ $hloptionsPane := default "" ($.Get "highlight") -}} {{ $textPane := default false ($.Get "text") -}} {{ $langEqualsHeader := default false ($.Get "langEqualsHeader") -}} -{{ $persistLang := default true ($.Get "persistLang") -}} +{{ $deprecatedPersistLang := $_persistLang | default true -}} +{{ $persistKeyKind := $_persist | default (cond (eq $langPane "") "lang" "header") -}} +{{ $persistTab := and $deprecatedPersistLang (ne $persistKeyKind "none") -}} {{ $rightPane := default false ($.Get "right") -}} {{ $activeSet := false -}} {{- /* Scratchpad gets populated through call to .Inner */ -}} {{- .Inner -}} -{{ $langs := slice -}} +{{ $persistKeyList := slice -}} {{ $duplicate := false -}} -{{ $duplicateLang := "" -}} +{{ $duplicateKey := "" -}} {{ $Ordinal := $.Ordinal -}} {{ if ge hugo.Version "0.93.0" -}} @@ -62,14 +75,21 @@ {{ $lang = . -}} {{ end -}} - {{/* Check for duplicate languages */ -}} - {{ if and $persistLang (not $duplicate) -}} - {{ if and (not $disabled) (ne $lang "") -}} - {{ $langs = $langs | append $lang -}} - {{ end -}} - {{ if ne $langs (uniq $langs) -}} + {{ $persistKey := "" -}} + {{ if eq $persistKeyKind "lang" -}} + {{ $persistKey = $lang -}} + {{ else if eq $persistKeyKind "header" -}} + {{ $persistKey = $element.header -}} + {{ end -}} + + {{/* Check for duplicate tab-persistence keys */ -}} + {{ if and $persistTab $persistKey -}} + {{ if in $persistKey $persistKeyList -}} {{ $duplicate = true -}} - {{ $duplicateLang = $lang -}} + {{ $duplicateKey = $persistKey -}} + {{ $persistTab = false -}} + {{ else -}} + {{ $persistKeyList = $persistKeyList | append $persistKey -}} {{ end -}} {{ end -}} @@ -78,16 +98,23 @@ {{ $rightpush = . -}} {{ end -}} - {{/* Replace space and +, not valid for css selectors */ -}} - {{ $lang := replaceRE "[\\s+]" "-" $lang -}} + {{/* Replace by "-" all chars that are not valid in a CSS class name: */ -}} + {{ $persistKey = replaceRE "[^a-zA-Z0-9_-]" "-" $persistKey | lower -}}