2023-07-27 14:14:55 +00:00
|
|
|
{{- $page := .page }}
|
|
|
|
{{- if and (not $page) .context }}
|
|
|
|
{{- $page = .context }}
|
|
|
|
{{- warnf "%q: DEPRECATED parameter 'context' for shortcode 'highlight' found, use 'page' instead; see https://mcshelby.github.io/hugo-theme-relearn/basics/migration/#5180-2023-07-27" $page.File.Path }}
|
|
|
|
{{- 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" }}
|
|
|
|
{{- 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 }}
|
|
|
|
{{- else if eq $k "wrap" }}
|
|
|
|
{{- $otherAttributes = $otherAttributes | merge (dict $k $v) }}
|
|
|
|
{{- else }}
|
|
|
|
{{- $otherOptions = $otherOptions | merge (dict $k $v) }}
|
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
|
|
|
{{- $options = $options | merge $otherOptions }}
|
|
|
|
{{- $otherOptions := dict }}
|
|
|
|
{{- range $k, $v := $options }}
|
|
|
|
{{- if eq $k "wrap" }}
|
|
|
|
{{- $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 }}
|
|
|
|
{{- $attributes = $attributes | merge $otherAttributes }}
|
|
|
|
{{- $params := slice }}
|
|
|
|
{{- range $k, $v := $options }}
|
|
|
|
{{- $params = $params | append (printf "%s=%s" $k $v) }}
|
|
|
|
{{- end }}
|
|
|
|
{{- $params = delimit $params ", " }}
|
|
|
|
{{- $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 }}
|
|
|
|
{{- range $k, $v := $attributes }}
|
|
|
|
{{- if eq $k "wrap" }}
|
|
|
|
{{- $wrap = $v }}
|
|
|
|
{{- end }}
|
|
|
|
{{- end }}
|
|
|
|
{{- if eq (printf "%T" $wrap) "string" }}
|
|
|
|
{{- $wrap = (eq $wrap "true") }}
|
|
|
|
{{- end }}
|
|
|
|
{{- $content = highlight $content $type $params }}
|
|
|
|
{{- $content = replaceRE "^([\\s\\n\\r]*)(<pre\\s+?[\\s\\S]*)$" "${1}<div class=\"highlight\">${2}</div>" $content }}
|
|
|
|
{{- if $wrap }}
|
|
|
|
{{- $content = replaceRE "^([\\s\\n\\r]*<div\\s+class=\")" "${1}wrap-code " $content 1 }}
|
|
|
|
{{- end }}
|
|
|
|
{{- $content | safeHTML }}
|