Skip to content
This repository has been archived by the owner on Nov 29, 2017. It is now read-only.

How do you deal with excess newlines? #193

Closed
ndarville opened this issue Nov 14, 2014 · 5 comments
Closed

How do you deal with excess newlines? #193

ndarville opened this issue Nov 14, 2014 · 5 comments

Comments

@ndarville
Copy link

Forloops, if-else conditionals and all that Liquid goodness leaves A LOT of trailer lines in my compiled code. Aside from running an HTML linter on top of the result, are there any good ways to deal with the cosmetic problem?

@nternetinspired
Copy link

Are you concerned about the added whitespace, or the formatting? If it is the former, you could use a layout to minimise the html:

https://github.com/penibelst/jekyll-compress-html

If it is the latter then you can only really deal with that by formatting your pre-compiled code horribly, and I wouldn't advise that personally.

@jaybe-jekyll
Copy link
Member

Post-processing (minify, etc.) is the simplest and most-straight-forward way to manage compiled/rendered source of course.

However, in the past, I have created liquid "functions" with liquid filters that provide for stripping newlines, etc. which accomplish more or less the same thing.

See the page, "Liquid for Designers", and reference some of the stripping filters that remove the
offending newlines, returns, whitespace, etc.

i.e. strip_newlines - strip all newlines (\n) from string

https://github.com/Shopify/liquid/wiki/Liquid-for-Designers

@ndarville
Copy link
Author

So the idea would be to {% capture %} the resulting output and apply strip_newlines to it?

@jaybe-jekyll
Copy link
Member

Yes; something like that... in some form or fashion, depending on your end goal.

I created routines/functions that handled doing that via an include I recall.

@ndarville
Copy link
Author

Cool beans, sounds doable, especially within the include itself!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants