From 086b940c8ee3b2e2f0931ac8e098c4f042bbde40 Mon Sep 17 00:00:00 2001 From: Carlana Johnson Date: Mon, 20 May 2024 14:59:06 -0400 Subject: [PATCH] Use xhtml.Children more --- internal/xhtml/children.go | 2 +- internal/xhtml/new.go | 2 +- internal/xhtml/string.go | 4 ++-- pkg/almanack/service-gdocs.go | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/xhtml/children.go b/internal/xhtml/children.go index f7726961..2cc84403 100644 --- a/internal/xhtml/children.go +++ b/internal/xhtml/children.go @@ -8,7 +8,7 @@ import ( "golang.org/x/net/html" ) -// Children returns a seq of the children of n. +// Children returns a seq of the immediate children of n. func Children(n *html.Node) iter.Seq[*html.Node] { return func(yield func(*html.Node) bool) { if n == nil { diff --git a/internal/xhtml/new.go b/internal/xhtml/new.go index 09697482..5fbfabaf 100644 --- a/internal/xhtml/new.go +++ b/internal/xhtml/new.go @@ -47,7 +47,7 @@ func Clone(n *html.Node) *html.Node { Namespace: n.Namespace, Attr: slices.Clone(n.Attr), } - for c := n.FirstChild; c != nil; c = c.NextSibling { + for c := range Children(n) { c2 := Clone(c) new.AppendChild(c2) } diff --git a/internal/xhtml/string.go b/internal/xhtml/string.go index a296c4b6..a9f0b1ed 100644 --- a/internal/xhtml/string.go +++ b/internal/xhtml/string.go @@ -34,7 +34,7 @@ func InnerHTML(n *html.Node) string { var buf strings.Builder buf.Grow(256) - for c := n.FirstChild; c != nil; c = c.NextSibling { + for c := range Children(n) { if err := html.Render(&buf, c); err != nil { panic(err) } @@ -48,7 +48,7 @@ func InnerHTMLBlocks(n *html.Node) string { var buf strings.Builder buf.Grow(256) - for c := n.FirstChild; c != nil; c = c.NextSibling { + for c := range Children(n) { if err := html.Render(&buf, c); err != nil { panic(err) } diff --git a/pkg/almanack/service-gdocs.go b/pkg/almanack/service-gdocs.go index 650fe3c2..58793a6a 100644 --- a/pkg/almanack/service-gdocs.go +++ b/pkg/almanack/service-gdocs.go @@ -290,7 +290,7 @@ func (svc Services) ProcessGDocsDoc(ctx context.Context, dbDoc db.GDocsDoc) (err } func removeTail(n *html.Node) { - for c := n.FirstChild; c != nil; c = c.NextSibling { + for c := range xhtml.Children(n) { if c.DataAtom == atom.Table { continue }