walk visits every element node under parent, applying tag/attr/style classification. Children are iterated via the next-sibling pointer because we mutate the tree in place (replace / remove nodes). The walker is iterative-style via explicit recursion because the html parser's typical nesting depth
(parent *xhtml.Node, rep *Report)
| 86 | // goroutine stack limit; the existing draft package's plainTextFromHTML |
| 87 | // (mail/draft/htmltext.go) similarly recurses for the same reason. |
| 88 | func walk(parent *xhtml.Node, rep *Report) { |
| 89 | child := parent.FirstChild |
| 90 | for child != nil { |
| 91 | next := child.NextSibling |
| 92 | if child.Type == xhtml.ElementNode { |
| 93 | processElement(parent, child, rep) |
| 94 | } |
| 95 | // child may have been removed/replaced by processElement; recurse |
| 96 | // only if it still has the original parent (i.e. wasn't deleted). |
| 97 | // The html parser sets Parent on every node, so a removed-then- |
| 98 | // reattached node still recurses correctly via its new Parent. |
| 99 | if child.Parent != nil { |
| 100 | walk(child, rep) |
| 101 | } |
| 102 | child = next |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | // processElement applies the element-level classification cascade: |
| 107 | // 1. tag → allow / warn-rewrite / error-delete |
no test coverage detected