revamp code highlighting

This commit is contained in:
panr
2025-02-28 15:14:45 +01:00
parent 6122019375
commit 32e7220cb9
10 changed files with 179 additions and 611 deletions

View File

@ -0,0 +1,20 @@
const blockcodes = document.querySelectorAll(".chroma code[data-lang]");
for (const bc of blockcodes) {
const parent = bc.parentElement;
const content = bc.innerText.split("\n").filter(Boolean).join("\n");
const cpbutton = document.createElement("button");
cpbutton.classList.add("copy-button");
cpbutton.innerText = "Copy";
cpbutton.addEventListener("click", () => {
cpbutton.innerText = "Copied";
setTimeout(() => {
cpbutton.innerText = "Copy";
}, 1000);
navigator.clipboard.writeText(content);
});
parent.prepend(cpbutton);
}