Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
renestalder opened this issue Dec 30, 2020 · 5 comments

Comments

@renestalder
Copy link

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
Copy link
Author

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 renestalder changed the title Formatter changes single quotation to double quotation in HTML markup Formatter changes single quotation to double quotation in HTML markup per default Dec 30, 2020
@panoply
Copy link
Owner

panoply commented Dec 30, 2020

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 panoply added the 💧Liquify Features shipping in Liquify label Dec 30, 2020
@panoply panoply added this to the Liquify milestone Dec 30, 2020
@naterodrigues
Copy link

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?

@renestalder
Copy link
Author

@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"
  }
}

@panoply panoply added v3.0.0 and removed 💧Liquify Features shipping in Liquify labels Sep 25, 2022
@panoply panoply removed this from the Liquify milestone Sep 25, 2022
@panoply
Copy link
Owner

panoply commented Sep 28, 2022

🚢 Shipped v3.0.0

@panoply panoply closed this as completed Sep 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants