function DrupalDiffInline::render in Diff 7.3
Same name and namespace in other branches
- 6.2 DiffEngine.php \DrupalDiffInline::render()
- 7.2 DiffEngine.php \DrupalDiffInline::render()
Render differences inline using HTML markup.
File
- ./
DiffEngine.php, line 1251 - A PHP diff engine for phpwiki. (Taken from phpwiki-1.3.3)
Class
- DrupalDiffInline
- Drupal inline Diff formatter. @private @subpackage DifferenceEngine
Code
function render() {
$a = preg_split('/(<[^>]+?>| )/', $this->a, -1, PREG_SPLIT_DELIM_CAPTURE);
$b = preg_split('/(<[^>]+?>| )/', $this->b, -1, PREG_SPLIT_DELIM_CAPTURE);
$diff = new Diff($a, $b);
$diff->edits = $this
->process_edits($diff->edits);
// Assemble highlighted output
$output = '';
foreach ($diff->edits as $chunk) {
switch ($chunk->type) {
case 'copy':
$output .= implode('', $chunk->closing);
break;
case 'delete':
foreach ($chunk->orig as $i => $piece) {
if (strpos($piece, '<') === 0 && drupal_substr($piece, drupal_strlen($piece) - 1) === '>') {
$output .= $piece;
}
else {
$output .= theme('diff_inline_chunk', array(
'text' => $piece,
'type' => $chunk->type,
));
}
}
break;
default:
$chunk->closing = $this
->process_chunk($chunk->closing);
foreach ($chunk->closing as $i => $piece) {
if ($piece === ' ' || strpos($piece, '<') === 0 && drupal_substr($piece, drupal_strlen($piece) - 1) === '>' && drupal_strtolower(drupal_substr($piece, 1, 3)) != 'img') {
$output .= $piece;
}
else {
$output .= theme('diff_inline_chunk', array(
'text' => $piece,
'type' => $chunk->type,
));
}
}
break;
}
}
return $output;
}