From 1328bfb74a4669fc1a5f42873e723368305c805f Mon Sep 17 00:00:00 2001 From: Taco de Wolff Date: Tue, 21 Sep 2021 11:16:25 -0300 Subject: [PATCH] HTML: don't keep whitespace after closing block tags with KeepWhitespace, fixes #442 --- html/html.go | 6 +++--- html/html_test.go | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/html/html.go b/html/html.go index 8342f72a8c..6868c9b79c 100644 --- a/html/html.go +++ b/html/html.go @@ -274,10 +274,10 @@ func (o *Minifier) Minify(m *minify.M, w io.Writer, r io.Reader, _ map[string]st } } - if o.KeepWhitespace || t.Traits&objectTag != 0 { - omitSpace = false - } else if t.Traits&nonPhrasingTag != 0 { + if t.Traits&nonPhrasingTag != 0 { omitSpace = true // omit spaces after block elements + } else if o.KeepWhitespace || t.Traits&objectTag != 0 { + omitSpace = false } if !omitEndTag { diff --git a/html/html_test.go b/html/html_test.go index 727c54e29e..c550788c0f 100644 --- a/html/html_test.go +++ b/html/html_test.go @@ -279,6 +279,7 @@ func TestHTMLKeepWhitespace(t *testing.T) { {"abc\n\ndef", "abc\ndef"}, {"\n\n", "\n"}, {"", ""}, + {"
  • one\n
  • \n
  • two", "
  • one\n
  • two"}, // #442 } m := minify.New()