Re: [webcomponents] Template element parser changes => Proposal for adding DocumentFragment.innerHTML

Users will surely find this annoying when they know that it can be
automated. This will also result in users being tripped up on this as they
learn about this feature by looking at some other code that isn't passing a
context (because it doesn't need one) and then all of a sudden they hit a
case where they need one and it fails.


On Wed, May 9, 2012 at 1:01 PM, Ian Hickson <ian@hixie.ch> wrote:

>
> Quick alternative proposal that might work for both <template> parsing and
> DocumentFragment.innerHTML:
>
>   Have createDocumentFragment() take as an argument a context element.
>   Maybe also make it a mutable attribute of the object. Defaults to its
>   owner document's body element or root element or some such. Null means
>   no root element.
>
>     var df = document.createDocumentFragment(document.body);
>     df.contextElement = document.createElement('style');
>
>   Have innerHTML use that as the context element to the fragment parsing
>   algorithm.
>
>     df.innerHTML = 'p::before { content: '<hello> <world>'; }';
>
>   Have <template> take an argument that's the element tag name for it to
>   use to create its context element. Defaults to <body>.
>
>     <template context="tr"> <td> </template>
>     <template context="svg"> <g/> </template>
>
>   Parse <template> by creating a new Document object that's like the ones
>   you get from createDocument() (i.e. "dead"), and then creating a
>   DocumentFragment owned by that Document, and then pushing that
>   DocumentFragment onto the stack instead of the <template> element, but
>   set up to act like the <template> element for the purposes of being
>   popped off. (Except when parsing without a browsing context, then you
>   just parse normally.)
>
> Not sure how solid this is, but it's an idea at least. Hopefully an
> original one, though I'm sure y'all have considered it before. :-)
>
> --
> Ian Hickson               U+1047E                )\._.,--....,'``.    fL
> http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
> Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'
>
>

Received on Wednesday, 9 May 2012 17:39:15 UTC