code block line numbers
This commit is contained in:
parent
2766453d75
commit
0226171b58
7 changed files with 159 additions and 99 deletions
|
@ -58,6 +58,19 @@ function addEffect({ target }: UIEvent) {
|
|||
})
|
||||
}
|
||||
|
||||
function addCodeBlockCopiers() {
|
||||
document.querySelectorAll('pre[class^=language]').forEach(el => {
|
||||
const copyButton = document.createElement('button')
|
||||
copyButton.classList.add('copy-button')
|
||||
copyButton.addEventListener('click', () => {
|
||||
if (el instanceof HTMLElement) {
|
||||
navigator.clipboard.writeText(el.innerText)
|
||||
}
|
||||
})
|
||||
el.appendChild(copyButton)
|
||||
})
|
||||
}
|
||||
|
||||
function attend({ target}: UIEvent) {
|
||||
if (!isElement(target) || !target.matches("a[href][target=_blank]")) {
|
||||
return
|
||||
|
@ -75,3 +88,5 @@ document.addEventListener("mouseleave", removeEffect, true)
|
|||
document.addEventListener("blur", removeEffect, true)
|
||||
|
||||
document.addEventListener("click", attend, true)
|
||||
|
||||
document.addEventListener("DOMContentLoaded", addCodeBlockCopiers)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue