Edgewall Software
Modify

Opened 3 years ago

Last modified 3 years ago

#12984 new defect

Incorrect placement of line breaks inside HTML <pre> tags

Reported by: vincent.privat@… Owned by:
Priority: low Milestone:
Component: wiki system Version:
Severity: trivial Keywords:
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

Hello, We're using Trac 1.2.2.

When entering on a Wiki page:

# Running a jar
java [Java options] -jar josm-tested.jar [Program arguments]

# Launch a Web Start
javaws [run-options] -J[Java option] josm.jnlp

The resulting HTML code is:

<div class="wiki-code"><div class="code"><pre><span class="c1"># Running a jar
</span>java <span class="o">[</span>Java options<span class="o">]</span> -jar josm-tested.jar <span class="o">[</span>Program arguments<span class="o">]</span>

<span class="c1"># Launch a Web Start
</span>javaws <span class="o">[</span>run-options<span class="o">]</span> -J<span class="o">[</span>Java option<span class="o">]</span> josm.jnlp
</pre></div></div>

This causes a problem when we try to display this HTML code with Swing (https://josm.openstreetmap.de/ticket/15998) probably because the line break is inside the <span> instead of being right after it.

I think the correct HTML code should be:

<div class="wiki-code"><div class="code"><pre><span class="c1"># Running a jar</span>
java <span class="o">[</span>Java options<span class="o">]</span> -jar josm-tested.jar <span class="o">[</span>Program arguments<span class="o">]</span>

<span class="c1"># Launch a Web Start</span>
javaws <span class="o">[</span>run-options<span class="o">]</span> -J<span class="o">[</span>Java option<span class="o">]</span> josm.jnlp
</pre></div></div>

Attachments (0)

Change History (3)

comment:1 by vincent.privat@…, 3 years ago

Component: generalwiki system

It seems the behaviour is correct on this Trac instance so it might be a duplicate of another ticket fixed meanwhile.

comment:2 by anonymous, 3 years ago

Bisecting suggests it was fixed by [15418].

comment:3 by Jun Omae, 3 years ago

Priority: normallow
Severity: normaltrivial

I think that behavior is a html viewer's issue in Swing. Newlines even within span element in pre element shouldn't be ignored.

  • trac/mimeview/pygments.py

    diff --git a/trac/mimeview/pygments.py b/trac/mimeview/pygments.py
    index 4dab18e59..c45cd4d37 100644
    a b class GenshiHtmlFormatter(HtmlFormatter):  
    295295        def _generate():
    296296            for c, text in self._chunk(tokens):
    297297                if c:
    298                     attrs = Attrs([(class_, c)])
    299                     yield START, (span, attrs), pos
    300                     yield TEXT, text, pos
    301                     yield END, span, pos
     298                    for idx, t in enumerate(text.split('\n')):
     299                        if t:
     300                            attrs = Attrs([(class_, c)])
     301                            yield START, (span, attrs), pos
     302                            yield TEXT, t, pos
     303                            yield END, span, pos
     304                        if idx > 0:
     305                            yield TEXT, '\n', pos
    302306                else:
    303307                    yield TEXT, text, pos
    304308        return Stream(_generate())
Version 0, edited 3 years ago by Jun Omae (next)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The ticket will remain with no owner.
The ticket will be disowned.
as The resolution will be set. Next status will be 'closed'.
The owner will be changed from (none) to anonymous. Next status will be 'assigned'.

Add Comment


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