Edgewall Software

Opened 14 years ago

Closed 13 years ago

#3925 closed defect (fixed)

whitespace not preserved in `{{{ }}}` blocks

Reported by: Matthew Good Owned by: Christian Boos
Priority: highest Milestone: 0.11
Component: wiki system Version: devel
Severity: normal Keywords: genshi
Cc: manuzhai@… Branch:
Release Notes:
API Changes:
Internal Changes:


There's a test failure which appears to be due to whitespace not being preserved in the {{{ }}} blocks. This is possibly an issue in Genshi, though I thought it was already fixed to preserve whitespace inside <pre> elements.

FAIL: Test Unfinished code blocks
Traceback (most recent call last):
  File "/home/matt/Projects/trac/trunk/trac/wiki/tests/formatter.py", line 129, in test
    raise AssertionError( # See below for details
--------------- expected:
<pre class="wiki">number one

and block
number two
--------------- actual:
<pre class="wiki">number one
and block
number two

/home/matt/Projects/trac/trunk/trac/wiki/tests/wiki-tests.txt:413: "Unfinished code blocks" (default flavor)

Attachments (0)

Change History (15)

comment:1 by Christian Boos, 14 years ago

Severity: normalminor

That only happens with Python 2.5, AFAICT. At least, all test succeed with ActivePython 2.4.2, using [genshi 347].

I'll re-test with 2.5 on win64 later today.

comment:2 by Manuzhai, 14 years ago

Cc: manuzhai@… added

I see the same problem with Python 2.4.3 on Gentoo Linux (x86).

comment:3 by Christian Boos, 14 years ago

Ok, tried with Python 2.4.2 on Linux (x64) and I have the issue too (latest trunk of both).

comment:4 by Manuzhai, 14 years ago

That would make it (at least partly) an OS/architecture-related problem? Could have something to do with differing newlines? \r\n vs. \n, that sort of thing.

comment:5 by Christian Boos, 14 years ago

Right, on Windows, the usage of \r\n masks the problem.

The problem is that the <pre> blocks, as output by the Wiki formatter, are seen as chunks of Markup by Genshi (he, nice to have different names now ;) ). As such, the genshi.output.WhitespaceFilter will simplify the whitespace and collapse the lines. The default regexp for line collapsing is '\n{2,}', that's why the problem was not visible for me on Windows, due to the usage of os.linesep throughout trac.wiki.Formatter as the line separator.

See the __call__ method at genshi:source:trunk/genshi/output.py@351#L475.

That's one situation where it would make sense to generate XML serialization events for Genshi, when rendering a parse tree to XHTML.

comment:6 by Christian Boos, 14 years ago

Keywords: genshi added
Owner: changed from Jonas Borgström to Christian Boos

Maybe an intermediate solution would be to use the builder for the <pre> blocks.

comment:7 by Manuzhai, 14 years ago

This should get some love. It's the last failing test; the buildbots would be much nicer when this didn't always fail.

comment:8 by Christian Boos, 13 years ago

… don't forget to revert r4608 when testing this issue ;)

comment:9 by Emmanuel Blot, 13 years ago

Priority: normalhigh

Increasing a bit the priority: many people are using {{{ }}} to copy n' paste existing documents in the wiki - bypassing WikiFormatting - and all their documents have become pretty hard to read without the empty lines ;-(

comment:10 by Christian Boos, 13 years ago

Component: generalwiki

Well, it's probably about time to think about this one if we want to have it fixed for 0.11, you're right ;)

Related to #4431.

comment:12 by Christian Boos, 13 years ago

Priority: highhighest
Severity: minornormal

This is one of the main annoyance with 0.11, bumping up the priority.

comment:13 by Christopher Lenz, 13 years ago

Resolution: fixed
Status: newclosed

This should be fixed in [5586]. As I noted in the log message, a proper fix can only be achieved once the wiki formatter has been updated to emit event streams.

comment:14 by Emmanuel Blot, 13 years ago

Resolution: fixed
Status: closedreopened

Thanks a million, Chris.

I think the fix is missing here, as the wiki preview keeps removing whitespace:

Index: wiki/templates/wiki_edit.html
--- wiki/templates/wiki_edit.html       (revision 5586)
+++ wiki/templates/wiki_edit.html       (working copy)
@@ -54,7 +54,7 @@
             <div py:when="diff" class="diff">
               <xi:include href="diff_div.html" py:with="no_id=True" />
-            <div py:otherwise="" class="wikipage">${wiki_to_html(context, page.text)}</div>
+            <div py:otherwise="" class="wikipage" xml:space="preserve">${wiki_to_html(context, page.text)}</div>
         <py:when test="'collision'">

comment:15 by Christopher Lenz, 13 years ago

Resolution: fixed
Status: reopenedclosed

You're right. Should be fixed in [5587:5588].

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain Christian Boos.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Christian Boos to the specified user.

Add Comment

E-mail address and name can be saved in the Preferences .
Note: See TracTickets for help on using tickets.