} else {
$abase = md5(join("\n", $input));
}
- //echo '<pre>' . implode("\n", $input);exit;
- $html = "<code><table class='code diff'>";
- //$html = "<pre class='code diff'>";
-
+
+ $ret = array();
+
while (true) {
+
+
if (!count($input)) {
break;
}
+
$line = array_shift($input);
$nlines++;
+
if (!strncmp($line, '@@ ', 3)) {
/* done with preamble */
break;
}
- $html .= "<tr class='meta'><td class='lineno'></td>".
- "<td class='lineno'></td><td class='lineno'></td><td width='100%'>".
- htmlspecialchars($line, ENT_QUOTES, 'utf-8') .
- '</tr>';
+ $ret[] = (object)array(
+
+ 'line' => $line,
+ 'meta' => true,
+ 'cls' =>'meta'
+
+ );
+
}
$class = 'meta';
$lines = array(0, 0);
$first = false;
+
+ $in_meta = false;
+
while (true) {
$class = 'unmod';
$lines[1] = (int)$M[2] - 1;
$class = 'meta';
$first = true;
+ $in_meta = false;
} else if (preg_match("/^diff /", $line)) {
- $class = 'head';
-
+ $class = 'meta';
+ $in_meta=true;
} elseif (strlen($line)) {
if ($line[0] == '-') {
}
- $row = "<tr class='$class";
- if ($first) {
- $row .= ' first';
+ if ($in_meta) {
+ $class = 'meta';
}
+ $cls = $class;
+
+ if ($first) {
+ $cls .= ' first';
+ } else
if ($class != 'meta' && $first) {
$first = false;
}
- $row .= "'>";
+
$anchor = $abase . '.' . $nlines;
- $anchor_row = "<td class='linelink'><a name='$anchor'></a>".
- "<a href='#$anchor' title='link to this line'>#</a></td>";
-
- $txt_data = '<td class="line" width="100%">'.
- htmlspecialchars($line, ENT_QUOTES, 'utf-8') .
- "</td></tr>\n";
-
- switch ($class) {
- case 'head':
- $line_info = '';
- $row .= '<td colspan="4" class="line" width="100%">' .
- htmlspecialchars($line, ENT_QUOTES, 'utf-8') . "</td></tr>\n";
- $html .= $row;
-
- break;
-
- case 'meta':
- $line_info = '';
- $row .= '<td colspan="4" class="line" width="100%">' .
- htmlspecialchars($line, ENT_QUOTES, 'utf-8') . "</td></tr>\n";
- $html .= $row;
- break;
+ $add = (object)array(
- case 'added':
- $row .= "<td class='lineno'></td><td class='lineno'>" .
- $lines[1] . "</td>" .
- $anchor_row . $txt_data ;
- $html .= $row;
-
- break;
-
- case 'removed':
- $row .= "<td class='lineno'>" . $lines[0] .
- "</td><td class='lineno'></td>" .
- $anchor_row . $txt_data ;
- $html .= $row;
-
- break;
-
- default:
- $row .= "<td class='lineno'>" . $lines[0] .
- "</td><td class='lineno'>" . $lines[1] . "</td>" .
- $anchor_row . $txt_data ;
- $html .= $row;
- }
+ 'line' => $class == 'meta' ? $line : substr($line, 1),
+ 'meta' => $class == 'meta',
+ 'cls' => $cls,
+ 'anchor' => $class == 'meta' ? $anchor : false
+ );
+
+ $add->$class = true;
+ $ret[] = $add;
if (!count($input)) {
}
if ($nlines == 0) {
- return null;
+ return null;
}
- $html .= "</table>";
- return $html;
+ return $ret;
}
}