mirror of https://github.com/theNewDynamic/gohugo-theme-ananke.git

Patrick Kollitsch
07.44.2026 c31ff8582907a3d06dcd524980895c7860befb99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
{{- /*
  Code block render hook.
 
  Wraps Hugo's standard syntax-highlighted output in a container with a
  copy-to-clipboard button. Highlighting still honours the site's
  [markup.highlight] configuration because we delegate to
  transform.HighlightCodeBlock, which reads both the per-fence options and the
  global config.
 
  Progressive enhancement: the button is rendered with the `hidden` attribute
  and is only revealed by site-scripts.html when JavaScript runs, so sites
  without JS show no inert button. The copy behaviour itself is wired by the
  same script (a single delegated listener).
 
  Disable site-wide with `[ananke] copy_code = false` (see params.toml).
*/ -}}
{{- $result := transform.HighlightCodeBlock . -}}
{{- if eq false site.Params.ananke.copy_code -}}
  {{- $result.Wrapped -}}
{{- else -}}
  <div class="code-block">
    <button class="code-copy" type="button" hidden aria-label="Copy code to clipboard">
      <span class="code-copy-label" aria-hidden="true">Copy</span>
    </button>
    {{ $result.Wrapped }}
  </div>
{{- end -}}