summaryrefslogtreecommitdiff
path: root/inc/DifferenceEngine.php
diff options
context:
space:
mode:
authorAdrian Lang <lang@cosmocode.de>2010-01-12 14:28:38 +0100
committerAdrian Lang <lang@cosmocode.de>2010-01-12 14:35:12 +0100
commit2d880650d862a116327ef08c24c9c7f5c0586797 (patch)
tree93f4b13d754a6a22449562cbab3a0c06df5ee4fa /inc/DifferenceEngine.php
parent21ed602531cbceff3e92e4ac33484f44ed2b6848 (diff)
downloadrpg-2d880650d862a116327ef08c24c9c7f5c0586797.tar.gz
rpg-2d880650d862a116327ef08c24c9c7f5c0586797.tar.bz2
Finally fix whitespace and HTML problem in diff.
Diffstat (limited to 'inc/DifferenceEngine.php')
-rw-r--r--inc/DifferenceEngine.php19
1 files changed, 10 insertions, 9 deletions
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(' ','&nbsp; ', $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>';
}