Skip to content

Highlight toggle #24

Merged
merged 4 commits into from
Jul 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1074,11 +1075,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 @@ -1391,6 +1404,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 @@ -1521,6 +1541,7 @@
data = {
colorMode: getColorMode(),
linkBehavior: "tabs",
highlightBehavior: "block",
customHighlights: [],
}
}
Expand Down