Edgewall Software

Opened 20 years ago

Closed 20 years ago

Last modified 12 years ago

#62 closed defect (fixed)

Genshi text template deletes blank lines

Reported by: talin@… Owned by: cmlenz
Priority: minor Milestone: 0.3.5
Component: Template processing Version: 0.3.3
Keywords: text template Cc: martin.kaffanke@…

Description (last modified by cmlenz)

In the example below, there is a blank line in the original template between "hello" and "world", however the output has them on adjacent lines. This makes it hard to do things like SMTP messages, where a blank line is required between the headers and the body :)

>>> from genshi.template import TextTemplate
>>> template = """hello
...
... world"""
>>> print TextTemplate( template ).generate()
hello
world
>>>

Change History (11)

comment:1 Changed 20 years ago by cmlenz

  • Component changed from General to Template processing
  • Description modified (diff)
  • Version changed from 0.2 to 0.3.1

(fixed description)

Can you please try:

>>> stream = TextTemplate(template).generate()
>>> print stream.render('text', strip_whitespace=False)

comment:2 Changed 20 years ago by cmlenz

#64 has been marked as a duplicate of this ticket.

comment:3 Changed 20 years ago by martin.kaffanke@…

  • Cc martin.kaffanke@… added
  • Version changed from 0.3.1 to 0.3.3

This does not work for me:

loader = TemplateLoader([config.templatedir])
tmpl = loader.load('emails/stellennotify.genshi.txt', cls=TextTemplate)
stream = tmpl.generate(data=data, userdata=userdata)
msg = stream.render('text', strip_whitespace=False)

Brings up this error:

Traceback (most recent call last):
  File "./send_notifications.py", line 90, in ?
    msg = stream.render('text', strip_whitespace=False)
  File "build/bdist.linux-i686/egg/genshi/core.py", line 140, in render
  File "build/bdist.linux-i686/egg/genshi/core.py", line 180, in serialize
TypeError: default __new__ takes no parameters

am I missing something?

Thanks, Martin

comment:4 Changed 20 years ago by cmlenz

Oops, my fault. The strip_whitespace parameter is not needed (nor is it supported if the output method is "text").

So, the following should work:

loader = TemplateLoader([config.templatedir])
tmpl = loader.load('emails/stellennotify.genshi.txt', cls=TextTemplate)
stream = tmpl.generate(data=data, userdata=userdata)
msg = stream.render('text')

I've been thinking about adding an affinity of streams to specifc output methods, so that rendering a text template would default to the "text" method, whereas rendering a markup template would default to "xml".

comment:5 follow-up: Changed 20 years ago by anonymous

As far as I can see you simple removed the strip_whitespace paremeter. So then we are back at the bug #64 where I told you that this does not work for

See this data:

#for item in data
  * ${item['Name']}
    http://www.somewhere.com/?id=${item['id']}

#end

Where some Lines get removed which I would like to have inside my email. It's interesting that it works on an other place, but not on the #for thing.

comment:6 in reply to: ↑ 5 Changed 20 years ago by cmlenz

  • Milestone set to 0.4
  • Status changed from new to assigned

Replying to anonymous:

As far as I can see you simple removed the strip_whitespace paremeter. So then we are back at the bug #64 where I told you that this does not work for

Note that I still added the “text” parameter to the render() invocation ;)

Anyway, I can reproduce this issue now and will look into it.

comment:7 follow-up: Changed 20 years ago by jochen.kupperschmidt@…

I stumpled upon this issue today while switching the source code highlighter my site uses from Fredrik Lundh's code colorizer to ​Pygments. The latter returns blank lines as multiple \n inside the all-embracing <pre> element. That caused me some headaches until I isolated Genshi as bad boy: While the newlines are available in variables passed to the template, trying to output them strips them down to one single newline.

Example:

<p>${'hello\n\n\nworld'}</p>

Is rendered as:

<p>hallo
peter</p>

Which is definitely seriously bad.

comment:8 in reply to: ↑ 7 ; follow-up: Changed 20 years ago by cmlenz

Replying to jochen.kupperschmidt@not.given:

I stumpled upon this issue today while switching the source code highlighter my site uses from Fredrik Lundh's code colorizer to ​Pygments. The latter returns blank lines as multiple \n inside the all-embracing <pre> element. That caused me some headaches until I isolated Genshi as bad boy: While the newlines are available in variables passed to the template, trying to output them strips them down to one single newline.

I think this is a different issue, likely a bug in the WhitespaceFilter. Which serialization method are you using?

comment:9 in reply to: ↑ 8 Changed 20 years ago by anonymous

Replying to cmlenz:

I think this is a different issue, likely a bug in the WhitespaceFilter. Which serialization method are you using?

I use some_stream.render('xhtml', 'iso-8859-1').

Feel free to create another ticket if reasonable.

comment:10 Changed 20 years ago by cmlenz

  • Milestone changed from 0.4 to 0.3.5

comment:11 Changed 20 years ago by cmlenz

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

Fixed in [445], ported to 0.3.x in [450].

Note: See TracTickets for help on using tickets.