Textwalker with optional filter func parameter (#77)

This commit is contained in:
Huang Xin
2025-06-10 12:45:43 +00:00
committed by GitHub
parent d7affcf969
commit 4ee127d88f
2 changed files with 4 additions and 4 deletions
+2 -2
View File
@@ -27,9 +27,9 @@ const acceptNode = node => {
return NodeFilter.FILTER_ACCEPT
}
export const textWalker = function* (x, func) {
export const textWalker = function* (x, func, filterFunc) {
const root = x.commonAncestorContainer ?? x.body ?? x
const walker = document.createTreeWalker(root, filter, { acceptNode })
const walker = document.createTreeWalker(root, filter, { acceptNode: filterFunc || acceptNode })
const walk = x.commonAncestorContainer ? walkRange : walkDocument
const nodes = walk(x, walker)
const strs = nodes.map(node => node.nodeValue)