From b53e7031e5d1a21d300c8a40821694469e282e66 Mon Sep 17 00:00:00 2001 From: lin <1002171145@qq.com> Date: Mon, 13 Jun 2022 11:40:20 +0800 Subject: [PATCH 1/2] Bug412-JiangLetian --- app/static/js/highlight.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/static/js/highlight.js b/app/static/js/highlight.js index 2e0d84a..d91fb24 100644 --- a/app/static/js/highlight.js +++ b/app/static/js/highlight.js @@ -29,9 +29,10 @@ function highLight() { if (sel_word1 != null) { var list = sel_word1.value.split(" "); for (var i = 0; i < list.length; ++i) { - list[i] = list[i].replace(/(^\s*)|(\s*$)/g, ""); + list[i] = list[i].replace(/(^\s*)|(\s*$)/g, "");//消除字符串两边空字符 if (list[i] != "" && "".indexOf(list[i]) == -1 && "".indexOf(list[i]) == -1) { - txt = txt.replace(new RegExp(list[i], "g"), "" + list[i] + ""); + + txt = txt.replace(new RegExp("\\s"+list[i]+"\\s", "g"), " " + list[i] + " "); } } } @@ -40,7 +41,7 @@ function highLight() { for (var i = 0; i < list2.length; ++i) { list2[i] = list2[i].replace(/(^\s*)|(\s*$)/g, ""); if (list2[i] != "" && "".indexOf(list2[i]) == -1 && "".indexOf(list2[i]) == -1) { - txt = txt.replace(new RegExp(list2[i], "g"), "" + list2[i] + ""); + txt = txt.replace(new RegExp("\\s"+list2[i]+"\\s", "g"), " " + list2[i] + " "); } } } From 041cbd97fc9e0b48126ed4dd633fac709599297b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=92=8B=E4=B9=90=E5=A4=A9?= <1249355696@qq.com> Date: Mon, 13 Jun 2022 21:32:49 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20'app/static/js/highlig?= =?UTF-8?q?ht.js'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/static/js/highlight.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/static/js/highlight.js b/app/static/js/highlight.js index d91fb24..21417c1 100644 --- a/app/static/js/highlight.js +++ b/app/static/js/highlight.js @@ -31,7 +31,7 @@ function highLight() { for (var i = 0; i < list.length; ++i) { list[i] = list[i].replace(/(^\s*)|(\s*$)/g, "");//消除字符串两边空字符 if (list[i] != "" && "".indexOf(list[i]) == -1 && "".indexOf(list[i]) == -1) { - + //将正则表达式进行修改 表示搜索的是两端带有空格的list[i] 那么搜索的便为一个完整单词 然后在mark标签的前后各加了一个空格对其进行替换 txt = txt.replace(new RegExp("\\s"+list[i]+"\\s", "g"), " " + list[i] + " "); } } @@ -41,6 +41,7 @@ function highLight() { for (var i = 0; i < list2.length; ++i) { list2[i] = list2[i].replace(/(^\s*)|(\s*$)/g, ""); if (list2[i] != "" && "".indexOf(list2[i]) == -1 && "".indexOf(list2[i]) == -1) { + //将正则表达式进行修改 表示搜索的是两端带有空格的list2[i] 那么搜索的便为一个完整单词 然后在mark标签的前后各加了一个空格对其进行替换 txt = txt.replace(new RegExp("\\s"+list2[i]+"\\s", "g"), " " + list2[i] + " "); } }