Edgewall Software

Opened 17 years ago

Closed 17 years ago

Last modified 16 years ago

#1691 closed defect (fixed)

Escape tabs in HTML preview of files

Reported by: jyrki@… Owned by: Christopher Lenz
Priority: normal Milestone: 0.9
Component: version control/browser Version: devel
Severity: normal Keywords: enscript white-space css
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:


Displaying files where leading (or trailing) white-space matters is broken with the current development version. For example viewing Makefiles is broken because of this.

Adding "white-space: pre;" line to code.css's "table.code-block tbody td" block fixes the problem.

I'm currently using enscript for code highlighting. I'm not sure if the problem exists with silvercity.

Attachments (0)

Change History (9)

comment:1 by Christopher Lenz, 17 years ago

Milestone: 0.9
Owner: changed from Jonas Borgström to Christopher Lenz
Status: newassigned

The spaces should be replaced by non-breaking spaces. The problem with white-space: pre is that it completely disables line-breaks. If white-space: pre-wrap were better supported, we'd use that. Unfortunately, it isn't.

Can you please paste a snippet of the generated HTML? Maybe it's the tabs that are messing up the display?

comment:2 by Christian Boos, 17 years ago

On a related note, when no highlighter is used, the display of C/C++ files containing tabs is indeed messed up (a tab should be replaced by the appropriate number of &nbsp;<space> pairs).

comment:3 by jyrki@…, 17 years ago

Here's the output from enscript, leading tab characters in the rm lines

<B><FONT COLOR="#A020F0">clean-state:</FONT></B>
	-rm -f $(<B><FONT COLOR="#5F9EA0">STATEDIR</FONT></B>)/*

<B><FONT COLOR="#A020F0">clean-state-%:</FONT></B>
	-rm -f $(<B><FONT COLOR="#5F9EA0">STATEDIR</FONT></B>)/$*

And here's the Trac's output, also has tab characters in front of "-rm -f …"

<tr><th id="l75">75</th>
<td>	-rm -f $(<B><span class="code-keyword">STATEDIR</span></B>)/*</td>
</tr><tr><th id="l76">76</th>
</tr><tr><th id="l77">77</th>

<td><B><span class="code-lang">clean-state-%:</span></B></td>
</tr><tr><th id="l78">78</th>
<td>	-rm -f $(<B><span class="code-keyword">STATEDIR</span></B>)/$*</td>

Now that I think of it, it is true that "white-space: pre;" doesn't allow line wrapping. But replacing every tab character with a static amount of (non-breaking) spaces isn't the right solution either.

comment:4 by Christopher Lenz, 17 years ago

But replacing every tab character with a static amount of (non-breaking) spaces isn't the right solution either.

Why? Or, what would be the right solution?

comment:5 by jyrki@…, 17 years ago

IMHO, it's better to let the long lines be long. An overkill solution would be to calculate the right amount of spaces to insert. For example in the following expand tabs to 5 and 4 spaces


foo     bar
xyzz    asdf

And well, there is a way to do it in CSS, but it's a butt ugly solution too. Check the first code block of this blog entry (has some other good points of CSS's white-space stuff too).

comment:6 by Christopher Lenz, 17 years ago

Python has a string.expandtabs() function built right in, so it's not overkill to implement properly.

comment:7 by jyrki@…, 17 years ago

Oh, I'm impressed. Well that's the cleanest solution then.

comment:8 by Christopher Lenz, 17 years ago

Summary: code.css should have "white-space: pre;" in code-block cellsEscape tabs in HTML preview of files

comment:9 by Christopher Lenz, 17 years ago

Resolution: fixed
Status: assignedclosed

Actually, tabs were already being replaced with spaces, but the number of spaces were not configurable.

[1944] adds this configurability. In trac.ini, you can say:

tab_width = 4

to configure a displayed tab width of 4.

Anyway, I'm not sure whether this fixes the issue raised in this ticket, as I had suspected that tabs were not getting escaped, when in fact they were. Reopen if you're still seeing a problem here.

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain Christopher Lenz.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Christopher Lenz 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.