Edgewall Software

Opened 17 years ago

Closed 17 years ago

#133 closed defect (fixed)

Linebreaks handling in TextTemplate (sth like #slurp in cheetah)

Reported by: Marcin.Kasperski@… Owned by: cmlenz
Priority: minor Milestone: 0.5
Component: Template processing Version: 0.4.2
Keywords: Cc:

Description

It seems to me that there is currently no way to avoid linebreak after template directive. This is bad, there are cases when one wants to - say - write #if to generate a few words within sentence. And in plain text linebreaks matter....

Cheetah uses #slurp to eat the following linebreak. It also allows one to embed directive within some line.

For genshi, maybe one could consider simpler solution: do not generate newlines on normal newlines, but on double-newlines? In other words, work like LaTeX, wiki formatter, structured text and many other tools...

Whatever solution would be considered, here is the simple use case. We are to write a template which gets two parameters: boys_count and girls_count. It should return one of the following (or sth similar):

Participants: 1 boy and 3 girls.

Participants: 7 boys and no girls.

Participants: no boys and 1 girl.

Which genshi template would you suggest?

Change History (3)

comment:1 Changed 17 years ago by cmlenz

  • Component changed from General to Template processing

This is definitely a valid concern. In retrospect, I think we should have gone with a directive syntax more like Django's, which doesn't interpret line breaks in any special way. The ways Cheetah/Velocity? have to work around the problems originating in this design are pretty ugly.

comment:2 Changed 17 years ago by anonymous

I experimented with one workaround: writing postprocess filter which replaced individual linebreaks with spaces, while replacing multiple consecutive linebreaks with single break. It more or less worked, but I am not sure whether this is the natural way....

comment:3 Changed 17 years ago by cmlenz

  • Resolution set to fixed
  • Status changed from new to closed

Trunk has a new text template syntax that allows much more control over white-space and line-breaks. See the updated Text Template Language document. While this language will not be the default for 0.5 (we need to provide a reasonable migration path), it will be available, and will replace the old language in a subsequent release.

Note: See TracTickets for help on using tickets.