summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndres Rey <[email protected]>2016-11-14 17:04:49 +0000
committerAndres Rey <[email protected]>2016-11-14 17:04:49 +0000
commitfadc0c437251f797b2c224e97d55b3dec6b7d6cb (patch)
treeff518aafd40d043fdeb8daac1279cd94bf31232c /src
parent8a564266a76bf6f456f16b3512116964348f994b (diff)
Ported last part of node rating, new createNode function
Diffstat (limited to 'src')
-rw-r--r--src/HTMLParser.php7
-rw-r--r--src/Readability.php18
2 files changed, 25 insertions, 0 deletions
diff --git a/src/HTMLParser.php b/src/HTMLParser.php
index 2e37d22..6f7a1d5 100644
--- a/src/HTMLParser.php
+++ b/src/HTMLParser.php
@@ -324,6 +324,13 @@ class HTMLParser
} elseif (!$this->hasSingleChildBlockElement($node)) {
$node->setNodeTag('p');
$this->elementsToScore[] = $node;
+ } else {
+ // EXPERIMENTAL
+ foreach($node->getChildren() as $child) {
+ /** @var Readability $child */
+ $newNode = $node->createNode($child, 'p');
+ $child->replaceChild($newNode);
+ }
}
}
diff --git a/src/Readability.php b/src/Readability.php
index 7fc0d2b..f4e7b86 100644
--- a/src/Readability.php
+++ b/src/Readability.php
@@ -394,4 +394,22 @@ class Readability extends Element implements ReadabilityInterface
{
$this->node->parentNode->replaceChild($newNode->node, $this->node);
}
+
+ /**
+ * Creates a new node based on the text content of the original node.
+ *
+ * @param Readability $originalNode
+ * @param string $tagName
+ *
+ * @return Readability
+ */
+ public function createNode(Readability $originalNode, $tagName)
+ {
+ $text = $originalNode->getTextContent();
+ $newnode = $originalNode->node->ownerDocument->createElement($tagName, $text);
+
+ $return = $originalNode->node->appendChild($newnode);
+
+ return new static($return);
+ }
}