docs: add copy buttons (#3393)

This commit is contained in:
Marvin Hagemeister
2025-09-11 15:19:34 +02:00
committed by GitHub
parent a7af5c0c3d
commit 554644b240
7 changed files with 128 additions and 70 deletions
+48 -4
View File
@@ -176,14 +176,58 @@ class DefaultRenderer extends Marked.Renderer {
if (title || icon) {
const image = icon
? `<img src="${icon.src}" alt="${icon.text}" title="${icon.text}">`
? `<img src="${icon.src}" alt="${icon.text}" title="${icon.text}" width="20" height="20">`
: "";
out += `<div class="fenced-code-header">
<span class="fenced-code-title lang-${lang}">
${image}
${title ? escapeHtml(String(title)) : "&nbsp;"}
<span class="fenced-code-title lang-${lang} w-full">
<span class="flex items-center gap-2">
${image}
${title ? escapeHtml(String(title)) : "&nbsp;"}
</span>
</span>
${
icon && icon.text !== "Text"
? `<button
type="button"
data-code="${escapeHtml(text)}"
aria-label="Copy to Clipboard"
class="rounded-sm flex items-center justify-center border border-foreground-secondary/30 hover:bg-foreground-secondary/70 data-copied:text-green-300 relative group cursor-pointer w-7 h-7 text-white"
>
<span class="group-copied">
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-4 w-4"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
aria-hidden="true"
>
<path
stroke-width={3}
strokeLinecap="round"
strokeLinejoin="round"
d="M5 13l4 4L19 7"
/>
</svg>
</span>
<span class="group-not-copied">
<svg
class="h-4 w-4"
viewBox="0 0 15 15"
fill="none"
xmlns="http://www.w3.org/2000/svg"
aria-hidden="true"
>
<path
d="M1.55566 2.7C1.55566 2.03726 2.09292 1.5 2.75566 1.5H8.75566C9.41841 1.5 9.95566 2.03726 9.95566 2.7V5.1H12.3557C13.0184 5.1 13.5557 5.63726 13.5557 6.3V12.3C13.5557 12.9627 13.0184 13.5 12.3557 13.5H6.35566C5.69292 13.5 5.15566 12.9627 5.15566 12.3V9.9H2.75566C2.09292 9.9 1.55566 9.36274 1.55566 8.7V2.7ZM6.35566 9.9V12.3H12.3557V6.3H9.95566V8.7C9.95566 9.36274 9.41841 9.9 8.75566 9.9H6.35566ZM8.75566 8.7V2.7L2.75566 2.7V8.7H8.75566Z"
fill="currentColor"
/>
</svg>
</span>
</button>`
: ""
}
</div>`;
}