HTML spec compliance
See original GitHub issue ~ ¶ prettier --version
2.7.1
~ ¶ echo '<!doctype html><html lang=en><title>hello</title></body>' | prettier --parser html
[error] stdin: SyntaxError: Unexpected closing tag "body". It may happen when the tag has already been closed by another tag. For more info see https://www.w3.org/TR/html5/syntax.html#closing-elements-that-have-implied-end-tags (1:50)
[error] > 1 | <!doctype html><html lang=en><title>hello</title></body>
[error] | ^^^^^^^
[error] 2 |
Unclear why prettier is complaining about an “Unexpected closing tag” and linking to a random page of the HTML Standard. Perhaps use a correct HTML parser such as https://github.com/inikulin/parse5? The https://validator.w3.org/ reports no warnings or errors on this.
Issue Analytics
- State:
- Created a year ago
- Comments:17 (12 by maintainers)
Top Results From Across the Web
HTML Standard
1.7.1 Serializability of script execution; 1.7.2 Compliance with other specifications; 1.7.3 Extensibility. 1.8 HTML vs XML syntax; 1.9 Structure of this ...
Read more >Standards - W3C
W3C develops these technical specifications and guidelines through a ... the standards for building and Rendering Web pages, including HTML, CSS, SVG, Ajax, ......
Read more >compliance.html [plain text] - Apple Open Source
<html><head><meta http-equiv="Content-Type" content="text/html; ... and is likely to formally adopted in a future revision of the specification.
Read more >Short Note on HTML conformance checking - TPGi
Errors. Errors are instances where the code you are checking does not conform to MUST level requirements defined in the HTML specification. 1....
Read more >HTML5test - How well does your browser support HTML5?
HTML5 defines rules for embedding SVG and MathML inside a regular HTML document. ... The Web SQL Database specification is no longer being...
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 Free
Top 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
@jleedev Your points and use case are definitely valid, but if I’m not mistaken, you’re the first person on this issue tracker who requests this while the HTML support was added as early as 2018. So this sounds rather like a good idea for a plugin than something to be considered for the core.
Most of the time a code formatter isn’t expected to print tags that were absent in the input (
head
,tbody
, etc). Prettier is a practical tool, it’s a “code formatter” in the first place, and only then an “AST printer”. Unlike JS, any HTML tag soup can be somehow parsed by a browser. If Prettier worked that way too, that would lead to a messy editing experience. Imagine, you entered the opening tag for a div but not the closing one yet and hit save. What happens next is the rest of the markup is reindented because it’s inside this div now. Theoretically, that’d be correct, but practically annoyingly inconvenient. So a trade-off needs to be made, and using the parser from Angular is such a tradeoff. The Angular team faced a similar dilemma themselves, and they decided that what makes sense for browsing doesn’t necessarily make sense for authoring. E.g., unclosed tags most of the time are unintentional mistakes, something for the developer to fix, so tools shouldn’t try to work them around, an explicit error is much more useful.This is an example of what I’m talking about. It’d be less confusing if Prettier/Angular just refused to parse the code in this case. The current formatting/parsing is useless and looks like a bug to me.
I agree, for educational and debugging purposes, it’d be really cool to be able to explore how browsers see things. But as I described above, in the day-to-day editing experience, this isn’t exactly what’s expected from a formatter.
Yes. And this can be implemented as a plugin.
Yeah, but it is a breaking change, because now we don’t do it, not sure we can shipped it for v3