diff options
author | Andres Rey <[email protected]> | 2016-10-21 20:20:48 +0100 |
---|---|---|
committer | Andres Rey <[email protected]> | 2016-10-21 20:20:48 +0100 |
commit | 0c11d557755ddbbafeeccd71e2d70b5c1d1458ab (patch) | |
tree | fcef7e334ff98025c1b60e2a1b3600296097e45b /src/HTMLParser.php | |
parent | fe73c4d7cf71023c4cc5654afb0aea47b179c084 (diff) |
Major refactor, Readability now is an extension of Element.
Diffstat (limited to 'src/HTMLParser.php')
-rw-r--r-- | src/HTMLParser.php | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/HTMLParser.php b/src/HTMLParser.php index 133a513..2f54114 100644 --- a/src/HTMLParser.php +++ b/src/HTMLParser.php @@ -89,7 +89,7 @@ class HTMLParser throw new \InvalidArgumentException('Invalid HTML was provided'); } - $root = new DOMElement($root); + $root = new Readability($root); $this->getNodes($root); @@ -139,7 +139,7 @@ class HTMLParser { $metadata = []; foreach ($this->dom->getElementsByTagName('meta') as $meta) { - /* @var DOMElement $meta */ + /* @var Readability $meta */ $name = $meta->getAttribute('name'); $property = $meta->getAttribute('property'); @@ -213,9 +213,9 @@ class HTMLParser /** * Gets nodes from the root element. * - * @param $node DOMElementInterface + * @param $node ReadabilityInterface */ - private function getNodes(DOMElementInterface $node) + private function getNodes(ReadabilityInterface $node) { $matchString = $node->getAttribute('class') . ' ' . $node->getAttribute('id'); @@ -257,6 +257,7 @@ class HTMLParser { $candidates = []; + /** @var Readability $node */ foreach ($nodes as $node) { // Discard nodes with less than 25 characters @@ -281,9 +282,9 @@ class HTMLParser $contentScore += min(floor(strlen($node->getValue()) / 100), 3); // Initialize and score ancestors. + /** @var Readability $ancestor */ foreach ($ancestors as $level => $ancestor) { - $readability = new Readability($ancestor); - $readability = $readability->initializeNode(); + $readability = $ancestor->initializeNode(); /* * Node score divider: |