Page MenuHomePhabricator

Unwanted change of tabs to spaces on highlighted code makes it completely unaligned
Closed, ResolvedPublic

Description

The code

<syntaxhighlight lang="javascript" enclose="pre" highlight="2-3">
function doSomething() {
	var	foo,
		bar;
	if (baz) {
</syntaxhighlight>

, which use tabs for indentation, is wrongly rendered as

function doSomething() {
     var    foo,
         bar;
    if (baz) {

as you can check n the provided url.

This shouldn't happen.


Version: unspecified
Severity: normal
URL: https://secure.wikimedia.org/wikipedia/en/w/index.php?title=Wikipedia:Sandbox&oldid=450807921

Details

Reference
bz30930

Event Timeline

bzimport raised the priority of this task from to Lowest.Nov 21 2014, 11:47 PM
bzimport added a project: SyntaxHighlight.
bzimport set Reference to bz30930.
bzimport added a subscriber: Unknown Object (MLST).

It looks like the tab->space conversion is done by HTML tidy -- and it's behaving a bit differently on the <pre> as it does on the <span>s? Probably it's resetting its conversion on each element.

Probably the best way to fix this (other than turning off the damn conversion in tidy if we can) is to do our own tab->space conversion before passing things into syntax highlighting.

Though it'd be nicer still to preserve the original tabs I guess... but tidy doesn't seem to want to do that. :P

http://tidy.sourceforge.net/docs/quickref.html#tab-size says "Tidy never outputs tabs". whyyyyyyyyyyyyy

Done in r97300 -- applying the tab-to-space as a preprocess if tidy is enabled. Will need merge to 1.18 in which case it'll be in with the update deployments in the next couple weeks.

Change 98540 had a related patch set uploaded by Anomie:
Protect tabs from HTML Tidy

https://gerrit.wikimedia.org/r/98540

Change 98540 merged by jenkins-bot:
Protect tabs from HTML Tidy

https://gerrit.wikimedia.org/r/98540

matmarex set Security to None.