liquid icon indicating copy to clipboard operation
liquid copied to clipboard

Add special "whitespace control" tag for nicely formatted output-html

Open RoiEXLab opened this issue 8 years ago • 6 comments
trafficstars

Just a minor priority feature-request, but nonetheless nice to have: Imagine this common scenario: There is a basic layout file in jekyll like this:

<!DOCTYPE html>
<html>
  <head>
    <title>Some Title</title>
  </head>
  <body>
    {{ content }}
  </body>
</html>

If we have an HTML file using this layout like this:

---
layout: default
---
<div>
  <span>Something</span>
</div>

The resulting html would be

<!DOCTYPE html>
<html>
  <head>
    <title>Some Title</title>
  </head>
  <body>
    <div>
  <span>Something</span>
</div>
  </body>
</html>

although both files were nicely formatted. Even with the liquid 4 whitespace control, there's no way to effectively fix that.

My suggestion would be to add some sort of tag like {%?, ?%}, {{? and ?}} (or any other special character), which makes the inserted text have the space before this tag to the preceding newline char appended after every newline exect for the last one. So the resulting output would be

<!DOCTYPE html>
<html>
  <head>
    <title>Some Title</title>
  </head>
  <body>
    <div>
      <span>Something</span>
    </div>
  </body>
</html>

like you would expect.

If I wasn't clear enough, or if you have some other questions about this request, please let me know!

RoiEXLab avatar Aug 26 '17 16:08 RoiEXLab

I currently workaround this issue using a plugin called jekyll-tidy.. But it'd a be great to have this sorted out at Liquid itself.

ashmaroli avatar Sep 16 '17 16:09 ashmaroli

I'm not even sure it should have a special tag, why not just make this the default behaviour? It would make sense for resolving #514 too.

pmackay avatar Sep 10 '18 13:09 pmackay

Any developments here?

spencertweedy avatar Mar 15 '20 20:03 spencertweedy

Another vote for this (I came here from #514 because it doesn't make sense that including files inside my <head> tag end up being less indented than the parent tag)

daattali avatar Aug 22 '20 07:08 daattali

+1

jmrplens avatar Dec 27 '21 00:12 jmrplens