Add support for other languages inside {% javascript %}, {% style %} and {% schema %} tagsc
{% javascript %} -> JS formatter
{% style %} -> CSS formatter
{% schema %} -> JSON formatter
Add a new setting: embeddedSingleQuote
When true, single quotes will be preferred in embedded language blocks (JS, CSS, TS).
There's an upstream issue (shared by VueJS users) that prevents us from having two different "singleQuote" configurations in the same file.
Not having a setting for this caused a huge unecessary diff in Dawn. It looks like single in embedded and double for HTML is the way to go. THat'll be our default.
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.
In this PR
Add support for other languages inside
<script>
and<style>
tagsThat is, use prettier's other parsers for languages inside those code fences.
<script>
-> prettier's JavaScript formatter<script type="application/x-typescript">
-> prettier's TypeScript formatter<script type="anything/ends-with-json">
-> prettier's JSON formatter<script type="text/markdown">
-> prettier's Markdown formatter<style>
-> prettier's CSS formatterAdd support for other languages inside
{% javascript %}
,{% style %}
and{% schema %}
tagsc{% javascript %}
-> JS formatter{% style %}
-> CSS formatter{% schema %}
-> JSON formatterAdd a new setting:
embeddedSingleQuote
true
, single quotes will be preferred in embedded language blocks (JS, CSS, TS).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.
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.
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
On dawn
https://github.com/Shopify/dawn/compare/wip%2Fprettier...Shopify:wip%2Fprettier-2
Fixes #7 Fixes #8