Skip to content

Commit

Permalink
HTML: fix space before <svg>, fixes #751; and fix HTML templates righ…
Browse files Browse the repository at this point in the history
…t after start tag name
  • Loading branch information
tdewolff committed Sep 30, 2024
1 parent beabcf4 commit be02869
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
4 changes: 2 additions & 2 deletions html/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (o *Minifier) Minify(m *minify.M, w io.Writer, r io.Reader, _ map[string]st
} 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 {
} else if next.TokenType == html.StartTagToken || next.TokenType == html.EndTagToken || next.TokenType == html.SvgToken || next.TokenType == html.MathToken {
if o.KeepWhitespace {
break
}
Expand All @@ -208,7 +208,7 @@ 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.StartTagToken {
} else if next.TokenType == html.StartTagToken || next.TokenType == html.SvgToken || next.TokenType == html.MathToken {
break
}
}
Expand Down
8 changes: 2 additions & 6 deletions html/html_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func TestHTML(t *testing.T) {
{`a <picture> <img> </picture>b`, `a <picture><img> </picture>b`},
{`<input placeholder=" a " value=" b ">`, `<input placeholder=" a " value=" b ">`},
{`a <strike> b </strike> c`, `a <strike>b </strike>c`},
{`a <svg>`, `a <svg>`},

// from HTML Minifier
{`<DIV TITLE="blah">boo</DIV>`, `<div title=blah>boo</div>`},
Expand Down Expand Up @@ -379,12 +380,7 @@ func TestHTMLTemplates(t *testing.T) {
{`<select>{{ range . }}<option>{{ . }}{{ end }}</select>`, `<select>{{ range . }}<option>{{ . }}{{ end }}</select>`},
{`<p>Hello <code>{{""}}</code> there</p>`, `<p>Hello <code>{{""}}</code> there`},
{`<select><option>Default</option>{{range $i, $lang := .Languages}}<option>{{$lang}}</option>{{end}}</select>`, `<select><option>Default{{range $i, $lang := .Languages}}<option>{{$lang}}{{end}}</select>`},
{`<select name="language">
<option value=""{{if eq "" (.Post.Get "language")}} selected{{end}}>{{T "Default"}}</option>
{{range $i, $lang := .Languages}}
<option value="{{$lang}}"{{if eq $lang ($.Post.Get "language")}} selected{{end}}>{{index $.LanguageNames $i}}</option>
{{end}}
</select>`, ``},
{`<tr{{if .Deleted}} class="is-disabled"{{end}}>`, `<tr{{if .Deleted}} class="is-disabled"{{end}}>`},
}

m := minify.New()
Expand Down

0 comments on commit be02869

Please sign in to comment.