Shopify / Shopify/theme-tools

Formatting liquid templates for non-HTML content

Open
#376 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area:prettier-plugin enhancement
Dominant language
TypeScript
Stars
234
Forks
92
Avg merge
1d 3h
Merged PRs (30d)
6

Description

Is your feature request related to a problem? Please describe.
We are using liquid templates within text templates that are not HTML (ie, for text email content). When we use the prettier plugin, multiple whitespace and linebreaks get removed.

Describe the solution you'd like
I would love to be able to pass a config option like "textTemplate: true" to make prettier just format the liquid tags and not the text between them.

Describe alternatives you've considered
Have tried looking for other prettier plugins that support liquid but this seems to be the standard one.

Checklist

  • I have checked and made sure that the proposal adheres to this plugin's principles

I believe the extra whitespace is meaningful in text templates. I've read through this link as well: https://github.com/Shopify/prettier-plugin-liquid/blob/main/docs/whitespace-handling.md

I'm not sure if this prettier module is supposed to be specialized for HTML?

Additional context
Here is an example before/after for a template that I'm looking for:

Before:
{% if foo=="bar" %}FOO SPACE{%endif%}

After (current):
{% if foo == "bar" %}FOO SPACE{% endif %}

Desired Output (no removal of the spaces in between FOO and SPACE but the spacing within a liquid tag are correct):
{% if foo == "bar" %}FOO SPACE{% endif %}

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 from the formatter behavior described in the issue and inspect the repository's Liquid formatting entry points and configuration handling. Reproduce the before/after example, then determine how a text-template option could preserve whitespace outside Liquid tags while still formatting tag spacing; done means the desired output is covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.