Skip to content

Commit

Permalink
Add highlight toggle for block/text highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
ejunga committed Apr 22, 2025
1 parent 7bb2b11 commit d0a99bc
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions tdx-enhanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@
}

function handleHighlight(type, txt, element) {
let behavior = settings('get','highlightBehavior')

var re
var style = null
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -1060,6 +1069,13 @@
<input type="radio" id="linkBehavior-tabs" name="linkBehavior" value="tabs">
<label for="linkBehavior-tabs">Tabs</label>
</div>
<div>
<h4>Highlight Behavior</h4>
<input type="radio" id="highlightBehavior-block" name="highlightBehavior" value="block">
<label for="highlightBehavior-block">Block</label><br>
<input type="radio" id="highlightBehavior-text" name="highlightBehavior" value="text">
<label for="highlightBehavior-block">Text</label><br>
</div>
</form>
</div>
Expand Down Expand Up @@ -1190,6 +1206,7 @@
data = {
colorMode: getColorMode(),
linkBehavior: "tabs",
highlightBehavior: "block",
customHighlights: [],
}
}
Expand Down

0 comments on commit d0a99bc

Please sign in to comment.