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

Re: DOM comments inside a <style> element

From: Simon Pieters <simonp@opera.com>
Date: Mon, 27 Dec 2010 13:11:24 +0100
To: "HTML WG" <public-html@w3.org>, "Boris Zbarsky" <bzbarsky@mit.edu>
Message-ID: <op.vodf5a2pidj3kv@simon-pieterss-macbook.local>
On Mon, 27 Dec 2010 12:40:18 +0100, Boris Zbarsky <bzbarsky@mit.edu> wrote:

> 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.


Opera uses textContent, Firefox uses just child text and CDATA nodes.

"For styling languages that consist of pure text, user agents must  
evaluate style elements by passing the concatenation of the contents of  
all the text nodes that are direct children of the style element (not any  
other nodes such as comments or elements), in tree order, to the style  

The spec matches Firefox. The spec is consistent between <style> and  
<script> here. I think the spec is good as it is.

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

Simon Pieters
Opera Software
Received on Monday, 27 December 2010 12:12:02 UTC

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