[Petal] <![CDATA[ ... ]]> and HTML Elements

Fergal Daly fergal at esatclear.ie
Mon Nov 8 21:00:12 GMT 2004


On Mon, Nov 08, 2004 at 01:41:40PM -0500, William McKee wrote:
> Fergal,
> 
> I have no doubt you are right regarding the behavior of Petal. However,
> the correct behavior is not always the optimal behavior. Here's an
> example of a JavaScript that will fail when passed through Petal:
> 
>   <script type="text/Javascript" language="Javascript">
>     var d;
>     d = '1' & '1';
>     alert(d);
>   </script>
> 
> The '&' which does a comparison in the same way that Perl's own && gets
> converted to &amp;. Unfortunately, the browser does not treat this
> entity as a comparison operator.
> 
> Any advice on how to make this work without using an external Javascript
> file would be appreciated.

That's definitely a problem but I don't see the connection with CDATA. I
just tried

<script type="text/Javascript" language="Javascript">
<![CDATA[
  var d;
  d = '1' & '1';
  alert(d);
]]>
</script>

directly in a page in Mozilla (no Petal involved) and it didn't work, so
even if Petal left CDATAs untouched it would not solve this problem.

I generally do

<script type="text/Javascript" language="Javascript">
// <!-- hide this script
var d;
d = 1 & 1;
alert(d);
// --> 
</script>

Petal seems to leave that alone and it's the standard way of doing things
even when Petal isn't involved

http://www.w3.org/TR/html4/interact/scripts.html#h-18.3.2

I know this doesn't allow you to put Petal vars in there but you can't have
everything.

If you really need to put in a Petal var (as I did recently) you can do

<script type="text/Javascript" language="Javascript">
var name = "<tag tal:replace="user/name" />"
// <!-- hide this script
var d;
d = 1 & 1;
alert(d);
// --> 
</script>

There's also nothing to stop you closing the comment tag in the middle,
putting in some Petal and then starting again. It's not the prettiest in the
world but it works. Hope that helps,

Fergal


More information about the Petal mailing list