diff --git a/layouts/shortcodes/code-toggle.html b/layouts/shortcodes/code-toggle.html index 113d85a1f..b4cfaaa20 100644 --- a/layouts/shortcodes/code-toggle.html +++ b/layouts/shortcodes/code-toggle.html @@ -1,87 +1,66 @@ {{- /* Renders syntax-highlighted configuration data in JSON, TOML, and YAML formats. -@param {string} config - Section of site.Data.docs.config to render. - Example: markup.highlight - Default: "" -@param {bool} copy - Display a copy button. - Default: true -@param {string} file - File name to display above the rendered code. - Default: "" -@param {bool} fm - Does Inner represent front matter? - Default: false -@param {string} Inner - Content between opening and closing shortcode tags. - Default: "" -@param {bool} skipHeader - Omit top level key(s) when rendering a section of site.Data.docs.config. - Default: false +@param {string} [config] The section of site.Data.docs.config to render. +@param {bool} [copy=true] If true, display a copy to clipboard button. +@param {string} [file] The file name to display above the rendered code. +@param {bool} [fm=false] If true, render the code as front matter. +@param {bool} [skipHeader=false] If false, omit top level key(s) when rendering a section of site.Data.docs.config. + @returns {template.HTML} -*/ -}} +*/}} -{{- /* Initialize. */ -}} -{{- $config := "" -}} -{{- $copy := true -}} -{{- $file := "" -}} -{{- $fm := false -}} -{{- $skipHeader := false -}} +{{- /* Initialize. */}} +{{- $config := "" }} +{{- $copy := true }} +{{- $file := "" }} +{{- $fm := false }} +{{- $skipHeader := false }} -{{- /* Get parameters, defend against string booleans. */ -}} -{{- if .Params -}} - {{- $config = .Get "config" -}} - {{- $file = .Get "file" -}} - {{- if (isset .Params "copy") -}} - {{- if in (slice true "true") (.Get "copy") -}} - {{- $copy = true -}} - {{- else -}} - {{- $copy = false -}} - {{- end -}} - {{- end -}} - {{- if (isset .Params "fm") -}} - {{- if in (slice true "true") (.Get "fm") -}} - {{- $fm = true -}} - {{- else -}} - {{- $fm = false -}} - {{- end -}} - {{- end -}} - {{- if (isset .Params "skipHeader") -}} - {{- if in (slice true "true") (.Get "skipHeader") -}} - {{- $skipHeader = true -}} - {{- else -}} - {{- $skipHeader = false -}} - {{- end -}} - {{- end -}} -{{- end -}} +{{- /* Get parameters. */}} +{{- $config = .Get "config" }} +{{- $file = .Get "file" }} +{{- if in (slice "false" false 0) (.Get "copy") }} + {{- $copy = false }} +{{- else if in (slice "true" true 1) (.Get "copy")}} + {{- $copy = true }} +{{- end }} +{{- if in (slice "false" false 0) (.Get "fm") }} + {{- $fm = false }} +{{- else if in (slice "true" true 1) (.Get "fm")}} + {{- $fm = true }} +{{- end }} +{{- if in (slice "false" false 0) (.Get "skipHeader") }} + {{- $skipHeader = false }} +{{- else if in (slice "true" true 1) (.Get "skipHeader")}} + {{- $skipHeader = true }} +{{- end }} -{{- /* Define constants. */ -}} -{{- $delimiters := dict "toml" "+++" "yaml" "---" -}} -{{- $langs := slice "yaml" "toml" "json" -}} -{{- $placeHolder := "#-hugo-placeholder-#" -}} +{{- /* Define constants. */}} +{{- $delimiters := dict "toml" "+++" "yaml" "---" }} +{{- $langs := slice "yaml" "toml" "json" }} +{{- $placeHolder := "#-hugo-placeholder-#" }} -{{- /* Render. */ -}} -{{- $code := "" -}} -{{- with $config -}} - {{- $file = $file | default "config" -}} - {{- $sections := (split . ".") -}} - {{- $configSection := index $.Site.Data.docs.config $sections -}} - {{- $code = dict $sections $configSection -}} - {{- if $skipHeader -}} - {{- $code = $configSection -}} - {{- end -}} -{{- else -}} - {{- $code = $.Inner -}} +{{- /* Render. */}} +{{- $code := "" }} +{{- with $config }} + {{- $file = $file | default "config" }} + {{- $sections := (split . ".") }} + {{- $configSection := index $.Site.Data.docs.config $sections }} + {{- $code = dict $sections $configSection }} + {{- if $skipHeader }} + {{- $code = $configSection }} + {{- end }} +{{- else }} + {{- $code = $.Inner }} {{- end }}