[ZPT] Strange linebreaks

Guido van Rossum guido@digicool.com
Tue, 15 May 2001 11:08:56 -0500


> Please, could somebody explain to me how and when ZPT inserts linebreaks ?

Yes.  Everything you experience here is my fault. :-)

The original cause of this problem is that the XML and HTML parsers
don't tell the rest of the code what kind of whitespace was found
between attributes.  (They leave out a few more details, such as what
kind of quotes were used, and the XML parser even hides the difference
between <p/> and <p></p>.)

When you make an editing roundtrip in the management interface, the
system does macro-expansion (this may become an option in the future,
but it is always done for now).  Macro-expansion has to regenerate the
output from what the parser gives us, so it cannot retain the
intra-tag whitespace that was present in the source.

Originally, I simply places a single space between attributes, but for
the often long lists of attributes you get with TAL, the primitive
non-folding text editing window in the HTML form made it very
cumbersome to edit the text.  So I decided to auto-break at whitespace
in tags.  The details are all in the TALInterpreter class; the wrap
argument sets the wrapping line length (lines shorter than wrap are
never wrapped).

To turn of wrapping, you could set wrap to zero (either you can edit
TALInterpreter.py to change the default, or you can change the call to
TALInterpreter() in PageTemplate.py).

To change the wrapping algorithm (e.g. to align contination lines
flush left rather than aligning them with the end of the start tag)
you will have to change the algorithm in startTagCommon():

        align = self.col+1
        [...]
            if (self.wrap and
                self.col >= align and
                self.col + 1 + len(s) > self.wrap):
                self.stream_write("\n" + " "*align + s)

I suppose one refinement might be to do something different when align
>= self.wrap.  Can you suggest an improvement?

--Guido van Rossum (home page: http://www.python.org/~guido/)