Modify ↓
Opened 7 years ago
Last modified 2 years ago
#12984 new defect
Incorrect placement of line breaks inside HTML <pre> tags
Reported by: | 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 , 7 years ago
Component: | general → wiki system |
---|
comment:3 by , 7 years ago
Priority: | normal → low |
---|---|
Severity: | normal → trivial |
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): 291 291 pos = None, -1, -1 292 292 span = QName('span') 293 293 class_ = QName('class') 294 newlines_re = re.compile(r'(\n+)') 294 295 295 296 def _generate(): 296 297 for c, text in self._chunk(tokens): 297 298 if c: 298 299 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 302 307 else: 303 308 yield TEXT, text, pos 304 309 return Stream(_generate())
Note:
See TracTickets
for help on using tickets.
It seems the behaviour is correct on this Trac instance so it might be a duplicate of another ticket fixed meanwhile.