Shopify / theme-tools

Everything developer experience for Shopify themes
https://shopify.dev/docs/themes
MIT License
67 stars 19 forks source link

Formatting liquid templates for non-HTML content #376

Open amit777 opened 1 year ago

amit777 commented 1 year ago

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 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 %}

jamesmengo commented 2 months ago

Thanks for the suggestion @amit777!

Let me bring this to the team and I'll update you if we decide to action on this :)