diff --git a/PrettyMin.php b/PrettyMin.php index 35d51e3..88881d4 100644 --- a/PrettyMin.php +++ b/PrettyMin.php @@ -257,12 +257,18 @@ protected function removeWhitespace() { $node->nodeValue = str_replace(' ', ' ', $node->nodeValue); } - if (!($node->previousSibling && in_array($node->previousSibling->nodeName, $this->options['keep_whitespace_around']))) { - $node->nodeValue = ltrim($node->nodeValue); - } + if (!in_array($node->parentNode->nodeName, $this->options['keep_whitespace_around'])) { + if (!($node->previousSibling && in_array($node->previousSibling->nodeName, + $this->options['keep_whitespace_around'])) + ) { + $node->nodeValue = ltrim($node->nodeValue); + } - if (!($node->nextSibling && in_array($node->nextSibling->nodeName, $this->options['keep_whitespace_around']))) { - $node->nodeValue = rtrim($node->nodeValue); + if (!($node->nextSibling && in_array($node->nextSibling->nodeName, + $this->options['keep_whitespace_around'])) + ) { + $node->nodeValue = rtrim($node->nodeValue); + } } if((strlen($node->nodeValue) == 0)) { diff --git a/Tests/PrettyMinTest.php b/Tests/PrettyMinTest.php index 61c0c75..b935c7d 100644 --- a/Tests/PrettyMinTest.php +++ b/Tests/PrettyMinTest.php @@ -37,6 +37,7 @@ function () {

This is bold Text. And some more text, still in the same paragraph. + Inline tag whith whitespace at the end but not after.

This is another paragraph with a link.

@@ -55,7 +56,7 @@ public function testMinify() $expected = << -Test

Test

This is bold Text. And some more text, still in the same paragraph.

This is another paragraph with a link.

+Test

Test

This is bold Text. And some more text, still in the same paragraph. Inline tag whith whitespace at the end but not after.

This is another paragraph with a link.

HTML; @@ -93,7 +94,7 @@ function () {

Test

-

This is bold Text. And some more text, still in the same paragraph.

+

This is bold Text. And some more text, still in the same paragraph. Inline tag whith whitespace at the end but not after.

This is another paragraph with a link.