liquid icon indicating copy to clipboard operation
liquid copied to clipboard

Whitespace flags not respected on blocks (for/if)

Open chrisghill opened this issue 1 year ago • 6 comments

Checklist

  • [x] I have searched the issue list
  • [x] I have tested my example against Shopify Liquid. (This isn't necessary if the actual behavior is a panic, or an error for which IsTemplateError returns false.)

Expected Behavior

Respect whitespace flags in for and if blocks.

My friends are:

{%- for friend in people -%}
{{ friend }},
{%- endfor -%}

and I like them!

with

{"people": ["alice", "bob"]}

Should render as

My friends are:alice,bob,and I like them!

https://liquidjs.com/playground.html#TXkgZnJpZW5kcyBhcmU6Cgp7JS0gZm9yIGZyaWVuZCBpbiBwZW9wbGUgLSV9Cnt7IGZyaWVuZCB9fSwKeyUtIGVuZGZvciAtJX0KCmFuZCBJIGxpa2UgdGhlbSE=,eyJwZW9wbGUiOiBbImFsaWNlIiwgImJvYiJdfQ==

Actual Behavior

Whitespace flags are ignored:

My friends are:


alice,

bob,


and I like them!

Detailed Description

It seems the TrimLeft and TrimRight functions aren't invoked at the block level.

Possible Solution

Invoke TrimLeft and TrimRight on the block during rendering.

chrisghill avatar Mar 20 '23 05:03 chrisghill

Opening a PR to fix this.

chrisghill avatar Mar 20 '23 05:03 chrisghill

hi, @chrisghill What to Publish a New Version, fix bug

zsdyx avatar Apr 06 '23 03:04 zsdyx

Hey @zsdyx. I'm sorry, I don't understand what you asked.

chrisghill avatar Apr 15 '23 06:04 chrisghill

The proposed pull request does not completely fix the issue as "block" nodes have actually 4 trim params: left outside, right inside, left inside, right outside and in PR it handles only "outside" trims.

That would be great to have all whitespace trim issues fixed some day :)

LorienMan avatar Dec 08 '23 14:12 LorienMan

... and with if/elsif/else it's getting even worse 😨

LorienMan avatar Dec 08 '23 14:12 LorienMan

I also notices the whitespace control does not match normal liquid behavior and opened a PR with an attempt to fix it. Feedback is much appreciated :)

jamslinger avatar May 01 '24 10:05 jamslinger