mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-12-24 22:58:45 +00:00
7e073f9681
as it may happen to be called with string options in case of documented `partial (compat)` mode
67 lines
No EOL
2.2 KiB
HTML
67 lines
No EOL
2.2 KiB
HTML
{{- $context := .context }}
|
|
{{- $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" }}
|
|
{{- 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 }}
|
|
{{- 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 }}
|
|
{{- $otherOptions = (dict $k $v) | merge $otherOptions }}
|
|
{{- 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 }}
|
|
{{- if isset $context.Site.Params "highlightwrap" }}
|
|
{{- $wrap = $context.Site.Params.highlightWrap }}
|
|
{{- end }}
|
|
{{- if isset $context.Params "highlightwrap" }}
|
|
{{- $wrap = $context.Params.highlightWrap }}
|
|
{{- 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 }} |