Edgewall Software
Modify

Opened 7 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@…, 7 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, 7 years ago

Bisecting suggests it was fixed by [15418].

comment:3 by Jun Omae, 7 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..890ef6f13 100644
    a b class GenshiHtmlFormatter(HtmlFormatter):  
    291291        pos = None, -1, -1
    292292        span = QName('span')
    293293        class_ = QName('class')
     294        newlines_re = re.compile(r'(\n+)')
    294295
    295296        def _generate():
    296297            for c, text in self._chunk(tokens):
    297298                if c:
    298299                    attrs = Attrs([(class_, c)])
    299                     yield START, (span, attrs), pos
    300                     yield TEXT, text, pos
    301                     yield END, span, pos
     300                    for t in newlines_re.split(text):
     301                        if t.startswith('\n'):
     302                            yield TEXT, t, pos
     303                        elif t:
     304                            yield START, (span, attrs), pos
     305                            yield TEXT, t, pos
     306                            yield END, span, pos
    302307                else:
    303308                    yield TEXT, text, pos
    304309        return Stream(_generate())
Last edited 7 years ago by Jun Omae (previous) (diff)

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.