diff --git a/lib/Caxy/HtmlDiff/HtmlDiff.php b/lib/Caxy/HtmlDiff/HtmlDiff.php index 4dbc85f..1a161b0 100644 --- a/lib/Caxy/HtmlDiff/HtmlDiff.php +++ b/lib/Caxy/HtmlDiff/HtmlDiff.php @@ -584,7 +584,7 @@ protected function checkCondition($word, $condition) protected function wrapText(string $text, string $tagName, string $cssClass) : string { - if (trim($text) === '') { + if (!$this->config->isSpaceMatching() && trim($text) === '') { return ''; } diff --git a/lib/Caxy/HtmlDiff/HtmlDiffConfig.php b/lib/Caxy/HtmlDiff/HtmlDiffConfig.php index 2f97a23..660c6fc 100644 --- a/lib/Caxy/HtmlDiff/HtmlDiffConfig.php +++ b/lib/Caxy/HtmlDiff/HtmlDiffConfig.php @@ -77,6 +77,11 @@ class HtmlDiffConfig */ protected $purifierCacheLocation = null; + /** + * @var bool + */ + protected $spaceMatching = false; + /** * @return HtmlDiffConfig */ @@ -441,6 +446,22 @@ public function getPurifierCacheLocation() return $this->purifierCacheLocation; } + /** + * @return bool + */ + public function isSpaceMatching() + { + return $this->spaceMatching; + } + + /** + * @param bool $keepNewLines + */ + public function setSpaceMatching($spaceMatching) + { + $this->spaceMatching = $spaceMatching; + } + /** * @param string $tag * diff --git a/tests/fixtures/HtmlDiff/simple-list.html b/tests/fixtures/HtmlDiff/simple-list.html index 5f909fa..72c6357 100644 --- a/tests/fixtures/HtmlDiff/simple-list.html +++ b/tests/fixtures/HtmlDiff/simple-list.html @@ -1,26 +1,26 @@ -
  1. List item one
  2. -
  3. List item two with subitems: -
    • Subitem 1
    • -
    • Subitem 2
    • -
    • -

      - Hi there
      -

      • B
      • -
      • A
      • -
      • B
      • -
      -

      -
    • -
    • -
    • Deleted list
    • -
    • -
    -
  4. -
  5. Final list item
  6. -
+
  1. List item one
  2. +
  3. List item two with subitems: +
    • Subitem 1
    • +
    • Subitem 2
    • +
    • +

      + Hi there
      +

      • B
      • +
      • A
      • +
      • B
      • +
      +

      +
    • +
    • +
    • Deleted list
    • +
    • +
    +
  4. +
  5. Final list item
  6. +
diff --git a/tests/fixtures/HtmlDiff/spaces-added.html b/tests/fixtures/HtmlDiff/spaces-added.html new file mode 100644 index 0000000..d0acf53 --- /dev/null +++ b/tests/fixtures/HtmlDiff/spaces-added.html @@ -0,0 +1,6 @@ + + +He said:"OK!" +He said: "OK!" +He said: "OK!" diff --git a/tests/fixtures/HtmlDiff/spaces-removed-inside-tag.html b/tests/fixtures/HtmlDiff/spaces-removed-inside-tag.html new file mode 100644 index 0000000..a5e7c69 --- /dev/null +++ b/tests/fixtures/HtmlDiff/spaces-removed-inside-tag.html @@ -0,0 +1,6 @@ + + +this is +thisis +this is