diff options
author | Andres Rey <[email protected]> | 2017-11-29 23:53:43 +0000 |
---|---|---|
committer | Andres Rey <[email protected]> | 2017-11-29 23:53:43 +0000 |
commit | 86823e6cb1b1ec4a21824bb36b53a3d810d18203 (patch) | |
tree | 024fd388debf2b2eaeb340be9d7c8722034d6e20 /src/Readability.php | |
parent | dfcb1b892337bfb0dd7cb090f38ee7532342beb1 (diff) |
Check for class weighting before doing it
Diffstat (limited to 'src/Readability.php')
-rw-r--r-- | src/Readability.php | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/Readability.php b/src/Readability.php index 55583ac..53bc32d 100644 --- a/src/Readability.php +++ b/src/Readability.php @@ -773,7 +773,7 @@ class Readability /** @var $ancestor DOMElement */ foreach ($ancestors as $level => $ancestor) { if (!$ancestor->isInitialized()) { - $ancestor->initializeNode(); + $ancestor->initializeNode($this->configuration->getWeightClasses()); $candidates[] = $ancestor; } @@ -1262,7 +1262,10 @@ class Readability continue; } - $weight = $node->getClassWeight(); + $weight = 0; + if ($this->configuration->getWeightClasses()) { + $weight = $node->getClassWeight(); + } if ($weight < 0) { NodeUtility::removeNode($node); @@ -1367,7 +1370,12 @@ class Readability $headers = $article->getElementsByTagName('h' . $headerIndex); /** @var $header DOMElement */ foreach ($headers as $header) { - if ($header->getClassWeight() < 0) { + $weight = 0; + if ($this->configuration->getWeightClasses()) { + $weight = $header->getClassWeight(); + } + + if ($weight < 0) { NodeUtility::removeNode($header); } } |