W3C home > Mailing lists > Public > public-html@w3.org > December 2010

Re: DOM comments inside a <style> element

From: Boris Zbarsky <bzbarsky@MIT.EDU>
Date: Mon, 27 Dec 2010 05:40:18 -0600
Message-ID: <4D187B22.9070402@mit.edu>
To: HTML WG <public-html@w3.org>
On 12/27/10 4:33 AM, Daniel Glazman wrote:
> <style type="text/css">p { color: red; }</style>
> <style id="mystyles" type="text/css"></style>
> <script>
> var c = document.createComment("p { color: green; }");
> document.getElementById("mystyles).appendChild(c);
> <script>
> <p>This paragraph should be green</p>
>
> However, the serialization of the test's DOM tree just above after
> script's execution will create a document instance containing a
> valid and parsed stylesheet since the HTML parsing
> rules create an exception if raw text contents of a style element start
> with the literal string "<!--"...

It's not HTML parsing rules that create an exception.  HTML parsing 
rules for <style> are to just parse everything inside as CDATA.  It's 
CSS parsing rules that then go ahead and ignore the "<!--".

In HTML, there is no way to produce a comment node there via the parser.

> I think WebKit is right here. For consistency reasons, comments
> programmatically added to the children of a <style> element should be
> considered as the textual concatenation of "<!--", their textual data
> and "-->".

Consistency with what?

Right now, the behavior is purely based on the DOM: the textContent of 
the <style> element is passed to the CSS parser.  At least apparently in 
non-Webkit browsers.

It sounds like you're proposing some other algorithm for determining the 
data to pass to the CSS parser.  What algorithm?

-Boris
Received on Monday, 27 December 2010 11:40:54 UTC

This archive was generated by hypermail 2.3.1 : Thursday, 29 October 2015 10:16:07 UTC