Index: DiffEngine.php =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/diff/DiffEngine.php,v retrieving revision 1.1.4.1 diff -U3 -r1.1.4.1 DiffEngine.php --- DiffEngine.php 6 Jun 2007 18:14:25 -0000 1.1.4.1 +++ DiffEngine.php 7 Dec 2007 22:02:10 -0000 @@ -1119,3 +1119,137 @@ } } } + +/** + * Diff formatter which uses Drupal theme functions. + * @private + * @subpackage DifferenceEngine + */ +class DrupalDiffFormatter extends DiffFormatter +{ + + var $rows; + + function DrupalDiffFormatter() { + $this->leading_context_lines = 2; + $this->trailing_context_lines = 2; + } + + function _start_diff() { + $this->rows = array(); + } + + function _end_diff() { + return $this->rows; + } + + function _block_header( $xbeg, $xlen, $ybeg, $ylen ) { + return array( + array( + 'data' => '' . t('Line %nr', array('%nr' => $xbeg)) . '', + 'colspan' => 2 + ), + array( + 'data' => '' . t('Line %nr', array('%nr' => $ybeg)) . '', + 'colspan' => 2 + ) + ); + } + + function _start_block( $header ) { + if ($this->show_header) { + $this->rows[] = $header; + } + } + + function _end_block() { + } + + function _lines( $lines, $prefix=' ', $color='white' ) { + } + + /** + * Note: you should HTML-escape parameter before calling this. + */ + function addedLine($line) { + return array( + array( + 'data' => '+', + ), + array( + 'data' => $line, + 'class' => 'diff-addedline' + ) + ); + } + + /** + * Note: you should HTML-escape parameter before calling this. + */ + function deletedLine($line) { + return array( + array( + 'data' => '-', + ), + array( + 'data' => $line, + 'class' => 'diff-deletedline', + ) + ); + } + + /** + * Note: you should HTML-escape parameter before calling this. + */ + function contextLine($line) { + return array( + ' ', + array( + 'data' => $line, + 'class' => 'diff-context', + ) + ); + } + + function emptyLine() { + return array( + ' ', + ' ' + ); + } + + function _added($lines) { + foreach($lines as $line) { + $this->rows[] = array_merge($this->emptyLine(), $this->addedLine(check_plain($line))); + } + } + + function _deleted($lines) { + foreach($lines as $line) { + $this->rows[] = array_merge($this->deletedLine(check_plain ($line)), $this->emptyLine()); + } + } + + function _context($lines) { + foreach($lines as $line) { + $this->rows[] = array_merge($this->contextLine(check_plain ($line)), $this->contextLine(check_plain($line))); + } + } + + function _changed($orig, $closing) { + $diff = new WordLevelDiff($orig, $closing); + $del = $diff->orig(); + $add = $diff->closing(); + + // Notice that WordLevelDiff returns HTML-escaped output. + // Hence, we will be calling addedLine/deletedLine without HTML-escaping. + + while ($line = array_shift($del)) { + $aline = array_shift( $add ); + $this->rows[] = array_merge($this->deletedLine($line), $this->addedLine($aline)); + } + foreach ($add as $line) { // If any leftovers + $this->rows[] = array_merge($this->emptyLine(), $this->addedLine($line)); + } + } +} Index: diff.css =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/diff/diff.css,v retrieving revision 1.2.2.3 diff -U3 -r1.2.2.3 diff.css --- diff.css 31 Jan 2007 18:05:55 -0000 1.2.2.3 +++ diff.css 7 Dec 2007 22:02:10 -0000 @@ -4,6 +4,10 @@ width: 100%; margin-bottom: 20px; } +table.diff tr.even, table.diff tr.odd { + background-color: inherit; + border: none; +} td.diff-prevlink { text-align: left; } Index: diff.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/diff/diff.module,v retrieving revision 1.8.2.8 diff -U3 -r1.8.2.8 diff.module --- diff.module 6 Jun 2007 18:14:25 -0000 1.8.2.8 +++ diff.module 7 Dec 2007 22:02:10 -0000 @@ -320,16 +320,43 @@ $prev_link = ''; } - // display table - $output .= '
| '. $old_header .' | '. $new_header .' | ||
|---|---|---|---|
| '. $old_log .' | '. $new_log .' | ||
| '. $prev_link .' | '. $next_link .' |