handlebars.java icon indicating copy to clipboard operation
handlebars.java copied to clipboard

Whitespace around {{else}} and {{^}} not stripped in pretty print mode

Open heapoutofspace opened this issue 9 years ago • 4 comments

Given the following template:

A
{{#if someVariableWhichIsFalse}}
B
{{else}}
C
{{/if}}
D

I'd expect the following output:

A
C
D

Instead I'm getting this:

A

C
D

As stated in the title, prettyPrint is enabled. Version is 4.0.6

heapoutofspace avatar May 29 '17 14:05 heapoutofspace

As a workaround I'm using the following template at the moment:

A
{{#if someVariableWhichIsFalse}}
B
{{/if}}
{{#unless someVariableWhichIsFalse}}
C
{{/unless}}
D

This works fine, but using {{else}} would be preferable of course.

heapoutofspace avatar May 29 '17 15:05 heapoutofspace

There is a whitespace control character:

A
{{~#if someVariableWhichIsFalse~}}
B
{{else}}
C
{{/if}}
D

jknack avatar May 25 '18 14:05 jknack

The whitespace control character does not have the same functionality as stripping lines with nothing but a tag. If someVariableWhichIsFalse were true in your example the output would be:

AB
D

In addition, it is very hard to achieve proper indentation with the whitespace control character. E.g.:

A
{{#if someVariableWhichIsTrue~}}
  B
{{/if}}
C

results in

A
B
C

instead of

A
  B
C

heapoutofspace avatar May 28 '18 07:05 heapoutofspace

Thank you 👍🏻

heapoutofspace avatar May 29 '18 15:05 heapoutofspace