Browse Source

feat: 跳过高亮词组

zhangyuhan 1 month ago
parent
commit
ba0a0a01a8
1 changed files with 6 additions and 1 deletions
  1. 6 1
      resource/staticres/js/common.js

+ 6 - 1
resource/staticres/js/common.js

@@ -142,7 +142,12 @@ function replaceKeywordWithRichText (htmlString, keyword, richChar) {
       node.parentNode.replaceChild(frag, node)
       node.parentNode.replaceChild(frag, node)
     } else if (node.nodeType === Node.ELEMENT_NODE) {
     } else if (node.nodeType === Node.ELEMENT_NODE) {
       // 如果是元素节点,递归其子节点
       // 如果是元素节点,递归其子节点
-      Array.from(node.childNodes).forEach(replaceText)
+      var skipClassName = ['keyword', 'highlight-text']
+      var skip = skipClassName.some(sk => node.className.indexOf(sk) !== -1)
+      // 跳过已经高亮的元素子节点
+      if (!skip) {
+        Array.from(node.childNodes).forEach(replaceText)
+      }
     }
     }
   }
   }