diff options
author | Andres Rey <[email protected]> | 2016-11-11 14:20:10 +0000 |
---|---|---|
committer | Andres Rey <[email protected]> | 2016-11-11 14:20:10 +0000 |
commit | d34f8c03fd869815044b5769973e8c6ff336de2a (patch) | |
tree | 5d360377c51ac85ecffa0573e5aa75806f2d887b /src/Readability.php | |
parent | 787501d2f6e88ce3d5d850cf88c67f88ea24ea08 (diff) |
Conditional to filter DOMComments
Diffstat (limited to 'src/Readability.php')
-rw-r--r-- | src/Readability.php | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/Readability.php b/src/Readability.php index 0740a08..5a1a6e9 100644 --- a/src/Readability.php +++ b/src/Readability.php @@ -48,8 +48,13 @@ class Readability extends Element implements ReadabilityInterface */ $score = 0; - if (get_class($node) !== 'DOMDocument') { - $score = $node->getAttribute('readability'); + if (!in_array(get_class($node), ['DOMDocument', 'DOMComment'])) { + try { + $score = $node->getAttribute('readability'); + + } catch (\Error $e) { + $test=1; + } } $this->setContentScore(($score) ? $score : 0); @@ -257,11 +262,9 @@ class Readability extends Element implements ReadabilityInterface */ public function setContentScore($score) { - if (get_class($this->node) !== 'DOMDocument') { + if (!in_array(get_class($this->node), ['DOMDocument', 'DOMComment'])) { - // To prevent the -0 value - // TODO Might not be necessary now - $this->contentScore = ($score === (float) -0) ? 0 : $score; + $this->contentScore = $score; // Set score in an attribute of the tag to prevent losing it while creating new Readability objects. $this->node->setAttribute('readability', $this->contentScore); @@ -319,7 +322,7 @@ class Readability extends Element implements ReadabilityInterface public function removeAndGetNext($node) { $nextNode = $this->getNextNode($node, true); - $nextNode->node->parentNode->removeChild($node->node); + $node->node->parentNode->removeChild($node->node); return $nextNode; } |