From 2d880650d862a116327ef08c24c9c7f5c0586797 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Tue, 12 Jan 2010 14:28:38 +0100 Subject: Finally fix whitespace and HTML problem in diff. --- inc/DifferenceEngine.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'inc/DifferenceEngine.php') diff --git a/inc/DifferenceEngine.php b/inc/DifferenceEngine.php index e28826c1f..760f1c39a 100644 --- a/inc/DifferenceEngine.php +++ b/inc/DifferenceEngine.php @@ -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('/ (?=<)|(?<=[ >]) /', ' ', $val); + return $val; + } + function _pre($text){ $text = htmlspecialchars($text); - $text = str_replace(' ','  ',$text); - if($text{0} == ' ') $text = ' '.substr($text,1); return $text; } @@ -1003,27 +1010,21 @@ class TableDiffFormatter extends DiffFormatter } function addedLine( $line ) { - $line = str_replace(' ','  ',$line); - if($line{0} == ' ') $line = ' '.substr($line,1); return '+' . $line.''; + } function deletedLine( $line ) { - $line = str_replace(' ','  ',$line); - if($line{0} == ' ') $line = ' '.substr($line,1); return '-' . $line.''; } function emptyLine() { - //$line = str_replace(' ','  ',$line); return ' '; } function contextLine( $line ) { - $line = str_replace(' ','  ',$line); - if($line{0} == ' ') $line = ' '.substr($line,1); return ' '.$line.''; } -- cgit v1.2.3