From c0f855f69fc2681e7c34d91130acda1686776942 Mon Sep 17 00:00:00 2001 From: Joey574 Date: Fri, 22 May 2026 10:14:43 -0700 Subject: [PATCH] shim in template begin and template end support for the cli --- cmd/minify/main.go | 2 ++ html/html.go | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/cmd/minify/main.go b/cmd/minify/main.go index 2719e1735..6b9376b92 100644 --- a/cmd/minify/main.go +++ b/cmd/minify/main.go @@ -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(&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") diff --git a/html/html.go b/html/html.go index 938b794a4..73c63b77d 100644 --- a/html/html.go +++ b/html/html.go @@ -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. @@ -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 {