[whatwg] Common Subset

Michel Fortin michel.fortin at michelf.com
Sat Dec 9 05:54:31 PST 2006


Le 9 déc. 2006 à 7:50, Lachlan Hunt a écrit :

> Alexey Feldgendler wrote:
>> The HTML5 spec could somehow officially bless CDATA only when used  
>> like this:
>> <script>//<![CDATA[
>> ...
>> //]]></script>
>> It would not harm because it is already interoperable.
>
> It's technically already allowed because script and style elements  
> are defined to contain CDATA.  So basically any string of text that  
> doesn't include '</' before the end tag is valid.
>
> It's already interoperable because that whole string is passed to  
> the javascript engine, and since the '<![CDATA[' and ']]>' are  
> commented out with javascript comments, they're ignored.

I added this example on the wiki page about the common subset:

<script type="text/javascript">
/* <![CDATA[ */
if (a < 0 && a > 10) alert("A not in range (0 < a < 10).")
/* ]]> */
</script>

I used /* */ for comments instead of // so that the trick can work  
with <style> too, and I think the extra spaces make clearer the  
relationship between the CDATA block and the script.

<http://wiki.whatwg.org/wiki/Common_Subset>


Michel Fortin
michel.fortin at michelf.com
http://www.michelf.com/





More information about the whatwg mailing list