It looks like Hugo uses https://github.com/tdewolff/minify to minify HTML and XML. Its doc seems to say that newlines are preserved (collapsing contiguous whitespace with a newline into one newline):
The XML minifier uses these minifications:
- strip unnecessary whitespace and otherwise collapse it to one space (or newline if it originally contained a newline)
So for this XML template and the default minify options:
<?xml version="1.0"?>
<feed>
<p>{{.Title}}</p>
{{range .Pages}}
<p>{{.Title}}</p>
{{end}}
</feed>
I expected output like this:
<?xml version="1.0"?>
<feed>
<p>Home</p>
<p>Foo</p>
</feed>
However, I got output like this instead:
<?xml version="1.0"?><feed><p>Home</p><p>Foo</p></feed>
OK, so I guess line breaks are “unnecessary whitespace”? If so, fair enough. However, minified HTML seems to still have its indentation:
<html lang=en-us>
<head>
<meta charset=utf-8>
<meta content=foo name=theme>
According to the https://github.com/tdewolff/minify HTML doc, it applies the same policy to HTML indentation:
The HTML5 minifier uses these minifications:
- strip unnecessary whitespace and otherwise collapse it to one space (or newline if it originally contained a newline)
Indeed, if you invoke the minify library using https://go.tacodewolff.nl/minify and Hugo’s options and this HTML:
<html>
<body>
<p>Foo</p>
</body>
</html>
you don’t get indentation:
<html>
<body>
<p>Foo</p>
</body>
</html>
Where does the minified HTML from Hugo get its indentation? Can it be disabled? Can it be enabled for XML too?