[whatwg] Another issue in parsing tokens in foreign content

Ian Hickson ian at hixie.ch
Wed Jul 3 17:45:38 PDT 2013

On Thu, 4 Jul 2013, Michael Day wrote:
> > 
> > We don't have any data that says that we need to support this for 
> > innerHTML. I think it's a win if we can drop the hack from innerHTML.
> Okay, so allowing some HTML elements to break out of foreign content is 
> a hack added for historical reasons, that will surprise authors and 
> complicate implementations and is thus regrettable, but necessary.
> Then there are two possibilities for fragment parsing:
> (1) The hack can be left out of fragment parsing, as there is no 
> historical justification for it. Since the hack is bad, removing it from 
> as many situations as possible is good.
> (2) The hack can apply to fragment parsing in the same way as it applies 
> to regular parsing. This makes parsing behaviour more consistent across 
> different situations, which is good.
> I'm strongly in favour of (2), as it seems that omitting the hack from 
> some rare situations doesn't save authors any trouble, and doesn't 
> follow the principle of least surprise.

The problem is that we can't do (2) in _all_ cases, e.g. innerHTML on an 
<svg> can't possibly break out of the <svg> if it sees one of these tags, 
since that's the "root" of what is being parsed.

Given that, it's not clear that (2) is better than (1). (I agree that if 
we could actually always be consistent, it would be.)

Note that this isn't the only place like that.



   document.createElement('table').innerHTML = '<div>';

...result in very different DOMs (in the first, the <div> and the 
<table> are siblings; in the latter, the <div> is a child).

> In an ideal world it would be possible to grab any subsection of a 
> document, parse that in isolation as a fragment, and get the same result 
> as if it was parsed in its original document context. This is possible 
> in XML, but not HTML, due to the existing "author-friendly" hacks, and 
> making the parsing behaviour even more context sensitive doesn't seem 
> like a good thing.

I think we're _so_ far beyond this ideal world that I'm not sure it's 
worth even looking for it, to be honest. :-)

Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'

More information about the whatwg mailing list