Skip to content

Commit b0f859d

Browse files
committed
Addressed code review comments.
1 parent 606ad6a commit b0f859d

File tree

4 files changed

+77
-107
lines changed

4 files changed

+77
-107
lines changed

demo/demo_text.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
$demos = array(
4-
array(
4+
/*array(
55
'old' => "<ol>
66
<li>During the 40 kW exposure, flames <li>yeaaaa she <li>MICKEY <li>HAPPY MEAL</li> MOUSE</li> did</li> <li>noooooo</li> shall not spread to the ceiling.</li>
77
<li>The flame shall not spread to the outer extremities of the samples on the 8-foot by 12-foot (203 by 305 mm) walls.</li>
@@ -15,6 +15,28 @@
1515
</ol>",
1616
1717
'new' => "<ol> <li>During the 40 kW exposure, flames shall not spread to the ceiling.</li> <li>The flame shall not spread to the outer extremities of the samples on the 8-foot by 12-foot (203 by 305 mm) walls.</li> <li>Flashover, as defined in NFPA 265, shall not occur.</li> <li>The total smoke <li>yep she did</li> released throughout the test shall not exceed 1,000 m<sup>2</sup>. Stuff: <ol> <li>All the stuff I didnt</li> <li>Ok, I can</li> <li>Oh no she didnt.</li> </ol> </li> </ol>"
18+
)*/
19+
array(
20+
'old' => '<p>The required capacity of each door opening shall be sufficient for the <em>occupant load</em> thereof and shall provide a minimum clear width of 32 inches (813 mm). Clear openings of doorways with swinging doors shall be measured between the face of the door and the stop, with the door open 90 degrees (1.57 rad). Where this section requires a minimum clear width of 32 inches (813 mm) and a door opening includes two door leaves without a mullion, one leaf shall provide a clear opening width of 32 inches (813 mm). The maximum width of a swinging door leaf shall be 48 inches (1219 mm) nominal. <em>Means of egress</em> doors in a Group I-2 occupancy used for the movement of beds shall provide a clear width not less than 41<sup>1</sup>/ <sub><sub>2 </sub></sub> inches (1054 mm). The height of door openings shall be not less than 80 inches (2032 mm).</p><ul class="exception"><li><strong>Exceptions:</strong><ol><li>The minimum and maximum width shall not apply to door openings that are not part of the required <em>means of egress </em>in Group R-2 and R-3 occupancies.</li><li>Door openings to resident <em>sleeping units</em> in Group I-3 occupancies shall have a clear width of not less than 28 inches (711 mm).</li><li>Door openings to storage closets less than 10 square feet (0.93 m<sup>2</sup>) in area shall not be limited by the minimum width.</li><li>Width of door leaves in revolving doors that comply with Section 1010.1.4.1 shall not be limited.</li><li>Door openings within a <em>dwelling unit</em> or <em>sleeping unit</em> shall be not less than 78 inches (1981 mm) in height.</li><li>Exterior door openings in <em>dwelling units</em> and <em>sleeping units</em>, other than the required <em>exit </em>door, shall be not less than 76 inches (1930 mm) in height.</li><li>In other than Group R-1 occupancies, the minimum widths shall not apply to interior egress doors within a <em>dwelling unit</em> or <em>sleeping unit</em> that is not required to be an <em>Accessible unit</em>, <em>Type A unit </em>or <em>Type B unit</em>.</li><li>Door openings required to be <em>accessible</em> within <em>Type B units</em> shall have a minimum clear width of 31.75 inches (806 mm).</li><li>Doors to walk-in freezers and coolers less than 1,000 square feet (93 m<sup>2</sup>) in area shall have a maximum width of 60 inches (1524 mm).</li><li>In Group R-1 <em>dwelling units</em> or <em>sleeping units</em> not required to be <em>Accessible units</em>, the minimum width shall not apply to doors for showers or saunas.</li></ol></li></ul>',
21+
'new' => '
22+
<p>The required capacity of each door opening shall be sufficient for the <span class="content_italics">occupant load</span> thereof and shall provide a minimum clear&nbsp;opening&nbsp;width of 32 inches (813 mm). The clear opening width&nbsp;of doorways with swinging doors shall be measured between the face of the door and the stop, with the door open 90 degrees (1.57 rad). Where this section requires a minimum clear opening width of 32 inches (813 mm) and a door opening includes two door leaves without a mullion, one leaf shall provide a minimum clear opening width of 32 inches (813 mm). In Group I-2, doors serving as &nbsp;<em>m</em><span class="content_italics">eans of egress</span> doors where&nbsp;used for the movement of beds shall provide a minimum clear opening width of&nbsp;41<sup>1</sup>/ <sub>2 </sub> inches (1054 mm). The maximum width of a swinging door leaf shall be 48 inches (1219 mm) nominal. The minimum clear opening height of doors shall be 80 inches (2032 mm).</p>
23+
<ul class="exception">
24+
<li><span class="content_bold">Exceptions:</span>
25+
<ol>
26+
<li>In Group R-2 and R-3 dwelling and sleeping units that are not required to be an Accessible unit, Type A unit or Type B unit, the minimum and maximum width shall not apply to door openings that are not part of the required <span class="content_italics">means of egress</span>.</li>
27+
<li>In Group I-3, door openings to resident <span class="content_italics">sleeping units</span>&nbsp;that are not required to be an Accessible unit shall have a minimum clear opening width of 28 inches (711 mm).</li>
28+
<li>Door openings to storage closets less than 10 square feet (0.93 m<sup>2</sup>) in area shall not be limited by the minimum clear opening width.</li>
29+
<li>The width of door leaves in revolving doors that comply with Section 1010.1.4.1 shall not be limited.</li>
30+
<li>Door openings within a <span class="content_italics">dwelling unit</span> or <span class="content_italics">sleeping unit</span> shall have a minimum clear opening height&nbsp;than 78 inches (1981 mm) in height.</li>
31+
<li>In dwelling and sleeping units that are not required to be Accessible, Type A or Type B units, exterior door openings, other than the required <span class="content_italics">exit </span>door, shall have a minimum clear opening height of&nbsp;76 inches (1930 mm) in height.</li>
32+
<li>Groups I-1, R-2, R-3 and R-4&nbsp;occupancies, in dwelling and sleeping units that are not required to be Accessible, Type A or Type B units, the minimum clear opening widths shall not apply to interior egress doors.</li>
33+
<li>Door openings within <span class="content_italics">Type B units</span>&nbsp;intended for user passage shall have a minimum clear opening width of 31.75 inches (806 mm).</li>
34+
<li>Doors to walk-in freezers and coolers less than 1,000 square feet (93 m<sup>2</sup>) in area shall have a maximum width of 60 inches (1524 mm) nominal.</li>
35+
<li>The minimum clear opening width shall not apply to doors for non-accessible shower or sauna compartments.</li>
36+
<li>The minimum clear opening width shall not apply to the doors for non-accessible toilet stalls.</li>
37+
</ol>
38+
</li>
39+
</ul>'
1840
)
1941
);
2042
header('Content-Type: application/json');

demo/index.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@
2121

2222
if ($input) {
2323
$data = json_decode($input, true);
24-
$diff = new HtmlDiff($data['oldText'], $data['newText'], 'UTF-8', array());
24+
$diff = new HtmlDiff($_POST['oldText'], $_POST['newText'], 'UTF-8', array());
2525
$diff->build();
26-
/*try{
26+
try{
2727
echo $diff->build();
2828
} catch (Exception $e) {
2929
echo $e->getMessage();
30-
}*/
30+
}
3131

32-
header('Content-Type: application/json');
33-
echo json_encode(array('diff' => $diff->getDifference()));
32+
//header('Content-Type: application/json');
33+
//echo json_encode(array('diff' => $diff->getDifference()));
3434
} else {
3535
header('Content-Type: text/html');
3636
echo file_get_contents('demo.html');

lib/Caxy/HtmlDiff/HtmlDiff.php

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,43 +196,62 @@ protected function diffElements($oldText, $newText)
196196
$matches = array();
197197
$wrapStart = '';
198198
$wrapEnd = '';
199+
//preg_match_all($pattern, $newText, $testmatches); var_dump($testmatches);
199200
if (preg_match_all($pattern, $newText, $matches)) {
200-
$wrapStart = $matches[0][0];
201-
$wrapEnd = $matches[0][1];
201+
$wrapStart = count($matches[0]) ? $matches[0][0] : '';
202+
$wrapEnd = count($matches[0]) > 1 ? $matches[0][1] : '';
202203
}
203204
$oldText = preg_replace($pattern, '', $oldText);
204205
$newText = preg_replace($pattern, '', $newText);
205206

206-
$diff = new HtmlDiff($oldText, $newText, $this->encoding, $this->isolatedDiffTags, $this->groupDiffs);
207+
$diff = new HtmlDiff($oldText, $newText, $this->encoding, $this->specialCaseTags, $this->groupDiffs);
207208

208209
return $wrapStart . $diff->build() . $wrapEnd;
209210
}
210211

