summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordemo <demo@antix1>2026-05-08 12:10:06 -0400
committerdemo <demo@antix1>2026-05-08 12:10:06 -0400
commit1725d950bf406a23bebf5d3e15a4068a69997e64 (patch)
tree0ad6ae0752dde637a32aab73e6fcf3017642f7d1
parentf81b6df76521e9d3765b3f6d668f11137fa203c5 (diff)
docs: add comments explaining the logic
-rw-r--r--internal/findlinks/findlinks.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/internal/findlinks/findlinks.go b/internal/findlinks/findlinks.go
index a4f29d7..a281a49 100644
--- a/internal/findlinks/findlinks.go
+++ b/internal/findlinks/findlinks.go
@@ -29,7 +29,16 @@ func FindLinks(r io.Reader) ([]Link, error) {
return links, nil
}
+// iterHTML recursively scans the HTML tree n for link data.
func iterHTML(n *html.Node, buffer []Link) []Link {
+ // Return if n doesn't contain the right kind of data, since
+ // we could potentially iterate twice over things like text
+ // nodes when calling extractText.
+ if n.Type != html.ElementNode && n.Type != html.DocumentNode {
+ return buffer
+ }
+
+ // If we've hit a link, go for it.
if n.Type == html.ElementNode && n.DataAtom == atom.A {
var link Link
@@ -42,6 +51,8 @@ func iterHTML(n *html.Node, buffer []Link) []Link {
buffer = append(buffer, link)
} else {
+ // If not a link, just dive down the tree looking for
+ // more links.
for c := n.FirstChild; c != nil; c = c.NextSibling {
buffer = iterHTML(c, buffer)
}