From 6f665c2914abcbd49a24cc92580e5c493f42f493 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 11 Apr 2016 15:22:56 +0200 Subject: [PATCH] use HTML5-PHP --- composer.json | 3 ++- src/PHPePub/Core/EPub.php | 9 +++++---- src/PHPePub/Core/EPubChapterSplitter.php | 5 +++-- tests/composer.json | 3 ++- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 489594e..5813430 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,8 @@ "php": ">=5.3.0", "phpzip/phpzip": "~2.0.7", "grandt/phpresizegif": "~1.0.3", - "grandt/relativepath": "~1.0.1" + "grandt/relativepath": "~1.0.1", + "masterminds/html5": "^2.1" }, "autoload": { "psr-4": { diff --git a/src/PHPePub/Core/EPub.php b/src/PHPePub/Core/EPub.php index bbc6fe0..9b2579f 100644 --- a/src/PHPePub/Core/EPub.php +++ b/src/PHPePub/Core/EPub.php @@ -2,6 +2,7 @@ namespace PHPePub\Core; use com\grandt\BinStringStatic; +use Masterminds\HTML5; use DOMDocument; use DOMXPath; use PHPePub\Core\Structure\Ncx; @@ -358,8 +359,8 @@ function addChapter($chapterName, $fileName, $chapterData = null, $autoSplit = f * @return array */ function findIdAttributes($chapterData) { - $xmlDoc = new DOMDocument(); - @$xmlDoc->loadHTML($chapterData); + $html5 = new HTML5(); + $xmlDoc = $html5->loadHTML($chapterData); $xpath = new DomXpath($xmlDoc); @@ -420,8 +421,8 @@ protected function processChapterExternalReferences(&$doc, $externalReferences = if ($isDocAString) { $doc = StringHelper::removeComments($doc); - $xmlDoc = new DOMDocument(); - @$xmlDoc->loadHTML($doc); + $html5 = new HTML5(); + $xmlDoc = $html5->loadHTML($doc); } else { $xmlDoc = $doc; } diff --git a/src/PHPePub/Core/EPubChapterSplitter.php b/src/PHPePub/Core/EPubChapterSplitter.php index 41c4823..26e773a 100644 --- a/src/PHPePub/Core/EPubChapterSplitter.php +++ b/src/PHPePub/Core/EPubChapterSplitter.php @@ -1,6 +1,7 @@ loadHTML($chapter); + $html5 = new HTML5(); + $xmlDoc = $html5->loadHTML($chapter); $head = $xmlDoc->getElementsByTagName("head"); $body = $xmlDoc->getElementsByTagName("body"); diff --git a/tests/composer.json b/tests/composer.json index 65e16b8..32a7147 100644 --- a/tests/composer.json +++ b/tests/composer.json @@ -1,7 +1,8 @@ { "require": { "php": ">=5.3.0", - "phpzip/phpzip": ">=2.0.7" + "phpzip/phpzip": ">=2.0.7", + "masterminds/html5": "^2.1" }, "autoload": { "psr-4": {