Skip to content
Snippets Groups Projects
Commit 2d880650 authored by Adrian Lang's avatar Adrian Lang
Browse files

Finally fix whitespace and HTML problem in diff.

parent 21ed6025
No related branches found
No related tags found
No related merge requests found
......@@ -976,10 +976,17 @@ class TableDiffFormatter extends DiffFormatter
$this->trailing_context_lines = 2;
}
function format($diff) {
// Preserve whitespaces by converting some to non-breaking spaces.
// Do not convert all of them to allow word-wrap.
$val = parent::format($diff);
$val = str_replace(' ','  ', $val);
$val = preg_replace('/ (?=<)|(?<=[ >]) /', '&nbsp;', $val);
return $val;
}
function _pre($text){
$text = htmlspecialchars($text);
$text = str_replace(' ',' &nbsp;',$text);
if($text{0} == ' ') $text = '&nbsp;'.substr($text,1);
return $text;
}
......@@ -1003,27 +1010,21 @@ class TableDiffFormatter extends DiffFormatter
}
function addedLine( $line ) {
$line = str_replace(' ',' &nbsp;',$line);
if($line{0} == ' ') $line = '&nbsp;'.substr($line,1);
return '<td>+</td><td class="diff-addedline">' .
$line.'</td>';
}
function deletedLine( $line ) {
$line = str_replace(' ',' &nbsp;',$line);
if($line{0} == ' ') $line = '&nbsp;'.substr($line,1);
return '<td>-</td><td class="diff-deletedline">' .
$line.'</td>';
}
function emptyLine() {
//$line = str_replace(' ','&nbsp; ',$line);
return '<td colspan="2">&nbsp;</td>';
}
function contextLine( $line ) {
$line = str_replace(' ',' &nbsp;',$line);
if($line{0} == ' ') $line = '&nbsp;'.substr($line,1);
return '<td> </td><td class="diff-context">'.$line.'</td>';
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment