|
@@ -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)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|