Is there a way of minifying inline html?

I am passing HTML as an attribute and would like to know if there is a function or a workaround to minify this inline HTML.

This is the link of how I’m passing the html to an iframe srcdoc: {{.Inner}} not working with iframe srcdoc? - #8 by DatsGabs

You could simply use hugo --minify.

Not really, the whole app gets minified but not the attribute as it’s passed as a string

Have a look at the replaceRE function to remove line breaks and spaces.

1 Like

Hugo does some minification of variables and “loops” if you use for instance property="{{ with $variable -}}{{- . -}}{{- end }}" - this might help minify.

1 Like

I’m not sure how pretty it is, but:

{{ $html := "<h1>Hello</h1>" | resources.FromString "identifier.html" }}
{{ $minified := ($html | minify).Content
5 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.