github.com/choria-io/go-choria@v0.28.1-0.20240416190746-b3bf9c7d5a45/docs/themes/hugo-theme-relearn/layouts/partials/shortcodes/highlight.html (about)

     1  {{- $page := .page }}
     2  {{- if and (not $page) .context }}
     3    {{- $page = .context }}
     4    {{- warnf "%q: DEPRECATED parameter 'context' for shortcode 'highlight' found, use 'page' instead; see https://mcshelby.github.io/hugo-theme-relearn/basics/migration#5180" $page.File.Filename }}
     5  {{- end }}
     6  {{- $attributes := dict }}
     7  {{- $otherAttributes := dict }}
     8  {{- $content := "" }}
     9  {{- $options := dict }}
    10  {{- $otherOptions := dict }}
    11  {{- $type := "" }}
    12  {{- range $k, $v := . }}
    13    {{- if eq $k "context" }}
    14    {{- else if eq $k "page" }}
    15    {{- else if eq $k "attributes" }}
    16      {{- $attributes = $v }}
    17    {{- else if eq $k "content" }}
    18      {{- $content = trim $v "\n\r" }}
    19    {{- else if eq $k "options" }}
    20      {{- if eq (printf "%T" $v) "string" }}
    21        {{- range (split $v ",") }}
    22          {{- $pair := split . "=" }}
    23          {{- $options = $options | merge (dict (index $pair 0) (index $pair 1)) }}
    24        {{- end }}
    25      {{- else }}
    26        {{- $options = $v }}
    27      {{- end }}
    28    {{- else if eq $k "type" }}
    29      {{- $type = $v }}
    30    {{- else if eq $k "title" }}
    31      {{- $otherAttributes = $otherAttributes | merge (dict $k $v) }}
    32    {{- else if eq $k "wrap" }}
    33      {{- $otherAttributes = $otherAttributes | merge (dict $k $v) }}
    34    {{- else }}
    35      {{- $otherOptions = $otherOptions | merge (dict $k $v) }}
    36    {{- end }}
    37  {{- end }}
    38  
    39  {{- /* separate attributes from options */}}
    40  {{- $hl_inline := false }}
    41  {{- if and (isset $page.Params "markup") (isset $page.Params.markup "highlight") (isset $page.Params.markup.highlight "hl_inline") }}
    42    {{- $hl_inline = $page.Params.markup.highlight.hl_inline }}
    43  {{- end }}
    44  {{- $options = $options | merge $otherOptions }}
    45  {{- $otherOptions := dict }}
    46  {{- range $k, $v := $options }}
    47    {{- if eq $k "hl_inline" }}
    48      {{- $hl_inline = $v }}
    49      {{- $otherOptions = (dict $k $v) | merge $otherOptions }}
    50    {{- else if eq $k "title" }}
    51      {{- $otherAttributes = (dict $k $v) | merge $otherAttributes }}
    52    {{- else if eq $k "wrap" }}
    53      {{- $otherAttributes = (dict $k $v) | merge $otherAttributes }}
    54    {{- else }}
    55      {{- $otherOptions = (dict $k $v) | merge $otherOptions }}
    56    {{- end }}
    57  {{- end }}
    58  {{- $options = $otherOptions }}
    59  
    60  {{- /* separate shortcode attributes from rest */}}
    61  {{- $title := "" }}
    62  {{- $wrap := true }}
    63  {{- if isset $page.Site.Params "highlightwrap" }}
    64    {{- $wrap = $page.Site.Params.highlightWrap  }}
    65  {{- end }}
    66  {{- if isset $page.Params "highlightwrap" }}
    67    {{- $wrap = $page.Params.highlightWrap }}
    68  {{- end }}
    69  {{- $attributes = $attributes | merge $otherAttributes }}
    70  {{- $otherAttributes := dict }}
    71  {{- range $k, $v := $attributes }}
    72    {{- if eq $k "title" }}
    73      {{- $title = $v }}
    74    {{- else if eq $k "wrap" }}
    75      {{- $wrap = $v }}
    76    {{- else }}
    77      {{- $otherAttributes = (dict $k $v) | merge $otherAttributes }}
    78    {{- end }}
    79  {{- end }}
    80  {{- $attributes = $otherAttributes }}
    81  {{- if eq (printf "%T" $wrap) "string" }}
    82    {{- $wrap = (eq $wrap "true") }}
    83  {{- end }}
    84  
    85  {{- /* enrich attributes */}}
    86  {{- $attributes = merge $attributes (dict "class" (delimit (append (index $attributes "class" | default slice) "highlight" slice) " ")) }}
    87  {{- if $wrap }}
    88    {{- $attributes = merge $options (dict "class" (delimit (append (index $attributes "class" | default slice) "wrap-code" slice) " ")) }}
    89  {{- end }}
    90  
    91  {{- /* print da shtuff */}}
    92  {{- $div := slice }}
    93  {{- range $k, $v := $attributes }}
    94    {{- if $v }}
    95      {{- $div = $div | append (printf "%s=%q" $k $v | safeHTMLAttr) }}
    96    {{- end }}
    97  {{- end }}
    98  {{- $content = highlight $content $type $options }}
    99  {{- $content = replaceRE "^([\\s\\n\\r]*)(<pre\\s+?[\\s\\S]*)$" "${1}<div class=\"highlight\">${2}</div>" $content }}
   100  {{- $content = replaceRE "(class=\")([^\"]*)\"" (printf "%s" (delimit $div " ")) $content 1 }}
   101  {{- if and $title (not $hl_inline) }}
   102    {{- partial "shortcodes/tab.html" (dict
   103      "page"  $page
   104      "title" $title
   105      "content" $content
   106    )}}
   107  {{- else }}
   108    {{- $content | safeHTML }}
   109  {{- end }}