Skip to content

Add highlight toggle for block/text highlight #9

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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