Skip to content

Commit

Permalink
Merge pull request #24 from ejunga/highlight-toggle
Browse files Browse the repository at this point in the history
Highlight toggle
  • Loading branch information
ejunga authored Jul 22, 2025
2 parents bca23e3 + bf5c1c8 commit d0f229a
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions tdx-enhanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,7 @@
}

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

var re
var style = null
Expand Down Expand Up @@ -1081,11 +1082,23 @@
//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) {
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
}
}

for (const [attr,val] of Object.entries(style)) {
Expand Down Expand Up @@ -1398,6 +1411,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 @@ -1528,6 +1548,7 @@
data = {
colorMode: getColorMode(),
linkBehavior: "tabs",
highlightBehavior: "block",
customHighlights: [],
}
}
Expand Down

0 comments on commit d0f229a

Please sign in to comment.