Shopify / prettier-plugin-liquid

Prettier Liquid/HTML plugin
https://npm.im/@shopify/prettier-plugin-liquid
MIT License
94 stars 15 forks source link

Add support for embedded languages #88

Closed charlespwd closed 2 years ago

charlespwd commented 2 years ago

In this PR

A note about Liquid-in-JS/CSS/JSON-in-Liquid

We'll try to use prettier's parser to pretty print your JS/CSS/JSON.

If your Liquid only appears in strings, you'll be able to use both. If you use Liquid as an expression, it won't work.

<script>
// won't work
const product = JSON.parse({{ product | json }})
</script>

<script>
// will work
const stuff = { property: "{{ setting.foo }}" }
</script>

When their parser throws, what we do is reindent the body of the tag and nothing more.

We do not attempt to format missing whitespace in Liquid-in-X-in-Liquid.

<script>
  const stuff = {
    property: "{{setting.foo|filter1|filter2:missing:whitespace:ugly}}"
  }
</script>

You'll still have to format that manually (sorry). We might come up with some genius idea to fix this in the future, but it won't be part of v1.0.0.

Examples

image

On dawn

https://github.com/Shopify/dawn/compare/wip%2Fprettier...Shopify:wip%2Fprettier-2

Fixes #7 Fixes #8