Genshi strips blank lines from code if converted to HTML with Mimeview.render

33 views
Skip to first unread message

Manuel Holtgrewe

unread,
Sep 5, 2012, 8:15:13 AM9/5/12
to trac...@googlegroups.com
Dear all,

I have a problem with Mimeview.render.

I am using a macro that uses Mimeview.render to render source code with syntax highlighting using Mimeview.render.

The highlighting itself works fine, but blank lines are stripped from the source code. I think that Genshi is the culprit where blank lines are stripped from the output by default. I also think that I have tracked down the problem to the Mimeview.render function and the following line:


I guess that this is the problem since I found out about the xml:space attribute and that I have to set it to "preserve" to keep blank lines here:


Is there any way that the statement in line 791 of mimeview/api.py could be changed to preserve the blank lines? This would be great since source code can be hard to read without any intentional blank lines.

Thanks,
Manuel

RjOllos

unread,
Sep 6, 2012, 12:30:01 AM9/6/12
to trac...@googlegroups.com


On Wednesday, September 5, 2012 5:15:13 AM UTC-7, Manuel Holtgrewe wrote:
The highlighting itself works fine, but blank lines are stripped from the source code. I think that Genshi is the culprit where blank lines are stripped from the output by default. I also think that I have tracked down the problem to the Mimeview.render function and the following line:

I'm wondering how your implementation is different than, for example, the LinenoMacro (1), which doesn't seem to exhibit the issue with blank lines being stripped.

RjOllos

unread,
Sep 10, 2012, 12:14:50 AM9/10/12
to trac...@googlegroups.com
On Wednesday, September 5, 2012 5:15:13 AM UTC-7, Manuel Holtgrewe wrote:
I guess that this is the problem since I found out about the xml:space attribute and that I have to set it to "preserve" to keep blank lines here:

You could also try:

formatter.context.set_hints(preserve_newlines=True )

Manuel Holtgrewe

unread,
Sep 10, 2012, 4:42:07 AM9/10/12
to trac...@googlegroups.com
Thank you very much!

This lead me to reconsider my code (which builds upon another author's code).

The problem was that the IncludeMacro sanitizes HTML and this removed the empty lines.

I could fix my problem.

Thanks,
Manuel
Reply all
Reply to author
Forward
0 new messages