Edgewall Software

Ticket #78 (closed defect: fixed)

Opened 18 months ago

Last modified 2 weeks 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 18 months 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 18 months 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 18 months 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 18 months 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 16 months ago by anonymous

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

  Changed 16 months ago by mgood

  • status changed from closed to reopened
  • resolution deleted

Please don't close tickets without a comment.

  Changed 16 months 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 deleted

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

Add/Change #78 (Genshi (markup) template deletes blank lines)

Author



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