...
1
2
3
4
5
6
7 package html
8
9 import "iter"
10
11
12
13
14 func (n *Node) Ancestors() iter.Seq[*Node] {
15 _ = n.Parent
16
17 return func(yield func(*Node) bool) {
18 for p := n.Parent; p != nil && yield(p); p = p.Parent {
19 }
20 }
21 }
22
23
24
25
26
27 func (n *Node) ChildNodes() iter.Seq[*Node] {
28 _ = n.FirstChild
29
30 return func(yield func(*Node) bool) {
31 for c := n.FirstChild; c != nil && yield(c); c = c.NextSibling {
32 }
33 }
34
35 }
36
37
38
39
40
41 func (n *Node) Descendants() iter.Seq[*Node] {
42 _ = n.FirstChild
43
44 return func(yield func(*Node) bool) {
45 n.descendants(yield)
46 }
47 }
48
49 func (n *Node) descendants(yield func(*Node) bool) bool {
50 for c := range n.ChildNodes() {
51 if !yield(c) || !c.descendants(yield) {
52 return false
53 }
54 }
55 return true
56 }
57
View as plain text