eta-dev / eta

Embedded JS template engine for Node, Deno, and the browser. Lighweight, fast, and pluggable. Written in TypeScript
https://eta.js.org
MIT License
1.35k stars 60 forks source link

[Question] How to trim whitespaces and indentation? #259

Closed tjhoo closed 9 months ago

tjhoo commented 9 months ago

Hi I have a template (with indentation) that looks like the following,

<html>
  <body>
    <h2 ><%= it.name %></h2>
  </body>
</html>

Can Eta trim all the indentation and EOL when generating the output? I want the indentation when editing the template, and to trim the whitespace when saving the output into database.

I have enabled autoTrim like this,

const eta = new Eta({ views: "templates", autoTrim: ["nl", "slurp"] });
const html = eta.render("./dummy", data);

but the indentation and whitespaces are still in html.

nebrelbug commented 9 months ago

@tjhoo Eta won't minify your HTML for you, autoTrim just enables trimming after Eta tags. But you could write a plugin to perform minification quite easily!

tjhoo commented 9 months ago

Thanks for your reply.