Diff.php
authorAlan Knowles <alan@akbkhome.com>
Sat, 27 Oct 2012 13:52:26 +0000 (21:52 +0800)
committerAlan Knowles <alan@akbkhome.com>
Sat, 27 Oct 2012 13:52:26 +0000 (21:52 +0800)
Diff.php

index 22e0c3e..4b878b4 100644 (file)
--- a/Diff.php
+++ b/Diff.php
@@ -30,94 +30,94 @@ class Pman_MTrack_Diff extends Pman {
             $abase = md5(join("\n", $input));
         }
 
-  /* we could use toggle() below, but it is much faster to determine
-   * if we are hiding or showing based on a single variable than evaluating
-   * that for each possible cell */
-   $html = "<table class='code diff'>";
-  //$html = "<pre class='code diff'>";
-
-  while (true) {
-    if (!count($input)) {
-      break;
-    }
-    $line = array_shift($input);
-    $nlines++;
-    if (!strncmp($line, '@@ ', 3)) {
-      /* done with preamble */
-      break;
-    }
-    $line = htmlspecialchars($line, ENT_QUOTES, 'utf-8');
-    $line = "<tr class='meta'><td class='lineno'></td><td class='lineno'></td><td class='lineno'></td><td width='100%'>$line</tr>";
-    $html .= $line . "\n";
-  }
-
-  $lines = array(0, 0);
-  $first = false;
-  while (true) {
-    $class = 'unmod';
-
-    if (preg_match("/^@@\s+-(\pN+)(?:,\pN+)?\s+\+(\pN+)(?:,\pN+)?\s*@@/",
-        $line, $M)) {
-      $lines[0] = (int)$M[1] - 1;
-      $lines[1] = (int)$M[2] - 1;
-      $class = 'meta';
-      $first = true;
-    } elseif (strlen($line)) {
-      if ($line[0] == '-') {
-        $lines[0]++;
-        $class = 'removed';
-      } elseif ($line[0] == '+') {
-        $lines[1]++;
-        $class = 'added';
-      } else {
-        $lines[0]++;
-        $lines[1]++;
-      }
-    } else {
-      $lines[0]++;
-      $lines[1]++;
-    }
-    $row = "<tr class='$class";
-    if ($first) {
-      $row .= ' first';
-    }
-    if ($class != 'meta' && $first) {
-      $first = false;
-    }
-    $row .= "'>";
-
-    switch ($class) {
-      case 'meta':
-        $line_info = '';
-        $row .= "<td class='lineno'></td><td class='lineno'></td>";
-        break;
-      case 'added':
-        $row .= "<td class='lineno'></td><td class='lineno'>" . $lines[1] . "</td>";
-        break;
-      case 'removed':
-        $row .= "<td class='lineno'>" . $lines[0] . "</td><td class='lineno'></td>";
-        break;
-      default:
-        $row .= "<td class='lineno'>" . $lines[0] . "</td><td class='lineno'>" . $lines[1] . "</td>";
-    }
-    $anchor = $abase . '.' . $nlines;
-    $row .= "<td class='linelink'><a name='$anchor'></a><a href='#$anchor' title='link to this line'>#</a></td>";
-
-    $line = htmlspecialchars($line, ENT_QUOTES, 'utf-8');
-    $row .= "<td class='line' width='100%'>$line</td></tr>\n";
-    $html .= $row;
-
-    if (!count($input)) {
-      break;
-    }
-    $line = array_shift($input);
-    $nlines++;
-  }
-
-  if ($nlines == 0) {
-    return null;
-  }
-
-  $html .= "</table>";
-  return $html;
+        $html = "<table class='code diff'>";
+            //$html = "<pre class='code diff'>";
+          
+        while (true) {
+            if (!count($input)) {
+                break;
+            }
+            $line = array_shift($input);
+            $nlines++;
+            if (!strncmp($line, '@@ ', 3)) {
+                /* done with preamble */
+                break;
+            }
+            $line = 
+            $line = "<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>';
+            $html .= $line . "\n";
+        }
+          
+            $lines = array(0, 0);
+            $first = false;
+            while (true) {
+              $class = 'unmod';
+          
+              if (preg_match("/^@@\s+-(\pN+)(?:,\pN+)?\s+\+(\pN+)(?:,\pN+)?\s*@@/",
+                  $line, $M)) {
+                $lines[0] = (int)$M[1] - 1;
+                $lines[1] = (int)$M[2] - 1;
+                $class = 'meta';
+                $first = true;
+              } elseif (strlen($line)) {
+                if ($line[0] == '-') {
+                  $lines[0]++;
+                  $class = 'removed';
+                } elseif ($line[0] == '+') {
+                  $lines[1]++;
+                  $class = 'added';
+                } else {
+                  $lines[0]++;
+                  $lines[1]++;
+                }
+              } else {
+                $lines[0]++;
+                $lines[1]++;
+              }
+              $row = "<tr class='$class";
+              if ($first) {
+                $row .= ' first';
+              }
+              if ($class != 'meta' && $first) {
+                $first = false;
+              }
+              $row .= "'>";
+          
+              switch ($class) {
+                case 'meta':
+                  $line_info = '';
+                  $row .= "<td class='lineno'></td><td class='lineno'></td>";
+                  break;
+                case 'added':
+                  $row .= "<td class='lineno'></td><td class='lineno'>" . $lines[1] . "</td>";
+                  break;
+                case 'removed':
+                  $row .= "<td class='lineno'>" . $lines[0] . "</td><td class='lineno'></td>";
+                  break;
+                default:
+                  $row .= "<td class='lineno'>" . $lines[0] . "</td><td class='lineno'>" . $lines[1] . "</td>";
+              }
+              $anchor = $abase . '.' . $nlines;
+              $row .= "<td class='linelink'><a name='$anchor'></a><a href='#$anchor' title='link to this line'>#</a></td>";
+          
+              $line = htmlspecialchars($line, ENT_QUOTES, 'utf-8');
+              $row .= "<td class='line' width='100%'>$line</td></tr>\n";
+              $html .= $row;
+          
+              if (!count($input)) {
+                break;
+              }
+              $line = array_shift($input);
+              $nlines++;
+            }
+          
+            if ($nlines == 0) {
+              return null;
+            }
+          
+            $html .= "</table>";
+            return $html;
 }