Shopify / Shopify/liquid

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

Open
#925 6 comments 10 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
11.9k
Forks
1.5k
Avg merge
17h 55m
Merged PRs (30d)
3

Description

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!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing Liquid's existing whitespace-control behavior and the layout and rendered-output examples in this issue. The request needs a decision on the tag syntax and exact newline/indentation semantics; done means the chosen syntax produces the demonstrated formatted HTML without changing unrelated output.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.