vscode-liquid icon indicating copy to clipboard operation
vscode-liquid copied to clipboard

Formatter changes single quotation to double quotation in HTML markup per default

Open renestalder opened this issue 4 years ago • 4 comments

When I format a liquid file with the formatter provider by vscode-liquid, the formatter changes single quotation marks of the HTML markup code to double quotations, all the time.

The default HTML formatter of vscode handles it correctly by keeping it as is.

Single quotations might be rarely used, but they can for example be useful when JSON data is provided via an HTML attribute's value. As JSON is bitchy about requiring double quotations all the time, the solution is to surround the value of the HTML attribute with single quotations to be able using double quotations in the value itself.

Example:

<body class="l-{{data.template}}" data-controller="font" data-font-families-value='["Sailec"]' data-font-loaded-families-value="[]">
</body>

When formatting with vscode-liquid, it will result in this (see data-font-families-value value):

<body class="l-{{data.template}}" data-controller="font" data-font-families-value="['Sailec']" data-font-loaded-families-value="[]">
</body>

I noticed earlier the day, when my client-side JavaScript code threw an error due to not being able to JSON parse the value it got from the HTML elements.

renestalder avatar Dec 30 '20 17:12 renestalder

Mind: There is the option of setting "quote_convert": "none" in the liquidrc file, but somehow I believe, the default should be inverted for HTML attributes.

renestalder avatar Dec 30 '20 17:12 renestalder

Hey @renestalder my logic is always to use double quotes with HTML and single quotes with Liquid, I think my own tastes crept into things a little bit here, so thanks for the submission. I'll make sure to default these in Liquify.

panoply avatar Dec 30 '20 21:12 panoply

Hey @renestalder, I'm having trouble trying to find what option to put for "quote_convert": **** to convert double quotes to single quotes. Couldn't seem to find this anywhere in the docs, do you know what this needs to be set as?

naterodrigues avatar Jan 03 '22 09:01 naterodrigues

@naterodrigues See the rules in the section of the README.

Here's what I did:

{
  "html": {
    "correct": false,
    "force_attribute": false,
    "braces": false,
    "preserve": 2,
    "unformatted": false,
    "quote_convert": "none"
  }
}

renestalder avatar Jan 03 '22 09:01 renestalder

🚢 Shipped v3.0.0

panoply avatar Sep 28 '22 08:09 panoply