Only highlight when nesscary
This commit is contained in:
parent
8c2883ba5c
commit
983d221664
1 changed files with 42 additions and 37 deletions
|
@ -68,7 +68,7 @@ function pathReplacer(html) {
|
|||
return html
|
||||
}
|
||||
|
||||
function highlighter(json, full=true) {
|
||||
function highlighter(json, full = true) {
|
||||
for (var i = 0; i < json.length; i++) {
|
||||
var element = json[i]
|
||||
if (element.type == "element") {
|
||||
|
@ -137,7 +137,7 @@ function highlighter(json, full=true) {
|
|||
|
||||
element.content = element.content.substring(0, spanStart) + replacement + element.content.substring(spanEnd)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// element.content = element.content.replaceAll(termKey, replacement)
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ function highlighter(json, full=true) {
|
|||
return json
|
||||
}
|
||||
|
||||
function converter(html, dynamic=true) {
|
||||
function converter(html, dynamic = true) {
|
||||
var startTime = Date.now()
|
||||
var config = JSON.parse(fs.readFileSync(path.join(__dirname, 'config/config.json')))
|
||||
|
||||
|
@ -178,7 +178,7 @@ function converter(html, dynamic=true) {
|
|||
if (status.emoji) {
|
||||
if (status.emoji.id) {
|
||||
addedHTML += `<img src="/emojis/${status.emoji.id}" title="${status.emoji.name}" class="emoji"/>`
|
||||
} else {
|
||||
} else {
|
||||
addedHTML += status.emoji.name + " "
|
||||
}
|
||||
}
|
||||
|
@ -244,30 +244,35 @@ function converter(html, dynamic=true) {
|
|||
|
||||
for (let index = 0; index < rpTable.length; index++) {
|
||||
const text = rpTable[index];
|
||||
if (dynamic) {
|
||||
replacers[text] = himalaya.stringify(highlighter(himalaya.parse(replacers[text])))
|
||||
}
|
||||
html = html.replaceAll(`{${text}}`, replacers[text])
|
||||
}
|
||||
|
||||
if (html.includes("<body>")) {
|
||||
var bodyHTML = htmlMinifier.minify(html.substring(html.indexOf("<body>") + 6, html.lastIndexOf("</body>")))
|
||||
var parsedHTML = himalaya.parse(bodyHTML)
|
||||
} else {
|
||||
var parsedHTML = himalaya.parse(html)
|
||||
if (!dynamic) {
|
||||
if (html.includes("<body>")) {
|
||||
var bodyHTML = htmlMinifier.minify(html.substring(html.indexOf("<body>") + 6, html.lastIndexOf("</body>")))
|
||||
var parsedHTML = himalaya.parse(bodyHTML)
|
||||
} else {
|
||||
var parsedHTML = himalaya.parse(html)
|
||||
}
|
||||
|
||||
parsedHTML = highlighter(parsedHTML)
|
||||
|
||||
parsedHTML = himalaya.stringify(parsedHTML)
|
||||
if (html.includes("<body>")) {
|
||||
parsedHTML = "<body>" + parsedHTML + "</body>"
|
||||
html = html.substring(0, html.indexOf("<body>")) + parsedHTML + html.substring(html.indexOf("</body>") + 7)
|
||||
} else {
|
||||
html = parsedHTML
|
||||
}
|
||||
}
|
||||
|
||||
// console.log(parsedHTML)
|
||||
|
||||
parsedHTML = highlighter(parsedHTML, dynamic)
|
||||
|
||||
parsedHTML = himalaya.stringify(parsedHTML)
|
||||
if (html.includes("<body>")) {
|
||||
parsedHTML = "<body>" + parsedHTML + "</body>"
|
||||
html = html.substring(0, html.indexOf("<body>")) + parsedHTML + html.substring(html.indexOf("</body>") + 7)
|
||||
} else {
|
||||
html = parsedHTML
|
||||
if (dynamic) {
|
||||
html = html.replaceAll("{LOAD_TIME}", (Date.now() - startTime).toString() + "ms")
|
||||
}
|
||||
|
||||
html = html.replaceAll("{LOAD_TIME}", (Date.now() - startTime).toString() + "ms")
|
||||
|
||||
return html
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue