| | |
| | | let els = document.getElementsByClassName("highlight"); |
| | | // for each highlight |
| | | for (let i = 0; i < els.length; i++) { |
| | | try { |
| | | if (els[i].getElementsByClassName("clipboard-button").length) continue; |
| | | |
| | | // find pre > code inside els[i] |
| | |
| | | button.className = "clipboard-button"; |
| | | button.type = "button"; |
| | | button.innerHTML = svgCopy; |
| | | button.ariaLabel = "opy the shown code"; |
| | | // remove every second newline from lastCodeBlock.innerText |
| | | button.addEventListener("click", () => { |
| | | navigator.clipboard.writeText(lastCodeBlock.innerText.replace(/\n\n/g, "\n")).then( |
| | |
| | | // find chroma inside els[i] |
| | | let chroma = els[i].getElementsByClassName("chroma")[0]; |
| | | els[i].insertBefore(button, chroma); |
| | | } catch(error) { |
| | | console.debug(error); |
| | | } |
| | | } |
| | | } |