<script type="text/javascript"> - generate CDATA as well ?

The correct way of writing JS ]]> blocks is following:

        //
        
]]>


How about IDEA will generate those CDATA blocks as well when completing the code after ]]> if type chosen is "text/javascript" ?

9 comments
Comment actions Permalink

All right, for the personal use - I'll just use Live Templates .. :)

0
Comment actions Permalink


There's a "Surround with...CDATA section" template.


0
Comment actions Permalink

Ah, never used this one. Thanks !

But still - if IDEA clearly sees the user is going to write a JS script block - it may still add a CDATA section by itself, enforcing a correct writing style. Otherwise people may not even remember to provide one.

0
Comment actions Permalink

For what it's worth I prefer a style without any comments and/or CDATA sections
myself.


0
Comment actions Permalink

Hello Taras,

For what it's worth I prefer a style without any comments and/or CDATA
sections myself.


The trick about the comments is to make XHTML work in both Internet Explorer and FireFox, etc.: IE
doesn't understand XHTML and implicitly assumes ]]> to be CDATA, so the section start/end
appears to be commented out. FF however needs the CDATA for things like "i < j" in JS.

Browser Hell ;)

Sascha

0
Comment actions Permalink

In our JSF application we use RichFaces and Ajax4jsf. Ajax4jsf needs HTMl response to be a legal XHTML page so it requires developers to put it's own Servlet Filter that parses the output and wraps all ]]> content in CDATA if it doesn't appear there already.

0
Comment actions Permalink

FF however needs the CDATA for things like "i < j" in JS.


Right, forgot to mention it. IDEA needs it as well - otherwise it complains about &, inside ]]></span> block. After CDATA is added - IDEA becomes happy and stops complaining.</p>

0

Please sign in to leave a comment.