summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordemo <demo@antix1>2026-05-09 12:00:26 -0400
committerdemo <demo@antix1>2026-05-09 12:00:26 -0400
commitda78b8aaff657cb3d89b5968b5bad7fb964b7d21 (patch)
tree0c5d34a9a90989bc173fb131228a26d2c6c77519
parent7ad8b06c83310925b3f1fae54a0903c02e49e47c (diff)
feat: assume HTML preserves spacing as intendedmaster
-rw-r--r--internal/findlinks/findlinks_v2.go9
-rw-r--r--internal/test/findlinks_test.go2
2 files changed, 7 insertions, 4 deletions
diff --git a/internal/findlinks/findlinks_v2.go b/internal/findlinks/findlinks_v2.go
index e56a961..e55dc90 100644
--- a/internal/findlinks/findlinks_v2.go
+++ b/internal/findlinks/findlinks_v2.go
@@ -62,11 +62,14 @@ func harvestText(n *html.Node) string {
return n.Data
// The text of an [html.ElementNode] is the aggregate of the
- // text of its children.
+ // text of its children. We can assume that text is otherwise
+ // correctly formatted in terms of spacing (i.e. markup
+ // doesn't otherwise introduce run-on words unless intended,
+ // for example "I am on <strong>GitHub</strong>!")
case html.ElementNode:
var builder strings.Builder
- for c := n.FirstChild; c != nil; c = c.NextSibling {
- fmt.Fprintf(&builder, "%s ", harvestText(c))
+ for child := n.FirstChild; child != nil; child = child.NextSibling {
+ builder.WriteString(harvestText(child))
}
rawResult := builder.String()
diff --git a/internal/test/findlinks_test.go b/internal/test/findlinks_test.go
index c9107f1..faaa244 100644
--- a/internal/test/findlinks_test.go
+++ b/internal/test/findlinks_test.go
@@ -47,7 +47,7 @@ func TestFindlinks(t *testing.T) {
},
{
Href: "https://github.com/gophercises",
- Text: "Gophercises is on Github !",
+ Text: "Gophercises is on Github!",
},
},
},