2023-07-27 14:14:55 +00:00
|
|
|
{{- $page := .page }}
|
|
|
|
{{- if and (not $page) .context }}
|
|
|
|
{{- $page = .context }}
|
2024-09-29 21:54:17 +00:00
|
|
|
{{- warnf "%q: DEPRECATED parameter 'context' for shortcode 'highlight' found, use 'page' instead; see https://mcshelby.github.io/hugo-theme-relearn/introduction/releasenotes/5/#5-18-0" $page.File.Filename }}
|
2023-07-27 14:14:55 +00:00
|
|
|
{{- end }}
|
2023-06-21 23:22:08 +00:00
|
|
|
{{- $attributes := dict }}
|
|
|
|
{{- $otherAttributes := dict }}
|
|
|
|
{{- $content := "" }}
|
|
|
|
{{- $options := dict }}
|
|
|
|
{{- $otherOptions := dict }}
|
|
|
|
{{- $type := "" }}
|
|
|
|
{{- range $k, $v := . }}
|
|
|
|
{{- if eq $k "context" }}
|
2023-08-26 10:08:34 +00:00
|
|
|
{{- else if eq $k "page" }}
|
2023-06-21 23:22:08 +00:00
|
|
|
{{- else if eq $k "attributes" }}
|
|
|
|
{{- $attributes = $v }}
|
|
|
|
{{- else if eq $k "content" }}
|
|
|
|
{{- $content = trim $v "\n\r" }}
|
|
|
|
{{- else if eq $k "options" }}
|
2023-06-22 15:34:04 +00:00
|
|
|
{{- if eq (printf "%T" $v) "string" }}
|
|
|
|
{{- range (split $v ",") }}
|
|
|
|
{{- $pair := split . "=" }}
|
|
|
|
{{- $options = $options | merge (dict (index $pair 0) (index $pair 1)) }}
|
|
|
|
{{- end }}
|
|
|
|
{{- else }}
|
|
|
|
{{- $options = $v }}
|
|
|
|
{{- end }}
|
2023-06-21 23:22:08 +00:00
|
|
|
{{- else if eq $k "type" }}
|
|
|
|
{{- $type = $v }}
|
2023-08-12 22:58:41 +00:00
|
|
|
{{- else if eq $k "title" }}
|
|
|
|
{{- $otherAttributes = $otherAttributes | merge (dict $k $v) }}
|
2023-06-21 23:22:08 +00:00
|
|
|
{{- else if eq $k "wrap" }}
|
|
|
|
{{- $otherAttributes = $otherAttributes | merge (dict $k $v) }}
|
|
|
|
{{- else }}
|
|
|
|
{{- $otherOptions = $otherOptions | merge (dict $k $v) }}
|
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
2024-03-11 17:56:18 +00:00
|
|
|
|
|
|
|
{{- /* separate attributes from options */}}
|
|
|
|
{{- $hl_inline := false }}
|
|
|
|
{{- if and (isset $page.Params "markup") (isset $page.Params.markup "highlight") (isset $page.Params.markup.highlight "hl_inline") }}
|
|
|
|
{{- $hl_inline = $page.Params.markup.highlight.hl_inline }}
|
|
|
|
{{- end }}
|
2023-06-21 23:22:08 +00:00
|
|
|
{{- $options = $options | merge $otherOptions }}
|
|
|
|
{{- $otherOptions := dict }}
|
|
|
|
{{- range $k, $v := $options }}
|
2024-03-11 17:56:18 +00:00
|
|
|
{{- if eq $k "hl_inline" }}
|
|
|
|
{{- $hl_inline = $v }}
|
|
|
|
{{- $otherOptions = (dict $k $v) | merge $otherOptions }}
|
|
|
|
{{- else if eq $k "title" }}
|
2023-08-12 22:58:41 +00:00
|
|
|
{{- $otherAttributes = (dict $k $v) | merge $otherAttributes }}
|
|
|
|
{{- else if eq $k "wrap" }}
|
2023-06-21 23:22:08 +00:00
|
|
|
{{- $otherAttributes = (dict $k $v) | merge $otherAttributes }}
|
|
|
|
{{- else }}
|
2023-06-22 15:34:04 +00:00
|
|
|
{{- $otherOptions = (dict $k $v) | merge $otherOptions }}
|
2023-06-21 23:22:08 +00:00
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
|
|
|
{{- $options = $otherOptions }}
|
2024-03-11 17:56:18 +00:00
|
|
|
|
2024-03-11 19:45:51 +00:00
|
|
|
{{- /* separate shortcode attributes from rest */}}
|
2023-08-12 22:58:41 +00:00
|
|
|
{{- $title := "" }}
|
2023-06-21 23:22:08 +00:00
|
|
|
{{- $wrap := true }}
|
2023-07-27 14:14:55 +00:00
|
|
|
{{- if isset $page.Site.Params "highlightwrap" }}
|
|
|
|
{{- $wrap = $page.Site.Params.highlightWrap }}
|
2023-06-21 23:22:08 +00:00
|
|
|
{{- end }}
|
2023-07-27 14:14:55 +00:00
|
|
|
{{- if isset $page.Params "highlightwrap" }}
|
|
|
|
{{- $wrap = $page.Params.highlightWrap }}
|
2023-06-21 23:22:08 +00:00
|
|
|
{{- end }}
|
2024-03-11 17:56:18 +00:00
|
|
|
{{- $attributes = $attributes | merge $otherAttributes }}
|
|
|
|
{{- $otherAttributes := dict }}
|
2023-06-21 23:22:08 +00:00
|
|
|
{{- range $k, $v := $attributes }}
|
2023-08-12 22:58:41 +00:00
|
|
|
{{- if eq $k "title" }}
|
|
|
|
{{- $title = $v }}
|
|
|
|
{{- else if eq $k "wrap" }}
|
2023-06-21 23:22:08 +00:00
|
|
|
{{- $wrap = $v }}
|
2024-03-11 17:56:18 +00:00
|
|
|
{{- else }}
|
|
|
|
{{- $otherAttributes = (dict $k $v) | merge $otherAttributes }}
|
2023-06-21 23:22:08 +00:00
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
2024-03-11 17:56:18 +00:00
|
|
|
{{- $attributes = $otherAttributes }}
|
2023-06-21 23:22:08 +00:00
|
|
|
{{- if eq (printf "%T" $wrap) "string" }}
|
|
|
|
{{- $wrap = (eq $wrap "true") }}
|
|
|
|
{{- end }}
|
2024-03-11 17:56:18 +00:00
|
|
|
|
2024-03-11 21:08:16 +00:00
|
|
|
{{- /* enrich attributes */}}
|
2024-03-11 17:56:18 +00:00
|
|
|
{{- $attributes = merge $attributes (dict "class" (delimit (append (index $attributes "class" | default slice) "highlight" slice) " ")) }}
|
2023-06-21 23:22:08 +00:00
|
|
|
{{- if $wrap }}
|
2024-03-11 17:56:18 +00:00
|
|
|
{{- $attributes = merge $options (dict "class" (delimit (append (index $attributes "class" | default slice) "wrap-code" slice) " ")) }}
|
2023-06-21 23:22:08 +00:00
|
|
|
{{- end }}
|
2024-03-11 17:56:18 +00:00
|
|
|
|
|
|
|
{{- /* print da shtuff */}}
|
|
|
|
{{- $div := slice }}
|
|
|
|
{{- range $k, $v := $attributes }}
|
|
|
|
{{- if $v }}
|
|
|
|
{{- $div = $div | append (printf "%s=%q" $k $v | safeHTMLAttr) }}
|
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
|
|
|
{{- $content = highlight $content $type $options }}
|
|
|
|
{{- $content = replaceRE "^([\\s\\n\\r]*)(<pre\\s+?[\\s\\S]*)$" "${1}<div class=\"highlight\">${2}</div>" $content }}
|
|
|
|
{{- $content = replaceRE "(class=\")([^\"]*)\"" (printf "%s" (delimit $div " ")) $content 1 }}
|
2023-08-14 08:36:48 +00:00
|
|
|
{{- if and $title (not $hl_inline) }}
|
2024-03-11 17:56:18 +00:00
|
|
|
{{- partial "shortcodes/tab.html" (dict
|
2023-08-12 22:58:41 +00:00
|
|
|
"page" $page
|
|
|
|
"title" $title
|
|
|
|
"content" $content
|
|
|
|
)}}
|
|
|
|
{{- else }}
|
|
|
|
{{- $content | safeHTML }}
|
2024-09-05 18:02:38 +00:00
|
|
|
{{- if and (not $hl_inline) (not (hasSuffix $content "\n")) }}
|
|
|
|
{{ end }}
|
2023-08-12 22:58:41 +00:00
|
|
|
{{- end }}
|