RE: hyphens in comments in script tags

Erik Severinsen wrote:
> 
> Despite using the 'fix-bad-comments: true' setting the HTML comment inside
> the script tag isn't cleaned as hoped. The multiple hyphens (---) stops my
> XSL-transformation as '--' is not valid XML. Isn't Tidy suppose to handle
> this. I'm using JTidy ver. 8jul
> 
> <script type="text/javascript" language="javascript">
> <!--
> myRandomNum = Math.round(10000*Math.random())
> //--- Preload Images ---//
> var idx;
> var check;
> var maxImages = 14;         // Number of images to preload.
> var rollImg = new Array();
> for(idx=0; idx < maxImages + 1; idx++)
> {
>     rollImg[idx] = new Image();
>     if (idx == 0)
>         rollImg[idx].src = "/gfx/lc_glbnetwork_usaflag.gif";
>     if (idx == 1)
>         rollImg[idx].src = "/gfx/lc_glbnetwork_dkflag.gif";
>       if (idx == 11)
>         rollImg[idx].src = "/gfx/lc_glbnetwork_no.gif";
> }
> //-->

The problem is the -- operator.  For example, the for loop in your
example might have been counting down instead of up.  You wouldn't want
Tidy to change idx-- into idx==.  I don't believe you can represent
the -- operator inside a comment that's both legal XML and is recognized
by JavaScript.  So Tidy has to leave it alone.

The only solution is to pull the JavaScript out of the comment and put
it in a CDATA section.  Gary L Peskin posted some changes to do this a
few weeks ago.  Search the Tidy archives at

   http://lists.w3.org/Archives/Public/html-tidy/2000JulSep/thread.html

for "CDATA".  Beware that the results might get rendered improperly by
non-JavaScript aware browsers, assuming you wanted the resulting XML to
be renderable as "backwards compatible" XHTML.

--Randy

Received on Wednesday, 2 August 2000 12:55:08 UTC