From d0a99bcf179add020f2f33526b7efc4087bc9820 Mon Sep 17 00:00:00 2001 From: ejunga Date: Tue, 22 Apr 2025 12:51:53 -0400 Subject: [PATCH 1/2] Add highlight toggle for block/text highlight --- tdx-enhanced.js | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/tdx-enhanced.js b/tdx-enhanced.js index ca10fe2..8ae7daf 100644 --- a/tdx-enhanced.js +++ b/tdx-enhanced.js @@ -686,6 +686,7 @@ } function handleHighlight(type, txt, element) { + let behavior = settings('get','highlightBehavior') var re var style = null @@ -745,11 +746,19 @@ //console.log("Apply custom highlight:",txt) let link = element.querySelector("a") - if (re && link) { - let newTitle = re[1] - link.innerText = newTitle - //reset regex - re.lastIndex = 0 + if (behavior==="block") { + if (re && link) { + let newTitle = re[1] + link.innerText = newTitle + //reset regex + re.lastIndex = 0 + } + } else { + if (re && link) { + element = link + //reset regex + re.lastIndex = 0 + } } for (const [attr,val] of Object.entries(style)) { @@ -1060,6 +1069,13 @@ +
+

Highlight Behavior

+ +
+ +
+
@@ -1190,6 +1206,7 @@ data = { colorMode: getColorMode(), linkBehavior: "tabs", + highlightBehavior: "block", customHighlights: [], } } From c96357be75615695cba500ba086f8e75ad1fe38d Mon Sep 17 00:00:00 2001 From: ejunga Date: Mon, 2 Jun 2025 11:13:57 -0400 Subject: [PATCH 2/2] Fix text highlighting for tdx update --- tdx-enhanced.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tdx-enhanced.js b/tdx-enhanced.js index 3fd7a1f..e34ce7f 100644 --- a/tdx-enhanced.js +++ b/tdx-enhanced.js @@ -1084,7 +1084,11 @@ } } else { if (re && link) { - element = link + let text = link.innerText + link.innerText = "" + element = link.appendChild(document.createElement("span")) + element.innerText = text + element.style.lineHeight = "1.4" //reset regex re.lastIndex = 0 }