0
0
Fork 0

更新 app/static/js/highlight.js

Bug551-DingZeYu
丁晟晔 2024-04-19 10:51:18 +08:00
parent d5c76674da
commit 393264a6fe
1 changed files with 3 additions and 2 deletions

View File

@ -43,11 +43,12 @@ function highLight() {
// 删除所有的mark标签,防止标签发生嵌套 // 删除所有的mark标签,防止标签发生嵌套
articleContent = articleContent.replace(/<(mark)[^>]*>/gi, ""); articleContent = articleContent.replace(/<(mark)[^>]*>/gi, "");
articleContent = articleContent.replace(/<(\/mark)[^>]*>/gi, ""); articleContent = articleContent.replace(/<(\/mark)[^>]*>/gi, "");
// 将文章中所有出现该单词word的地方改为"<mark>" + word + "<mark>"。 // 将文章中所有出现该单词word的地方改为"<span class='highlighted'>" + word + "</span>"。
for (let word of totalSet) { for (let word of totalSet) {
articleContent = articleContent.replace(new RegExp("\\b" + word + "\\b", "g"), "<mark>" + word + "</mark>"); articleContent = articleContent.replace(new RegExp("\\b" + word + "\\b", "g"), "<span class='highlighted'>" + word + "</span>");
} }
document.getElementById("article").innerHTML = articleContent; document.getElementById("article").innerHTML = articleContent;
} }
function cancelHighlighting() { function cancelHighlighting() {