eta-dev / eta

Embedded JS template engine for Node, Deno, and the browser. Lighweight, fast, and pluggable. Written in TypeScript

Home Page:https://eta.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Control token for *preserving* whitespace

osyvokon opened this issue · comments

Problem
The default for whitespace control is to trim newlines after the tag. This is sensible in most cases. However, sometimes I'd like to preserve the newline. For example:

One
<%= num2str(1 + 1) %>
Three

This is expected to be rendered to

One
Two
Three

but the default output is

One
Two Three

Describe the solution you'd like
Introduce a tag that preserves whitespace overruling global settings. Something like |%>. The example above would become this:

One
<%= num2str(1 + 1) |%>
Three

Describe alternatives you've considered

  1. Put an extra new line after the tag, but this doesn't look good:
    One
    <%= num2str(1 + 1) %>
    
    Three
    
  2. Set autoTrim: false, but that requires trimming whitespace manually (by using <%- and -%>). Again, for the most part I'm happy with autoTrim, but in some rare cases need to override it.

Let me know if you think this is a sensible feature. If so, I can open a pull request.

Thanks!

This is an intriguing idea! I'll ask people what they think in the Eta Discord.