mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-22 19:46:23 +00:00
fix: ensure code exists inside pre before adding clipboard
This commit is contained in:
parent
ca17af4ae2
commit
7b7064ad2b
1 changed files with 22 additions and 20 deletions
|
@ -7,6 +7,7 @@ document.addEventListener("nav", () => {
|
||||||
const els = document.getElementsByTagName("pre")
|
const els = document.getElementsByTagName("pre")
|
||||||
for (let i = 0; i < els.length; i++) {
|
for (let i = 0; i < els.length; i++) {
|
||||||
const codeBlock = els[i].getElementsByTagName("code")[0]
|
const codeBlock = els[i].getElementsByTagName("code")[0]
|
||||||
|
if (codeBlock) {
|
||||||
const source = codeBlock.innerText.replace(/\n\n/g, "\n")
|
const source = codeBlock.innerText.replace(/\n\n/g, "\n")
|
||||||
const button = document.createElement("button")
|
const button = document.createElement("button")
|
||||||
button.className = "clipboard-button"
|
button.className = "clipboard-button"
|
||||||
|
@ -28,4 +29,5 @@ document.addEventListener("nav", () => {
|
||||||
})
|
})
|
||||||
els[i].prepend(button)
|
els[i].prepend(button)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue