Edgewall Software

Opened 18 years ago

Closed 14 years ago

Last modified 13 years ago

#78 closed defect (fixed)

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?

Change History (9)

comment:1 follow-up: Changed 18 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.

comment:2 in reply to: ↑ 1 Changed 18 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.

comment:3 follow-up: Changed 18 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?

comment:4 in reply to: ↑ 3 Changed 18 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.

comment:5 Changed 18 years ago by anonymous

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

comment:6 Changed 18 years ago by mgood

  • Resolution wontfix deleted
  • Status changed from closed to reopened

Please don't close tickets without a comment.

comment:7 Changed 18 years ago by cmlenz

  • Component changed from General to Documentation
  • Milestone 0.4 deleted
  • Resolution set to fixed
  • Status changed from reopened to closed
  • Version changed from devel to 0.3.5

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

comment:8 Changed 15 years ago by anonymous

Test

comment:9 Changed 14 years ago by Carsten Klein <carsten.klein@…>

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

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

Note: See TracTickets for help on using tickets.