diff --git a/composer.json b/composer.json index f99ffc5..be705df 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "hampe/inky", "description": "PHP Implementation of ZURB's Foundation for Email parser (Inky)", - "version": "1.3.6.1", + "version": "1.3.6.2", "license": "MIT", "authors": [ { @@ -19,6 +19,6 @@ }, "require": { "php": ">=5.4.0", - "paquettg/php-html-parser": "^1.6" + "paquettg/php-html-parser": "^1.7" } } diff --git a/src/Inky.php b/src/Inky.php index 56ce1d5..24aa792 100644 --- a/src/Inky.php +++ b/src/Inky.php @@ -29,10 +29,11 @@ use Hampe\Inky\Component\RowFactory; use Hampe\Inky\Component\SpacerFactory; use Hampe\Inky\Component\WrapperFactory; -use Hampe\Inky\PHPHtmlParser\Dom; +use PHPHtmlParser\Dom; use PHPHtmlParser\Dom\AbstractNode; use PHPHtmlParser\Dom\Collection; use PHPHtmlParser\Dom\HtmlNode; +use PHPHtmlParser\Dom\InnerNode; use PHPHtmlParser\Exceptions\CircularException; class Inky @@ -183,6 +184,10 @@ protected function getAllComponentFactories() public function releaseTheKraken($html) { $dom = new Dom(); + $dom->setOptions([ + 'removeStyles' => false, + 'removeScripts' => false, + ]); $dom->load((string) $html); $parseCounter = 0; @@ -196,14 +201,15 @@ public function releaseTheKraken($html) return $dom->root->outerhtml; } - protected function clearCache(AbstractNode $node) + protected function clearCache(InnerNode $node) { foreach($node->getChildren() as $child) { if($child instanceof AbstractNode) { - $this->clearCache($child); + if($child instanceof InnerNode) { + $this->clearCache($child); + } $node->removeChild($child->id()); $node->addChild($child); - } } } @@ -237,7 +243,11 @@ protected function parse(Dom $dom) $parseInComplete = true; //replace element with new element $parent = $element->getParent(); - $siblings = $element->getParent()->getChildren(); + if(!$parent instanceof InnerNode) { + continue; + } + + $siblings = $parent->getChildren(); foreach($siblings as $sibling) { /** @var $sibling HtmlNode*/ $parent->removeChild($sibling->id()); diff --git a/src/PHPHtmlParser/Dom.php b/src/PHPHtmlParser/Dom.php deleted file mode 100644 index 513d8bf..0000000 --- a/src/PHPHtmlParser/Dom.php +++ /dev/null @@ -1,42 +0,0 @@ - - * @copyright 2013-2016 Thomas Hampe - * @date 30.08.16 - */ - - -namespace Hampe\Inky\PHPHtmlParser; - - -class Dom extends \PHPHtmlParser\Dom -{ - - /** - * Cleans the html of any none-html information. - * - * @param string $str - * @return string - */ - protected function clean($str) - { - // clean out the \n\r - $str = str_replace(["\r\n", "\r", "\n"], ' ', $str); - - // strip the doctype - $str = mb_eregi_replace("", '', $str); - - // strip out cdata - $str = mb_eregi_replace("", '', $str); - - return $str; - } - - -} \ No newline at end of file diff --git a/tests/Component/AbstractComponentFactoryTest.php b/tests/Component/AbstractComponentFactoryTest.php index 8aa6caf..2b4e1cd 100644 --- a/tests/Component/AbstractComponentFactoryTest.php +++ b/tests/Component/AbstractComponentFactoryTest.php @@ -16,7 +16,7 @@ use Hampe\Inky\Inky; -use Hampe\Inky\PHPHtmlParser\Dom; +use PHPHtmlParser\Dom; class AbstractComponentFactoryTest extends \PHPUnit_Framework_TestCase { @@ -43,6 +43,10 @@ public function testParse() foreach($this->testCases as $caseName => $testCase) { $fromHtml = trim(preg_replace('~>\s+<~', '><', $testCase['from'])); $dom = new Dom(); + $dom->setOptions([ + 'removeStyles' => false, + 'removeScripts' => false, + ]); $dom->load((string) trim(preg_replace('~>\s+<~', '><', $testCase['to']))); $toHtml = $dom->root->outerHtml(); $result = $inky->releaseTheKraken($fromHtml); diff --git a/tests/InkyTest.php b/tests/InkyTest.php index 8d34d9c..455bec0 100644 --- a/tests/InkyTest.php +++ b/tests/InkyTest.php @@ -11,7 +11,7 @@ * @date 13.03.16 */ -use Hampe\Inky\PHPHtmlParser\Dom; +use PHPHtmlParser\Dom; class InkyTest extends PHPUnit_Framework_TestCase { @@ -56,6 +56,10 @@ public function testStyles() foreach($stylesTestCases as $caseName => $testCase) { $fromHtml = trim(preg_replace('~>\s+<~', '><', $testCase['from'])); $dom = new Dom(); + $dom->setOptions([ + 'removeStyles' => false, + 'removeScripts' => false, + ]); $dom->load((string) trim(preg_replace('~>\s+<~', '><', $testCase['to']))); $toHtml = $dom->root->outerHtml(); $result = $inky->releaseTheKraken($fromHtml);