Skip to content

Commit

Permalink
Use xhtml.Children more
Browse files Browse the repository at this point in the history
  • Loading branch information
earthboundkid committed May 20, 2024
1 parent 5238a93 commit 086b940
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion internal/xhtml/children.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/xhtml/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/xhtml/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/almanack/service-gdocs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 086b940

Please sign in to comment.