Index: trunk/extensions/CodeReview/backend/DiffHighlighter.php |
— | — | @@ -4,9 +4,14 @@ |
5 | 5 | * Highlight a SVN diff for easier readibility |
6 | 6 | */ |
7 | 7 | class CodeDiffHighlighter { |
| 8 | + /* chunk line count for the original file */ |
8 | 9 | private $left = 0; |
| 10 | + /* chunk line count for the changed file */ |
9 | 11 | private $right = 0; |
| 12 | + /* number of chunks */ |
10 | 13 | private $chunk = 0; |
| 14 | + /* line number inside patch */ |
| 15 | + private $lineNumber = 0; |
11 | 16 | |
12 | 17 | /** |
13 | 18 | * Main entry point. Given a diff text, highlight it |
— | — | @@ -40,6 +45,8 @@ |
41 | 46 | * @return string HTML table line (with <tr></tr>) |
42 | 47 | */ |
43 | 48 | function parseLine( $line ) { |
| 49 | + $this->lineNumber++; |
| 50 | + |
44 | 51 | if( $line === '' ) { return ""; } // do not create bogus lines |
45 | 52 | |
46 | 53 | # Dispatch diff lines to the proper handler |
— | — | @@ -82,8 +89,9 @@ |
83 | 90 | . "<td class=\"linenumbers\">%s</td>" |
84 | 91 | ; |
85 | 92 | |
| 93 | + $idAttr = $this->getLineIdAttr(); |
86 | 94 | if( is_null($class) ) { |
87 | | - return sprintf( "<tr>{$formatLN}<td>%s</td></tr>\n", |
| 95 | + return sprintf( "<tr {$idAttr}>{$formatLN}<td>%s</td></tr>\n", |
88 | 96 | $this->left, |
89 | 97 | $this->right, |
90 | 98 | $content |
— | — | @@ -113,7 +121,7 @@ |
114 | 122 | } |
115 | 123 | |
116 | 124 | $classAttr = is_null($class) ? '' : " class=\"$class\""; |
117 | | - return sprintf( "<tr>{$formatLN}<td%s>%s</td></tr>\n", |
| 125 | + return sprintf( "<tr {$idAttr}>{$formatLN}<td%s>%s</td></tr>\n", |
118 | 126 | $left, $right, |
119 | 127 | $classAttr, $content |
120 | 128 | ); |
— | — | @@ -150,10 +158,16 @@ |
151 | 159 | } |
152 | 160 | |
153 | 161 | function handleLineFile( $line ) { |
154 | | - return "<tr class=\"patchedfile\"><td colspan=\"3\">$line</td></tr>"; |
| 162 | + $this->chunk = 0; |
| 163 | + $idAttr = $this->getLineIdAttr(); |
| 164 | + return "<tr $idAttr class=\"patchedfile\"><td colspan=\"3\">$line</td></tr>"; |
155 | 165 | } |
156 | 166 | #### END OF LINES HANDLERS ######################################### |
157 | 167 | |
| 168 | + function getLineIdAttr() { |
| 169 | + return "id=\"line-{$this->lineNumber}\""; |
| 170 | + } |
| 171 | + |
158 | 172 | /** |
159 | 173 | * Turn a diff line into a properly formatted string suitable |
160 | 174 | * for output |