Unexpected whitespace/newline insertion before elements with tal:repeat

Bug #229931 reported by Eleanor Berger
4
Affects Status Importance Assigned to Milestone
Zope 3
Won't Fix
Undecided
Unassigned
zope.tal
Invalid
Undecided
Unassigned

Bug Description

Contrary to the documentation, and to the expectation of users, elements with tal:repeat render with a newline and whitespace if they are the first non-whitespace test on their line in the template.

This is is not only confusing, but also makes it difficult to implement loops where there shouldn't be any whitespace between the repeated elements.

See also a discussion of the problem here: http://mail.zope.org/pipermail/zpt/2002-August/003552.html

Tags: tech-debt
Revision history for this message
Fred Drake (fdrake) wrote : Re: [Bug 229931] [NEW] Unexpected whitespace/newline insertion before elements with tal:repeat

If I recall correctly, this was done so that generated HTML "looked
right" when viewed as source. I don't know the source of this
requirement.

Revision history for this message
Tim Penhey (thumper) wrote :

"looking right" is obviously a very subjective idea. I'm currently wrestling with TAL and repeat in order to not get extra whitespace (before a comma in the output).

Revision history for this message
Fred Drake (fdrake) wrote : Re: [Bug 229931] Re: Unexpected whitespace/newline insertion before elements with tal:repeat

On Sun, Feb 15, 2009 at 1:12 PM, Tim Penhey <email address hidden> wrote:
> "looking right" is obviously a very subjective idea. I'm currently
> wrestling with TAL and repeat in order to not get extra whitespace
> (before a comma in the output).

I don't disagree; the decision wasn't mine.

  -Fred

--
Fred L. Drake, Jr. <fdrake at gmail.com>
"Chaos is the score upon which reality is written." --Henry Miller

Curtis Hovey (sinzui)
tags: added: tech-debt
Tres Seaver (tseaver)
Changed in zope3:
status: New → Won't Fix
Revision history for this message
Anthony Gerrard (anthonygerrard+launchpad-net) wrote :

I just raised a chameleon issue asking for the same thing

https://github.com/malthe/chameleon/issues/110

Revision history for this message
Cong Do (codo) wrote :

I can't believe that i have to edit the library and it's my first day working with zope.
I mean at least give some option to turn off the whitespace and newline.

The impact of this bugs effect every page that use css display:inline and display:inline-block. Since the newline with display on the browser as a space.

Here is a hack for anyone having issue and zope are unwilling to help.
Quick work around is to edit program.py
change
            self._whitespace = "" + "" * len(self._last.rsplit('\n', 1)[-1])
to
            self._whitespace = ""

To add a tal command to prevent the white space in program.py
find
        # Remember whitespace for item repetition
        if self._last is not None:
            self._whitespace = "\n" + " " * len(self._last.rsplit('\n', 1)[-1])

and replace with
        try:
            whitespace = ns[TAL,'whitespace'].lower() != "false"
        except KeyError:
            whitespace = True

        # Remember whitespace for item repetition
        if self._last is not None and whitespace:
            self._whitespace = "\n" + " " * len(self._last.rsplit('\n', 1)[-1])
        else:
            self._whitespace = ""

and modified WHITELIST in tal.py to include "whitespace"

Revision history for this message
Tres Seaver (tseaver) wrote :

If you'd like to see this change land, please:

- Fork the zope.tal repository on Github: https://github.com/zopefoundation/zope.tal

- Clone your fork, and apply your changes there.

- Add tests which exercise the new behavior.

- Add a CHANGES.txt entry for the change.

- Push your changes back to Git

- Submit a pull request: I will review it.

Revision history for this message
Colin Watson (cjwatson) wrote :

The zope.tal project on Launchpad has been archived at the request of the Zope developers (see https://answers.launchpad.net/launchpad/+question/683589 and https://answers.launchpad.net/launchpad/+question/685285). If this bug is still relevant, please refile it at https://github.com/zopefoundation/zope.tal.

Changed in zope.tal:
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.