211212
protected function diffList($oldText, $newText)
212213
{
213-
$diff = new ListDiff($oldText, $newText, $this->encoding, $this->isolatedDiffTags, $this->groupDiffs);
214+
$diff = new ListDiff($oldText, $newText, $this->encoding, $this->specialCaseTags, $this->groupDiffs);
214215
return $diff->build();
215216
}
216217

217218
protected function processEqualOperation($operation)
218219
{
219220
$result = array();
220221
foreach ($this->newWords as $pos => $s) {
222+
221223
if ($pos >= $operation->startInNew && $pos < $operation->endInNew) {
224+
222225
if (in_array($s, $this->isolatedDiffTags) && isset($this->newIsolatedDiffTags[$pos])) {
226+
223227
$oldText = implode("", $this->findIsolatedDiffTagsInOld($operation, $pos));
224228
$newText = implode("", $this->newIsolatedDiffTags[$pos]);
225-
$type = in_array($s, array($this->isolatedDiffTags['ol'], $this->isolatedDiffTags['dl'], $this->isolatedDiffTags['ul']))
226-
? "List"
227-
: "Elements";
228-
$result[] = $this->{'diff' . $type}($oldText, $newText);
229+
230+
if ($this->isListPlaceholder($s)) {
231+
$result[] = $this->diffList($oldText, $newText);
232+
} else {
233+
$result[] = $this->diffElements($oldText, $newText);
234+
}
229235
} else {
230236
$result[] = $s;
231237
}
232238
}
233239
}
234240
$this->content .= implode( "", $result );
235241
}
242+
243+
protected function isListPlaceholder($text)
244+
{
245+
if (in_array($text, array(
246+
$this->isolatedDiffTags['ol'],
247+
$this->isolatedDiffTags['dl'],
248+
$this->isolatedDiffTags['ul']
249+
))) {
250+
return true;
251+
}
252+
253+
return false;
254+
}
236255

237256
protected function findIsolatedDiffTagsInOld($operation, $posInNew)
238257
{

0 commit comments

Comments
 (0)