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

Patrick Kollitsch
yesterday 8c3143a220e69752c9434b15309c75145b99b896
refs
author Patrick Kollitsch <davidsneighbourdev+gh@gmail.com>
Saturday, June 6, 2026 14:27 +0200
committer Patrick Kollitsch <davidsneighbourdev+gh@gmail.com>
Saturday, June 6, 2026 14:27 +0200
commit8c3143a220e69752c9434b15309c75145b99b896
tree 573b399a5afe395305425ccbb712f21fbc446295 tree | zip | gz
parent da071934f9c4fa85c9c8ef0102b3af6c2759a0c2 view | diff
feat: copy-to-clipboard buttons for code blocks (#986)

Add a code block render hook (layouts/_markup/render-codeblock.html) that
wraps highlighted output in a .code-block container with a .code-copy
button, plus the copy behaviour in site-scripts.html and button styles in
_code.css.

Progressive enhancement: buttons are rendered with the hidden attribute
and only revealed once JavaScript runs, so sites without JS show no inert
button and code stays selectable. A single delegated listener handles
every block; copy uses the async Clipboard API with an execCommand
fallback for non-secure contexts. Styling is reduced-motion aware, has
focus-visible reveal for keyboard users, and a touch-device fallback.

Reuses the same class names (.code-block/.code-copy/.is-copied) as the
documentation site's existing override so the two remain drop-in
compatible. Toggle with [ananke] copy_code (default true).

Part of #985
Closes #986

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
3 files modified
1 files added
165 ■■■■■ changed files
assets/ananke/css/_code.css 60 ●●●●● diff | view | raw | blame | history
config/_default/params.toml 1 ●●●● diff | view | raw | blame | history
layouts/_markup/render-codeblock.html 27 ●●●●● diff | view | raw | blame | history
layouts/_partials/site-scripts.html 77 ●●●●● diff | view | raw | blame | history