Skip to content

Commit

Permalink
HTML: don't keep whitespace after closing block tags with KeepWhitesp…
Browse files Browse the repository at this point in the history
…ace, fixes #442
  • Loading branch information
tdewolff committed Sep 21, 2021
1 parent 8a4a1bb commit 1328bfb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions html/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions html/html_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ func TestHTMLKeepWhitespace(t *testing.T) {
{"abc\n</body>\ndef", "abc\ndef"},
{"<x>\n<!--y-->\n</x>", "<x>\n</x>"},
{"<style>lala{color:red}</style>", "<style>lala{color:red}</style>"},
{"<li>one\n</li>\n<li>two", "<li>one\n<li>two"}, // #442
}

m := minify.New()
Expand Down

0 comments on commit 1328bfb

Please sign in to comment.