Skip to content

Commit 78aea00

Browse files
committed
format/htmlparser: collapse spaces when parsing html
1 parent 6ea2337 commit 78aea00

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

format/htmlparser.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"strconv"
1414
"strings"
1515

16+
"go.mau.fi/util/exstrings"
1617
"golang.org/x/net/html"
1718

1819
"maunium.net/go/mautrix/event"
@@ -371,7 +372,7 @@ func (parser *HTMLParser) singleNodeToString(node *html.Node, ctx Context) Tagge
371372
switch node.Type {
372373
case html.TextNode:
373374
if !ctx.PreserveWhitespace {
374-
node.Data = strings.Replace(node.Data, "\n", "", -1)
375+
node.Data = exstrings.CollapseSpaces(strings.ReplaceAll(node.Data, "\n", ""))
375376
}
376377
if parser.TextConverter != nil {
377378
node.Data = parser.TextConverter(node.Data, ctx)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ require (
1717
github.com/tidwall/gjson v1.18.0
1818
github.com/tidwall/sjson v1.2.5
1919
github.com/yuin/goldmark v1.7.12
20-
go.mau.fi/util v0.8.9-0.20250808135321-09699c48d2fa
20+
go.mau.fi/util v0.8.9-0.20250810202017-1d053aac320a
2121
go.mau.fi/zeroconfig v0.1.3
2222
golang.org/x/crypto v0.40.0
2323
golang.org/x/exp v0.0.0-20250718183923-645b1fa84792

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
5151
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
5252
github.com/yuin/goldmark v1.7.12 h1:YwGP/rrea2/CnCtUHgjuolG/PnMxdQtPMO5PvaE2/nY=
5353
github.com/yuin/goldmark v1.7.12/go.mod h1:ip/1k0VRfGynBgxOz0yCqHrbZXhcjxyuS66Brc7iBKg=
54-
go.mau.fi/util v0.8.9-0.20250808135321-09699c48d2fa h1:xVnyD0gaIvK+7xA5lWSqWJf5EB2URW2Y0R4ABisAHD0=
55-
go.mau.fi/util v0.8.9-0.20250808135321-09699c48d2fa/go.mod h1:GZZp5f9r2MgEu4GDvtB0XxCF7i6Z7Z8fM0w9a5oZH3Y=
54+
go.mau.fi/util v0.8.9-0.20250810202017-1d053aac320a h1:AviXwC+XRYNvlmLieSQxBjj5/K5JUIjBgduYNVSrPTo=
55+
go.mau.fi/util v0.8.9-0.20250810202017-1d053aac320a/go.mod h1:GZZp5f9r2MgEu4GDvtB0XxCF7i6Z7Z8fM0w9a5oZH3Y=
5656
go.mau.fi/zeroconfig v0.1.3 h1:As9wYDKmktjmNZW5i1vn8zvJlmGKHeVxHVIBMXsm4kM=
5757
go.mau.fi/zeroconfig v0.1.3/go.mod h1:NcSJkf180JT+1IId76PcMuLTNa1CzsFFZ0nBygIQM70=
5858
golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM=

0 commit comments

Comments
 (0)