Edgewall Software

Ticket #62 (closed defect: fixed)

Opened 8 years ago

Last modified 6 years ago

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) (diff)

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
>>>

Attachments

Change History

  Changed 8 years ago by cmlenz

  • version changed from 0.2 to 0.3.1
  • component changed from General to Template processing
  • description modified (diff)

(fixed description)

Can you please try:

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

  Changed 8 years ago by cmlenz

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

  Changed 8 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

  Changed 8 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".

follow-up: ↓ 6   Changed 8 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.

in reply to: ↑ 5   Changed 8 years ago by cmlenz

  • status changed from new to assigned
  • milestone set to 0.4

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.

follow-up: ↓ 8   Changed 7 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.

in reply to: ↑ 7 ; follow-up: ↓ 9   Changed 7 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?

in reply to: ↑ 8   Changed 7 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.

  Changed 7 years ago by cmlenz

  • milestone changed from 0.4 to 0.3.5

  Changed 7 years ago by cmlenz

  • status changed from assigned to closed
  • resolution set to fixed

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

Add/Change #62 (Genshi text template deletes blank lines)

Author


E-mail address and user name can be saved in the Preferences.


Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
 
Note: See TracTickets for help on using tickets.