Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/minify/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ func run() int {
f.AddOpt(&htmlMinifier.KeepWhitespace, "", "html-keep-whitespace", "Preserve whitespace characters but still collapse multiple into one")
f.AddOpt(&htmlMinifier.KeepQuotes, "", "html-keep-quotes", "Preserve quotes around attribute values")
//f.AddOpt(&htmlMinifier.TemplateDelims, "", "html-template-delims", "Set template delimiters explicitly, for example <?,?> for PHP or {{,}} for Go templates") // TODO: fix parsing {{ }} in tdewolff/argp
f.AddOpt(&htmlMinifier.TemplateBegin, "", "html-template-begin", "Set template open delimiters explicitly, for example <? for PHP or {{ for Go templates")
f.AddOpt(&htmlMinifier.TemplateEnd, "", "html-template-end", "Set template close delimiters explicitly, for example ?> for PHP or }} for Go templates")
f.AddOpt(&jsMinifier.Precision, "", "js-precision", "Number of significant digits to preserve in numbers, 0 is all")
f.AddOpt(&jsMinifier.KeepVarNames, "", "js-keep-var-names", "Preserve original variable names")
f.AddOpt(&jsMinifier.Version, "", "js-version", "ECMAScript version to toggle supported optimizations (e.g. 2019, 2020), by default 0 is the latest version")
Expand Down
8 changes: 8 additions & 0 deletions html/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ type Minifier struct {
KeepQuotes bool
KeepWhitespace bool
TemplateDelims [2]string
TemplateBegin string
TemplateEnd string
}

// Minify minifies HTML data, it reads from r and writes to w.
Expand Down Expand Up @@ -88,6 +90,12 @@ func (o *Minifier) Minify(m *minify.M, w io.Writer, r io.Reader, _ map[string]st
z := parse.NewInput(r)
defer z.Restore()

// shim to properly handle template delims if they have been passed via the cli
if o.TemplateDelims[0] == "" && o.TemplateDelims[1] == "" && o.TemplateBegin != "" && o.TemplateEnd != "" {
o.TemplateDelims[0] = o.TemplateBegin
o.TemplateDelims[1] = o.TemplateEnd
}

l := html.NewTemplateLexer(z, o.TemplateDelims)
tb := NewTokenBuffer(z, l)
for {
Expand Down