Skip to content

Commit de416bc

Browse files
authored
Add spaceMatching setting that matches all spaces (#111)
1 parent 5e19401 commit de416bc

File tree

5 files changed

+54
-21
lines changed

5 files changed

+54
-21
lines changed

lib/Caxy/HtmlDiff/HtmlDiff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ protected function checkCondition($word, $condition)
584584

585585
protected function wrapText(string $text, string $tagName, string $cssClass) : string
586586
{
587-
if (trim($text) === '') {
587+
if (!$this->config->isSpaceMatching() && trim($text) === '') {
588588
return '';
589589
}
590590

lib/Caxy/HtmlDiff/HtmlDiffConfig.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ class HtmlDiffConfig
7777
*/
7878
protected $purifierCacheLocation = null;
7979

80+
/**
81+
* @var bool
82+
*/
83+
protected $spaceMatching = false;
84+
8085
/**
8186
* @return HtmlDiffConfig
8287
*/
@@ -441,6 +446,22 @@ public function getPurifierCacheLocation()
441446
return $this->purifierCacheLocation;
442447
}
443448

449+
/**
450+
* @return bool
451+
*/
452+
public function isSpaceMatching()
453+
{
454+
return $this->spaceMatching;
455+
}
456+
457+
/**
458+
* @param bool $keepNewLines
459+
*/
460+
public function setSpaceMatching($spaceMatching)
461+
{
462+
$this->spaceMatching = $spaceMatching;
463+
}
464+
444465
/**
445466
* @param string $tag
446467
*

tests/fixtures/HtmlDiff/simple-list.html

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
<options></options>
22

33
<oldText>
4-
<ol><li>List item one</li>
5-
<li>List item two with subitems:
6-
<ul><li>Subitem 1</li>
7-
<li>Subitem 2</li>
8-
<li>
9-
<p>
10-
Hi there<br />
11-
<ul><li>B</li>
12-
<li>A</li>
13-
<li>B</li>
14-
</ul>
15-
</p>
16-
</li>
17-
<li>
18-
<dl><li>Deleted list</li></dl>
19-
</li>
20-
</ul>
21-
</li>
22-
<li>Final list item</li>
23-
</ol>
4+
<ol><li>List item one</li>
5+
<li>List item two with subitems:
6+
<ul><li>Subitem 1</li>
7+
<li>Subitem 2</li>
8+
<li>
9+
<p>
10+
Hi there<br />
11+
<ul><li>B</li>
12+
<li>A</li>
13+
<li>B</li>
14+
</ul>
15+
</p>
16+
</li>
17+
<li>
18+
<dl><li>Deleted list</li></dl>
19+
</li>
20+
</ul>
21+
</li>
22+
<li>Final list item</li>
23+
</ol>
2424
</oldText>
2525

2626
<newText>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<options>
2+
<option type="boolean" name="setSpaceMatching" value="true" />
3+
</options>
4+
<oldtext>He said:"OK!"</oldtext>
5+
<newtext>He said: "OK!"</newtext>
6+
<expected>He said:<ins class="diffins"> </ins>"OK!"</expected>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<options>
2+
<option type="boolean" name="setSpaceMatching" value="true" />
3+
</options>
4+
<oldtext><strong>this </strong>is</oldtext>
5+
<newtext><strong>this</strong>is</newtext>
6+
<expected><strong>this<del class="diffdel"> </del></strong>is</expected>

0 commit comments

Comments
 (0)