HTML Templating requires unquoted attributes
See original GitHub issueHTML supports unquoted attributes, we use a template language that uses unquoted attributes for templating and requires template attributes to NOT have templates. It would be ideal to support an option to not surround attributes with quotes.
Alternatively, having a “sub” HTML syntax like is done with Vue would work as well. We’d prefer to avoid forking the entire HTML plugin just to change this single format if possible.
Prettier 1.15.3 Playground link
--parser html
Input:
<div>
<p id={VALUE}>Hello</p>
</div>
Output:
<div><p id="{VALUE}">Hello</p></div>
Expected behavior: The attribute should not be surrounded by quotes.
<div><p id={VALUE}>Hello</p></div>
Issue Analytics
- State:
- Created 5 years ago
- Comments:15 (13 by maintainers)
Top Results From Across the Web
Unquoted attribute values in HTML and CSS/JS selectors
Attributes are placed inside the start tag, and consist of a name and a value, separated by an = character. The attribute value...
Read more >Can browsers understand unquoted attributes values?
I think browsers in general will have no trouble with unquoted attribute values in many years to come, unless maybe if the value...
Read more >13.2 Parsing HTML documents - HTML Standard - WhatWG
This error occurs if the parser encounters an attribute in a tag that already has an attribute with the same name. The parser...
Read more >html/template - Go Packages
Package template (html/template) implements data-driven templates for ... attribute names, and unquoted attribute // values because they can tickle parser ...
Read more >Template Designer Documentation - Jinja
A Jinja template doesn't need to have a specific extension: .html , .xml , or any ... to access attributes of a variable...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@diervo I know it’s a bit confusing but what I meant
--parser
here is actually a printer since we do not have--printer
at this point so we simply use--parser
as a hint for printers to output something different from the default one, the parser we actually used should be same as the one used by HTML. (The sub-language parsing is happened in the printer.)Regarding plugins, our current architecture does not support injecting some printer logics to other plugin, so I suggested to put it in the HTML plugin for now (https://github.com/prettier/prettier/issues/5627#issuecomment-451657206), and I hope we could address this issue in v2 so that you can easily write a plugin for it without forking the entire repo.
@ikatyang For the record, the grammar we use in LightningWebComponents is a subset of HTML, and we very purposely did that to be compliant with all parsers.
I’m a little bit concerned or unhappy that you guys want us to do a plugin rather that making it part of the default parser since by design we really tried to avoid going that route and have to do forks on things.
I worked on that part of the spec defining parser errors and doing some disambiguation. If you look at the syntax specification: https://www.w3.org/TR/2017/WD-html52-20170228/syntax.html#attribute-value-unquoted-state As long as you don’t use spaces or any quote or unicode that produce a parse error, it is valid HTML, and all the browsers actually honor this and do the correct parsing according to the spec.
We are fine if we have to do the plugin, but I would love for you guys to reconsider given that we are fundamentally spec compliant.