4 ms·
I believe you really meant that you are frequently dealing with HTML which structure is already known in advance, not the general HTML. Because... > [...] real
by lifthrasiir 6y ago
I believe you really meant that you are frequently dealing with HTML which structure is already known in advance, not the general HTML. Because...
> [...] real world HTML usually can't be parsed by any strict parser [...]
There is the literal standard for parsing HTML [1]. Any conformant implementation (and there are plenty) can of course parse the real world HTML by definition. Just that you don't always need the full HTML parser to do your job.
[1] https://html.spec.whatwg.org/multipage/parsing.html https://html.spec.whatwg.org/multipage/parsing.html
- tomashubelbauer 6y agoI think this is only true for HTML5, but previous versions of HTML supposedly weren't specced well enough to write a prefect parser. Fixing this was one of the goals of the HTML5 revision if I'm not mistaken.
- lifthrasiir 6y agoYou are correct, but I don't think they are even slightly relevant in 2021.
- bawolff 6y agoWeb browsers exist, therefore its possible to parse html, even earlier versions. You're right that the de jure spec did not match de facto html, and browsers didn't neccesarily agree with each other. But that's always true. GCC has language extensions that aren't part of the c spec, but you wouldn't say that c is impossible to parse. Old html may have taken it up to 11, but its not fair to say its impossible to parse.
- chrismorgan 6y agoPerl is famously unparseable: it’s impossible to determine a parse tree without executing the code. (HTML, however, was never unparseable, merely insufficiently defined.)
- uuidgen 6y agoNo, not really. The browsers did guess a lot and did standard-deviating parsing because the typical uses were wrong and they had to work. Nobody would switch to a new browser that doesn't work with existing pages. Modern example - mXSS. Even though modern html have to be valid xml the browser will, instead of giving an error when served invalid html, transform what's given to make it standard-compliant.
- bawolff 6y agoModern html by definition is not valid XML, unless you are using the xml serialization of html5 which isn't really teccomended and nobody does. Really no version of the official html spec was valid xml other than XHTML which was never particularly popular. But i don't really see your point. An implementation having a different idea how to parse html than you think is correct is not the same thing as something being unparsable. Its a tautology that if there exists a computer progran to parse something than it is possible to parse it with a computer program.
- anoncake 6y agoPrevious versions of HTML were based on SGML. You can write a perfect SGML parser, but the developers of web browsers couldn't be bothered.
- erik_seaberg 6y ago“Worse is better” strikes again. In the early days of markup hand written by amateurs, users preferred the browsers that tolerated mistakes. Now the language is defined by a common error handling procedure, instead of a grammar.
- karatinversion 6y ago> There is the literal standard for parsing HTML [1]. Any conformant implementation (and there are plenty) can of course parse the real world HTML by definition. I believe GP was alluding to the fact that many actual resources that declare themselves HTML are not spec conformant, and thus can’t be parsed by a parser that only accepts valid HTML.
- lifthrasiir 6y agoThe distinction between "valid" and "invalid" HTML used to matter once upon a time, but it no longer does at least for agents (authors can still benefit from error-free HTMLs because errors can distort their intents). Pretty much every string can be parsed to HTML since HTML5 and all errors are non-fatal, so many modern HTML parsers default to ignore errors. There are parsers that can be configured to abort on any error, but I don't think the GP intended that.
- tannhaeuser 6y agoTrue, and it's worth noting that since WHATWG HTML 5 has usurped HTML and taken it ad absurdum, WHATWG's parsing spec isn't actually useful nor representative at all of what people usually think HTML is. Nor do people have to follow WHATWG's (= bunch of Chrome developers) idea of HTML anymore than WHATWG did follow other's.
- detaro 6y agoWHATWG is not a "bunch of Chrome developers", and if you want to understand what a browser does with HTML, it's the place to look. "HTML, but not the HTML web browsers mean" is a fairly niche concern.
- chrismorgan 6y agoWHATWG’s HTML spec is the only thing that matters when considering what HTML is, because it’s what every browser uses, which is the primary target of HTML.
- dragonwriter 6y ago