[ZPT] Re: whitespace bug

Evan Simpson evan@4-am.com
Wed, 27 Nov 2002 13:26:17 -0600


Just to give you guys a quick bit of background rationale on the whole 
whitespace-behaviour thing:

Early on in TAL's implementation, somebody or other expressed concern 
about the aesthetic, as opposed to functional, effects of whitespace in 
generated text.  In response to this, Guido and Fred were careful to try 
to preserve whitespace where that seemed reasonable, wrap long lines 
without affecting rendering, etc.

The problem under discussion is specific to tal:repeat, and is a side 
effect of the effort to have template code like this:

<ul>
   <li tal:repeat="fruit basket" tal:content="fruit"></li>
</ul>

...produce text like this:

<ul>
   <li>Orange</li>
   <li>Apple</li>
   <li>Pear</li>
</ul>

...rather than this:

<ul>
   <li>Orange</li><li>Apple</li><li>Pear</li>
</ul>

In order to accomplish this, tal:repeat's semantics have been bent and 
slightly fractured -- it not only repeats the tag, but also all of the 
tag's leading whitespace.  The dummy enclosing tag trick eliminates the 
whitespace, but so does this code:

   X<span tal:repeat="fruit basket" tal:content="fruit"></span>

...which produces:

   X<span>Orange</span><span>Apple</span><span>Pear</span>

Cheers,

Evan @ 4-am