mozilla / nunjucks

A powerful templating engine with inheritance, asynchronous control, and more (jinja2 inspired)
https://mozilla.github.io/nunjucks/
BSD 2-Clause "Simplified" License
8.48k stars 635 forks source link

Different behavior for `trimBlocks` of ConfigureOptions and `trim` of filters #1374

Open 0xTadash1 opened 2 years ago

0xTadash1 commented 2 years ago

I noticed this when I used it with Whitespace Control.

Using trim of filters works as expected.

=========================

  {% if msg -%}
    msg:  {{ msg | trim }}
  {%- endif %}

=========================
=========================

  msg: foobar....

=========================

However, in the case of ConfigureOptions:

=========================

  {% if msg -%}
    msg: {{ msg }}
  {%- endif %}

=========================
=========================

  msg:  foobar....
=========================

Line breaks are lost.

To get the same result using trimBlocks:

=========================

  {% if msg -%}
    msg: {{ msg + "\n" }}
  {%- endif %}

=========================

This is ugly...


I'm going to use trimBlocks since I use trim frequently. So I'd be very happy if trimBlocks didn't require + "\n" :)