by chrismorgan · 5y ago · 0 comments
> IE6 had an interesting HTML parser. It did not necessarily produce a tree; rather it would produce a graph, to more faithfully preserve author intent. Ill-formed markup, e.g., <em><p></em></p>, would result in an ill-formed DOM. This could cause scripts to go into infinite loops by just trying to iterate over the DOM.
Huh, didn’t know that. It’s the sort of thing that makes me wonder, “hmm, was that what was happening that time all those years ago?”
> The problem is I now have to determine which of these four options to make the other three browsers implement (that is, which do I put in the spec). What do you think is the most likely to be accepted by the others? As a reminder, the options are incestual elements that can be their own uncles, elements who have secret lives in the rendering engine, elements that change their mind about who their parents are half-way through their childhood, and quantum elements whose parents change depending on whether you observe their birth or not.
That whole section is great reading, showing just a little bit of the madness that preceded the specification of HTML parsing, and how monumental a job it was.
The decision of some website/internet property owners to decide to 'wall' themselves off has nothing to do with the desire to create well formed documents. They've done this walling off already
"Be strict in what you accept and what you return." is a better methodology.
You're right, look at what a dumpster fire HTML and general HTTP servers are under the hood as a result of building protocols on top of sloppy text formats.
https://blogs.windows.com/msedgedev/2017/04/19/modernizing-d...
<em><p></em></p> would have become a linked list of four nodes <em> --> <p> --> </em> --> </p>
To efficiently find siblings there are forward/backwards links from <em> to </em> like in a skip list.
I have implemented this list, but never actually used it that way. It became too confusing. So I now remove mismatched tags, while creating the list, making it equivalent to a tree. Now I probably should rewrite it to not actually store closing tags.
our parser back then would never produce ill-formed DOM, and in this case it would have produced DOM as if for <em><p></p></em> - i.e. it would have inserted </p> upon meeting </em> to match the <p> and would have dropped the unmatched as result </p> after </em>.
The parser I know best would store a special pointer from the <em> element to where it ends, i.e. the text element between <p> and </em> and keep track of that state to end <em> rendering after passing the closing tag.
I think it was always a graph. I remember reading DOM implementation years ago, where a node will have siblings references as well making it graph DS.
graph doesn't mean multiple parents all the time. if you have references of other nodes in current node data(not just as children) as long as you can travel across Data structure, enough to say it as graph structure.