Ver Fonte

feat: 跳过高亮词组

zhangyuhan há 1 mês atrás
pai
commit
ba0a0a01a8
1 ficheiros alterados com 6 adições e 1 exclusões
  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)
     } 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)
+      }
     }
   }