summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndres Rey <[email protected]>2016-11-13 12:03:38 +0000
committerAndres Rey <[email protected]>2016-11-13 12:03:38 +0000
commit34460727a82e8d11775d9a137e7f5f07dc302f45 (patch)
treeca9574275eaf3ea2dce0b156925f3d6d6c50d69e /src
parent572ee51c33b27f4e8e0e945d862d5fddf34a36e2 (diff)
Correct loop for hasSingleChildBlockElement. Changed Readability function to match the JS version.
Diffstat (limited to 'src')
-rw-r--r--src/HTMLParser.php19
-rw-r--r--src/Readability.php2
2 files changed, 14 insertions, 7 deletions
diff --git a/src/HTMLParser.php b/src/HTMLParser.php
index 457fd20..0fae247 100644
--- a/src/HTMLParser.php
+++ b/src/HTMLParser.php
@@ -322,11 +322,9 @@ class HTMLParser
$node->replaceChild($pNode);
$node = $pNode;
} elseif (!$this->hasSingleChildBlockElement($node)) {
-
- // If there's any info on the node, add it to the elements to score in the next step.
- if ($node->getValue(true)) {
- $this->elementsToScore[] = $node;
- }
+ // FIXME!!!
+ $node->setNodeTag('p');
+ $this->elementsToScore[] = $node;
}
}
@@ -615,6 +613,15 @@ class HTMLParser
private function hasSingleChildBlockElement(Readability $node)
{
- return (in_array($node->getTagName(), $this->divToPElements)) ? true : $this->hasSingleChildBlockElement($node);
+ /** @var Readability $child */
+ foreach ($node->getChildren() as $child) {
+ if (in_array($child->getTagName(), $this->divToPElements)) {
+ $this->hasSingleChildBlockElement($child);
+ } else {
+ return false;
+ }
+ }
+
+ return true;
}
}
diff --git a/src/Readability.php b/src/Readability.php
index 8f7954a..2e2bf01 100644
--- a/src/Readability.php
+++ b/src/Readability.php
@@ -272,7 +272,7 @@ class Readability extends Element implements ReadabilityInterface
*
* @param string $value
*/
- public function setNodeName($value)
+ public function setNodeTag($value)
{
$this->node->nodeName = $value;
}