Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions website/assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -846,3 +846,21 @@ section{ padding:88px 0; }
font-family:var(--math); font-style:italic; font-size:clamp(60px,14vw,120px);
color:var(--accent); display:block; line-height:.9;
}

/* ---- Copy button for docs code blocks (issue #343) ---- */
.docs-content pre{ position:relative; padding-top:2rem; }
.copy-btn{
position:absolute; top:.5rem; right:.5rem;
padding:.15rem .5rem;
font:500 .75rem/1 var(--grotesk, ui-sans-serif, system-ui, sans-serif);
color:var(--ink-soft, #54607A);
background:var(--paper, #fff);
border:1px solid var(--grid-strong, #C9D6EE);
border-radius:4px;
cursor:pointer;
opacity:0;
transition:opacity .15s ease;
}
.docs-content pre:hover .copy-btn,
.copy-btn:focus-visible{ opacity:1; }
.copy-btn.copied{ color:var(--green, #1F8A5F); border-color:var(--green, #1F8A5F); }
34 changes: 34 additions & 0 deletions website/assets/js/copy-code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copy-to-clipboard button for docs code blocks (issue #343).
// Injects a "Copy" button into every <pre> inside the docs content area.
// The button is hidden until the parent <pre> is hovered or focused, and
// flashes a "Copied!" confirmation after a successful write.
document.addEventListener("DOMContentLoaded", () => {
const blocks = document.querySelectorAll(".docs-content pre");
blocks.forEach((pre) => {
if (pre.querySelector(".copy-btn")) return;

const button = document.createElement("button");
button.type = "button";
button.className = "copy-btn";
button.setAttribute("aria-label", "Copy code to clipboard");
button.textContent = "Copy";

button.addEventListener("click", async () => {
const codeEl = pre.querySelector("code");
const text = codeEl ? codeEl.textContent : pre.textContent;
try {
await navigator.clipboard.writeText(text);
button.textContent = "Copied!";
button.classList.add("copied");
} catch {
button.textContent = "Failed";
}
window.setTimeout(() => {
button.textContent = "Copy";
button.classList.remove("copied");
}, 1500);
});

pre.appendChild(button);
});
});
8 changes: 8 additions & 0 deletions website/layouts/doc/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@ <h1>{{ .Title }}</h1>
</article>
</div>
{{ end }}

{{ define "scripts" }}
{{ $copyJs := resources.Get "js/copy-code.js" }}
{{ if hugo.IsProduction }}
{{ $copyJs = $copyJs | js.Build | minify | fingerprint }}
{{ end }}
<script src="{{ $copyJs.RelPermalink }}"></script>
{{ end }}