diff options
Diffstat (limited to 'src/html/dom.nim')
-rw-r--r-- | src/html/dom.nim | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim index d50c1c8e..aaa33163 100644 --- a/src/html/dom.nim +++ b/src/html/dom.nim @@ -199,6 +199,23 @@ iterator branch*(node: Node): Node {.inline.} = yield node node = node.parentElement +func filterDescendants*(element: Element, predicate: (proc(child: Element): bool)): seq[Element] = + var stack: seq[Element] + stack.add(element.children) + while stack.len > 0: + let child = stack.pop() + if predicate(child): + result.add(child) + stack.add(child.children) + +func all_descendants*(element: Element): seq[Element] = + var stack: seq[Element] + stack.add(element.children) + while stack.len > 0: + let child = stack.pop() + result.add(child) + stack.add(child.children) + # a == b or b in a's ancestors func contains*(a, b: Node): bool = for node in a.branch: |