Continuing to pollute and overcomplicate the highlight system

This commit is contained in:
bingus_violet 2024-11-13 23:31:53 -06:00
parent dde5fbcce9
commit 1d6696999a

View file

@ -146,15 +146,17 @@ function highlighter(json, full = true, linkParent = false) {
var termKey = "{TERM" + index + "}" var termKey = "{TERM" + index + "}"
var termProps = dict var termProps = dict
while (element.content.includes(termKey)) { while (element.content.includes(termKey)) {
var endRegex = " "
var termIndex = element.content.indexOf(termKey) var termIndex = element.content.indexOf(termKey)
var spanEnd = element.content.indexOf(" ", termIndex) var spanEnd = element.content.indexOf(endRegex, termIndex)
if (spanEnd == -1) { if (spanEnd == -1) {
spanEnd = element.content.length spanEnd = element.content.length
} }
var spanStart = element.content.substring(0, termIndex).lastIndexOf(" ") + 1 var spanStart = element.content.substring(0, termIndex).lastIndexOf(endRegex) + 1
// if (highTable[index] == "ULTRAKILL") { // if (highTable[index] == "ULTRAKILL") {
// console.log(startContent, " ---- ", endContent) // console.log(startContent, " ---- ", endContent)
@ -164,12 +166,27 @@ function highlighter(json, full = true, linkParent = false) {
var endContent = element.content.substring(termIndex + termKey.length, spanEnd) var endContent = element.content.substring(termIndex + termKey.length, spanEnd)
if (startContent.includes("(") && !endContent.includes(")")) { if (startContent.includes("(") && !endContent.includes(")")) {
spanEnd = element.content.indexOf(")", spanStart) + 1 var newSpanEnd = element.content.indexOf(")", spanStart) + 1
endContent = element.content.substring(termIndex + termKey.length, spanEnd) var newEndContent = element.content.substring(termIndex + termKey.length, newSpanEnd)
if (newEndContent.includes("<") || newEndContent.includes("TERM")) {
spanStart += 1
startContent = startContent.substring(2)
} else {
spanEnd = newSpanEnd
endContent = newEndContent
}
} }
else if (endContent.includes(")") && !startContent.includes("(")) { else if (endContent.includes(")") && !startContent.includes("(")) {
spanStart = element.content.substring(0, spanStart).lastIndexOf("(") var newSpanStart = element.content.substring(0, spanStart).lastIndexOf("(")
startContent = element.content.substring(spanStart - 1, termIndex) var newStartContent = element.content.substring(newSpanStart - 1, termIndex)
if (newStartContent.includes("<") || newStartContent.includes("TERM")) {
spanEnd -= 1
endContent = endContent.substring(0, endContent.length - 1)
} else {
console.log(newStartContent)
spanStart = newSpanStart
startContent = newStartContent
}
} }
var style = termProps.style || "" var style = termProps.style || ""