Fixed highlighted lines adding blank lines when copying

This commit is contained in:
squidfunk
2021-12-19 13:40:16 +01:00
parent 368cad0955
commit be0a36d1b0
7 changed files with 27 additions and 22 deletions

View File

@@ -52,24 +52,14 @@ interface SetupOptions {
/**
* Extract text to copy
*
* This function hides annotations prior to extracting the text from the given
* code block, so they're not included in the text that is copied to clipboard.
*
* @param el - HTML element
*
* @returns Extracted text
*/
function extract(el: HTMLElement): string {
const annotations = getElements(".md-annotation", el)
for (const annotation of annotations)
annotation.hidden = true
/* Extract text and show annotations */
el.setAttribute("data-md-copying", "")
const text = el.innerText
for (const annotation of annotations)
annotation.hidden = false
/* Return extracted text */
el.removeAttribute("data-md-copying")
return text
}