harttle / liquidjs

A simple, expressive, safe and Shopify compatible template engine in pure JavaScript.
https://liquidjs.com
MIT License
1.52k stars 238 forks source link

Compatibility with whitespace handling in Jekyll: trim file on {% include %} #463

Closed Nowaker closed 2 years ago

Nowaker commented 2 years ago

On {% include blah.html %}, Jekyll start-trims (removes leading whitespace) from the referenced file - equivalent of fs.fileReadSync('blah.html').trimStart() - before embedding it into the output.

I'd like to ask for a new option(s) for https://liquidjs.com/tutorials/whitespace-control.html#via-Options:

Because {% include %} is a built-in tag, I wasn't able to tune it to ensure Jekyll compatibility.

FYI: My Jekyll-in-Gatsby project is now almost complete, with whitespace being the only difference between the builds.

harttle commented 2 years ago

Hey @Nowaker , we can treat this as a bugfix for Jekyll include. As for layout, I don't think it makes as much sense as include:

Nowaker commented 2 years ago

we can treat this as a bugfix for Jekyll include

That's a fantastic idea!

harttle commented 2 years ago

I created a demo for this on Jekyll: https://github.com/harttle/jekyll-include-demo The _layouts/foo.liquid included _includes/b.liquid which has leading & trailing spaces and new lines.

It turns out, in this demo, the leading & trailing spaces and new lines of the included file are preserved:

image