[Zope-dev] Re: TALES idea: tuple unpacking

Fred L. Drake, Jr. fred@zope.com
Tue, 29 Jul 2003 17:54:04 -0400


Shane Hathaway writes:
 > I'm not quite sure what you're saying.  The following fails compilation:
 > 
 > <span tal:content="python: "abc"" />

That's because you've broken the syntax.  It should have been:

    <span tal:content="python: &quot;abc&quot;" />

or, more legibly,

    <span tal:content="python: 'abc'" />

I think the problem is that it's easy to think of TAL as little bits
of different syntaxes, but that's not actually what's happening.  The
syntaxes are layered on top of each other, and where there are
characters meaningful to more than one layer, they have to be encoded
so they are interpreted by the proper layer.

 > Hence you need to be careful not to use double quotes in expressions.  I 
 > run into this every day.
 > 
 > I'm a little wary of expressions like this:
 > 
 > <span tal:content="python: 1 > 0" />
 > 
 > ... being converted by buggy XML or HTML software to this (I've seen it 
 > happen before):
 > 
 > <span tal:content="python: 1 &gt; 0" />

That's not buggy; that's what you should have written to start with.

 > Finally, if you use a pair of hyphens in an expression and later use XML 
 > syntax to comment it out while leaving the pair of hyphens, the block is 
 > technically not well-formed.
 > 
 > http://www.w3.org/TR/REC-xml#sec-comments
 > 
 > For example:
 > 
 > <!--
 > <span tal:content="python: 'What should we do--walk or run?'" />
 > -->
 > 
 > This is not something that should bother anyone, but I wanted to support 
 > my assertion. ;-)

That's life.  If you change the document, you may have to change
context.  If you want to make it possible to enclose something in a
comment, you have to encode your content differently.  For the double
hyphen, encode at least one of them like so:

    <!--
    <span tal:content="python: 'What should we do&#45;-walk or run?'" />
    -->

In general, I'd recommend using a syntax-highlighting editor to help
detect this one early, or even a "proper" XML editor for those who can
tolerate them.

I hope this makes sense as I've described it.


  -Fred

-- 
Fred L. Drake, Jr.  <fred at zope.com>
PythonLabs at Zope Corporation