summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndres Rey <[email protected]>2016-12-11 23:53:52 +0000
committerAndres Rey <[email protected]>2016-12-11 23:53:52 +0000
commit1fb1351943e27ca9d690a9e87c70ef4e1812a8ba (patch)
treef25ff16532c4f8fe3f3d5e44d430f499a757777d /src
parenta179eba52f0c1f868c800a9a85110216d3fcd34b (diff)
Added backupdom property, which will hold the original HTML in case it's needed to create a fake top candidate
Diffstat (limited to 'src')
-rw-r--r--src/HTMLParser.php12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/HTMLParser.php b/src/HTMLParser.php
index 27e376d..d262519 100644
--- a/src/HTMLParser.php
+++ b/src/HTMLParser.php
@@ -17,6 +17,11 @@ class HTMLParser
private $dom = null;
/**
+ * @var DOMDocument
+ */
+ private $backupdom = null;
+
+ /**
* @var array
*/
private $metadata = [];
@@ -154,6 +159,9 @@ class HTMLParser
{
$this->dom->loadHTML($html);
$this->dom->encoding = 'UTF-8';
+
+ // In case we need the original HTML to create a fake top candidate
+ $this->backupdom = clone $this->dom;
}
/**
@@ -465,7 +473,7 @@ class HTMLParser
$topCandidate = new DOMDocument();
$topCandidate->appendChild($topCandidate->createElement('div', ''));
- $kids = $this->dom->getElementsByTagName('body')->item(0)->childNodes;
+ $kids = $this->backupdom->getElementsByTagName('body')->item(0)->childNodes;
// Cannot be foreached, don't ask me why.
for ($i = 0; $i < $kids->length; $i++) {
@@ -473,7 +481,7 @@ class HTMLParser
$topCandidate->firstChild->appendChild($import);
}
- // Readability must be created using firstChild to grab de DOMElement instead of the DOMDocument.
+ // Readability must be created using firstChild to grab the DOMElement instead of the DOMDocument.
$topCandidate = new Readability($topCandidate->firstChild);
$topCandidate->initializeNode();