-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Extra Spacing in HTML Source Due To Liquid Tag Indentation #162
Comments
+1 Is it possible to have something like this in erb?
the minus after |
This is super annoying and forces me to either show very little love to the resulting HTML, or try to wield massive one liner liquid monstrosities. Is there any way around this? |
It seems that the simplest way to achieve this might be to update Liquid's tag regex to allow newline characters inside of the tag. So instead of this code, which will produce clean output with no blank lines:
... you could do this, which is more readable but would produce identical output:
This seems simpler than handling |
+1. Liquid tags in my case cause blank lines at the beginning of an .rss file, leading to warnings about malformed XML: |
+1 I like neat source code. |
+1 Just came to this realization with the problem indenting causes. I would much rather do this in my template, but you'll end up with bad indentation in the final HTML:
Instead your forced to do the following, which ends up making the template less readable, but then the indentation works out correctly in the final HTML source:
I'm hoping this won't always be the case, surely there is a decent solution for this. |
Closing for now... |
Something like that would be great. We need to show love for both the template markup as well as the final html results :) |
@fw42 here's a quick regex that you could use to extend your work in #218 that would likely handle what you're looking for (trimming all that extra whitespace from non-blank blocks): output.gsub(/[ \t]+$/, '').gsub(/(\r?\n)+/, "\n") That will first trim all trailing whitespace on each line and then get rid of blank lines. It will leave leading (indentation) whitespace alone. |
Thanks @nickpearson, will give it a thought! |
The only concern I have (and that's the reason why I didn't remove whitespace in #218 during rendering yet for blank blocks): I want whitespace inside of raw tags to not get stripped. |
This may be further than you want to take this, but keeping the whitespace inside the So, this: hi
<pre>some code</pre>
done becomes this during processing: hi
gfm-extraction-c7951391aa93bc9a21e91b41c98f6917
done with the { "c7951391aa93bc9a21e91b41c98f6917" => "<pre>some code</pre>" } You can see this in lines 5-10 and 23-25 in the gist shown at the bottom of the GitHub Flavored Markdown page. Since the extraction/replacement code is pretty short and simple, it could be used to keep |
Huh, that's a very interesting yet simple idea! @boourns, what do you think? |
Any idea when this might be reopened? |
I have the following code
When I have my HTML source and Liquid tags indented properly for readability and I build the site with Jekyll then there appears to be A TON of whitespace in my HTML source. This is caused by the if statement being false so the indentation before the beginning
{% if post.is_review == true and post.image != nil limit:10 %}
and the ending{% endfor %}
is being included into the output of the HTML source.You can see a pastebin of my source to see just how much whitespace is added. I originally reported this with the Jekyll project and was informed that it was a Liquid issue as Jekyll just prints the output of what Liquid parses and returns. White Space Issue
See the above screen shot to see what I mean. While the little bit of whitespace shown in the image may not seem like a big deal when it loops through 100 posts that do not match the if statement that is 100 lines of spaces for the indentation. In my site it leads to a ton of blanke white space only lines.
This may not seem like that big of an issue but to keep the tags on the same line screws with readability in my opinion. Not only does it make readability difficult it is actually increasing the size of the page thereby effecting the load times.
A work-around for this is to keep the endif and endfor on the same line such as the code below
The text was updated successfully, but these errors were encountered: