Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Whitespace flags not respected on blocks (for/if) #79

Closed
2 tasks done
chrisghill opened this issue Mar 20, 2023 · 6 comments
Closed
2 tasks done

Whitespace flags not respected on blocks (for/if) #79

chrisghill opened this issue Mar 20, 2023 · 6 comments

Comments

@chrisghill
Copy link
Contributor

Checklist

  • I have searched the issue list
  • 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
Copy link
Contributor Author

Opening a PR to fix this.

@zsdyx
Copy link

zsdyx commented Apr 6, 2023

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

@chrisghill
Copy link
Contributor Author

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

@LorienMan
Copy link

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
Copy link

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

@jamslinger jamslinger mentioned this issue May 1, 2024
6 tasks
@jamslinger
Copy link
Contributor

jamslinger commented May 1, 2024

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 :)

@danog danog closed this as completed Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants