Skip to content

Conversation

@sgargan
Copy link

@sgargan sgargan commented Apr 19, 2019

The liquid spec is a little vague about quite how greedy whitespace
trimming should be. Currently handling here will eat any available
whitespace between tags including all newline characters
e.g.

(

{%- sometag -%}

)

will render as

()

This is ok for web markup where the whitespace is not important, but for
other document types this greedy consumption is problematic.

Ideally the ws trimming would be less hungry and only trim any whitespace
on the line containing the tag up to and including it's newline, essentially
removing any trace of the tag but leaving other lines intact rendering the above as

(

)

The change here detects whitespace as tokens as they are parsed and
discards any as indicated by the trimming directives up to an including
the first newline.

Checklist

  • I have read the contribution guidelines.
  • make test passes.
  • make lint passes.
  • New and changed code is covered by tests.
  • Performance improvements include benchmarks.
  • Changes match the documented (not just the implemented) behavior of Shopify.

@coveralls
Copy link

coveralls commented Apr 19, 2019

Coverage Status

Coverage decreased (-39.8%) to 49.374% when pulling 0b920bd on sgargan:sgargan/whitespace-handling into e0ae159 on osteele:master.

The liquid spec is a little vague about quite how greedy whitespace
trimming should be. Currently handling here will eat any available
whitespace between tags including all newline characters
e.g.
```
(

{%- sometag -%}

)
```
will render as
```
()
```
This is ok for web markup where the whitespace is not important, but for
other document types this greedy consumption is problematic.

Ideally the ws trimming would be less hungry and only trim any whitespace
on the line containing the tag up to and including it's newline, essentially
removing any trace of the tag but leaving other lines intact rendering the above as
```
(

)
```

The change here detects whitespace as tokens as they are parsed and
discards any as indicated by the trimming directives up to an including
the first newline.
@sgargan sgargan force-pushed the sgargan/whitespace-handling branch from 817a0f5 to 0b920bd Compare April 20, 2019 12:18
@sgargan
Copy link
Author

sgargan commented May 8, 2019

Coverage decrease reported here is not correct ^

@osteele
Copy link
Owner

osteele commented May 12, 2019

I'll look at the coverage.

Do you happen to know how this tracks the reference (Ruby) implementation of Liquid? Does it make it more or less like Ruby Liquid?

(I'm planning to accept it either way, but if it makes this package act less like Ruby Liquid then it probably needs a configuration option. Otherwise an option isn't necessary and probably needlessly increases the complexity.)

@sgargan
Copy link
Author

sgargan commented May 13, 2019 via email

@bglw
Copy link

bglw commented Mar 6, 2021

Just jumping into this old thread to say that this behaviour wouldn't match the ruby liquid implementation, nor the liquidjs implementation. Both trim out newlines alongside whitespace. If merged it should certainly not be the default option.

@osteele
Copy link
Owner

osteele commented Jul 6, 2021

@sgargan can the whitespace control options be used to do what you want?

@osteele osteele self-assigned this Feb 7, 2022
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

Successfully merging this pull request may close these issues.

4 participants