Edgewall Software

Ticket #3925 (closed defect: fixed)

Opened 2 years ago

Last modified 15 months ago

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

Reported by: mgood Owned by: cboos
Priority: highest Milestone: 0.11
Component: wiki system Version: devel
Severity: normal Keywords: genshi
Cc: manuzhai@…

Description

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
AssertionError:
--------------- expected:
<p>
Block
</p>
<pre class="wiki">number one

and block
{{{
number two
 }}
}}}
</pre>
--------------- actual:
<p>
Block
</p>
<pre class="wiki">number one
and block
{{{
number two
 }}
}}}
</pre>
---------------


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

Attachments

Change History

Changed 2 years ago by cboos

  • severity changed from normal to minor

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.

Changed 2 years ago by Manuzhai

  • cc manuzhai@… added

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

Changed 2 years ago by cboos

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

Changed 2 years ago by Manuzhai

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.

Changed 2 years ago by cboos

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.

Changed 23 months ago by cboos

  • keywords genshi added
  • owner changed from jonas to cboos

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

Changed 21 months ago by Manuzhai

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

Changed 20 months ago by cboos

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

Changed 20 months ago by eblot

  • priority changed from normal to high

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 ;-(

Changed 20 months ago by cboos

  • component changed from general to wiki

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.

Changed 17 months ago by cboos

  • priority changed from high to highest
  • severity changed from minor to normal

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

Changed 15 months ago by cmlenz

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

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.

Changed 15 months ago by eblot

  • status changed from closed to reopened
  • resolution fixed deleted

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>
-            <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>
           </fieldset>
         </py:when>
         <py:when test="'collision'">

Changed 15 months ago by cmlenz

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

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

Add/Change #3925 (whitespace not preserved in `{{{ }}}` blocks)

Author



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