diff --git a/html/html.go b/html/html.go index 497a08dd0e..fe5d9ae99d 100644 --- a/html/html.go +++ b/html/html.go @@ -169,13 +169,8 @@ func (o *Minifier) Minify(m *minify.M, w io.Writer, r io.Reader, _ map[string]st t.Data = t.Data[:len(t.Data)-1] omitSpace = false break - } else if next.TokenType == html.TextToken { - // this only happens when a comment, doctype or phrasing end tag (only for !o.KeepWhitespace) was in between - // remove if the text token starts with a whitespace - if len(next.Data) > 0 && parse.IsWhitespace(next.Data[0]) { - t.Data = t.Data[:len(t.Data)-1] - omitSpace = false - } + } else if next.TokenType == html.TextToken && !parse.IsAllWhitespace(next.Data) { + // stop looking when text encountered break } else if next.TokenType == html.StartTagToken || next.TokenType == html.EndTagToken { if o.KeepWhitespace { diff --git a/html/html_test.go b/html/html_test.go index 0d02898b0e..16c2069218 100644 --- a/html/html_test.go +++ b/html/html_test.go @@ -85,23 +85,22 @@ func TestHTML(t *testing.T) { // whitespace {`cats and dogs `, `cats and dogs`}, - {`
x
y`, `x
y`}, {`xy
`, `xy`}, {`
`, ``}, // spaces before html and at the start of html are dropped {`
x
y`, `
x
y`},
- {`
x y`, `
x y`}, + {`
x y`, `
x y`},
{`a b`, `a
b`},
{`a
code
b`, `a code
b`},
- {`a code
b`, `a code
b`},
+ {`a code
b`, `a code
b`},
{`a b`, `a b`},
{"text\n\ntext", "text\ntext"},
{"abc\n