diff --git a/assets/scss/shortcodes/tabbed-pane.scss b/assets/scss/shortcodes/tabbed-pane.scss index f63b50d064..65096aee6e 100644 --- a/assets/scss/shortcodes/tabbed-pane.scss +++ b/assets/scss/shortcodes/tabbed-pane.scss @@ -1,14 +1,17 @@ .tab-content { - .highlight { - margin: 0rem 0 2rem 0; + .tab-pane { + pre { + margin: 0rem 0 0rem 0; + } } } + .tab-content { .tab-pane { .highlight { - margin: 0rem 0 0rem 0; - border: none; - max-width: 100%; + margin: 0rem 0 0rem 0; + border: none; + max-width: 100%; } margin-top: 0rem; margin-bottom: 1.5rem; @@ -16,7 +19,7 @@ border-left: 1px solid rgba(0, 0, 0, 0.125); border-right: 1px solid rgba(0, 0, 0, 0.125); border-bottom: 1px solid rgba(0, 0, 0, 0.125); - } + } } .tab-body { @@ -27,10 +30,9 @@ padding: 1.5rem; @each $color, $value in $theme-colors { - &-#{$color} { - - border-style: solid; - border-color: $value; - } + &-#{$color} { + border-style: solid; + border-color: $value; + } } } diff --git a/layouts/shortcodes/readfile.html b/layouts/shortcodes/readfile.html index f97541c598..7d27caa35a 100644 --- a/layouts/shortcodes/readfile.html +++ b/layouts/shortcodes/readfile.html @@ -1,3 +1,8 @@ +{{/* Store ordinal, to be retrieved by parent element */}} +{{ if ge hugo.Version "0.93.0" }} + {{ .Page.Store.Add "Ordinal" 1 }} +{{ end }} + {{/* Handle the "file" named parameter or a single unnamed parameter as the file path */}} {{ if .IsNamedParams }} @@ -24,10 +29,10 @@ {{ if fileExists ($.Scratch.Get "filepath") }} {{ if eq (.Get "code") "true" }} - {{- highlight ($.Scratch.Get "filepath" | readFile | htmlUnescape | + {{- highlight ($.Scratch.Get "filepath" | readFile | htmlUnescape | safeHTML ) (.Get "lang") "" -}} {{ else }} - {{- $.Scratch.Get "filepath" | readFile | .Page.RenderString | htmlUnescape | safeHTML -}} + {{- $.Scratch.Get "filepath" | os.ReadFile | .Page.RenderString | htmlUnescape | safeHTML -}} {{ end }} {{ else }} diff --git a/layouts/shortcodes/tab.html b/layouts/shortcodes/tab.html index c947ac48c0..8ec7e09d5e 100644 --- a/layouts/shortcodes/tab.html +++ b/layouts/shortcodes/tab.html @@ -1,52 +1,52 @@ - -{{ 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 }} - - {{ $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 -}} - -{{ $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 }} - - {{ $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 -}} - -{{ 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 4836f62675..1c38affdc7 100644 --- a/layouts/shortcodes/tabpane.html +++ b/layouts/shortcodes/tabpane.html @@ -1,130 +1,152 @@ - -{{ 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 }} - - -{{- $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 -}} - - +{{/* 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") -}} +{{ $activeSet := false -}} +{{- /* Scratchpad gets populated through call to .Inner */ -}} {{- .Inner -}} -