Edgewall Software

Ticket #78 (closed defect: fixed)

Opened 8 years ago

Last modified 3 years ago

Genshi (markup) template deletes blank lines

Reported by: jochen.kupperschmidt@… Owned by: cmlenz
Priority: major Milestone:
Component: Documentation Version: 0.3.5
Keywords: Cc:

Description

With the just released Genshi 0.3.5 the issue I described in http://genshi.edgewall.org/ticket/62#comment:7 still remains.

Is there a way to move the relevant comments here or should we copy/paste them?

Attachments

Change History

follow-up: ↓ 2   Changed 8 years ago by cmlenz

I think I see what this is about…

Pygments is returning a string that contains the <pre></pre> tags, right? And then you wrap that in a Markup object and pass it into the template?

If that is the case, the problem is the following: the removal of empty lines and trailing spaces is a feature in the serializer, and can be controlled by the strip_whitespace option. This feature does try to do the right thing by not stripping whitespace from content within <pre> and <textarea> tags. However, if the <pre> is just some text inside the Markup string, it is basically invisible to Genshi, and thus will not cause Genshi to switch to preserving whitespace.

There are some workarounds to this problem:

  • you could wrap the output in another <pre> element
  • you can wrap the output in some element that has the attribute xml:space="preserve" set, for example:
<div xml:space="preserve">${pygments_output}</div>

The optimal solution would be to get Pygments to output a Genshi stream instead of just a string, but that would of course be more work, and I'm not sure it's even possible.

in reply to: ↑ 1   Changed 8 years ago by cboos

Replying to cmlenz:

... However, if the <pre> is just some text inside the Markup string, it is basically invisible to Genshi, and thus will not cause Genshi to switch to preserving whitespace.

And as such, it's exactly the  #T3925 issue.

follow-up: ↓ 4   Changed 8 years ago by jochen.kupperschmidt@…

you could wrap the output in another <pre> element

That doesn't look like a good solution to me.

The optimal solution would be to get Pygments to output a Genshi stream instead of just a string, but that would of course be more work, and I'm not sure it's even possible.

This doesn't either. The need to modify or wrap one or more external packages to have them work with Genshi is far from user/developer friendly. Even if some package creators would provide Genshi output, others won't.

xml:space="preserve"

This does the trick and is sufficient for me so far. Thanks!

So what do you think is best to do? Just add this workaround (and maybe the others) to the docs? Or would a change/addition to the code make sense in the end?

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

Replying to jochen.kupperschmidt@not.given:

So what do you think is best to do? Just add this workaround (and maybe the others) to the docs? Or would a change/addition to the code make sense in the end?

Yeah, this should be added to the FAQ and possibly the docs (serialization is rather undocumented right now anyway). I don't see how this problem could be remedied by a change to Genshi.

BTW, I didn't mention another workaround, but that's because it'd be a bad idea performance-wise: wrap the Pygments output in XML() or HTML()... causing the text to be reparsed, and thus enabling Genshi to detect the <pre>. Just for the record, not saying it's a good idea.

  Changed 8 years ago by anonymous

  • status changed from new to closed
  • resolution set to wontfix

  Changed 8 years ago by mgood

  • status changed from closed to reopened
  • resolution wontfix deleted

Please don't close tickets without a comment.

  Changed 8 years ago by cmlenz

  • status changed from reopened to closed
  • resolution set to fixed
  • version changed from devel to 0.3.5
  • component changed from General to Documentation
  • milestone 0.4 deleted

I've added this issue to the FAQ, so this can be closed.

  Changed 5 years ago by anonymous

Test

  Changed 4 years ago by Carsten Klein <carsten.klein@…>

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

since this should have been closed and was somehow reopened, i will close it, if you don't mind.

Add/Change #78 (Genshi (markup) 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.