Skip to content

Commit

Permalink
Fix isPhrasingContent conditions, text node replacement
Browse files Browse the repository at this point in the history
It also disables reverting forced paragraph elements as it can break
layouts or corrupt content.

Signed-off-by: Kevin Decherf <[email protected]>
  • Loading branch information
Kdecherf committed Feb 15, 2022
1 parent 8af69ad commit 2ab87d7
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Readability.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Readability implements LoggerAwareInterface
public const MIN_NODE_LENGTH = 80;
public const MAX_LINK_DENSITY = 0.25;
public $convertLinksToFootnotes = false;
public $revertForcedParagraphElements = true;
public $revertForcedParagraphElements = false;
public $articleTitle;
public $articleContent;
public $original_html;
Expand Down Expand Up @@ -991,9 +991,9 @@ protected function grabArticle(DOMElement $page = null)
$p->appendChild($childNode);
} elseif ('' !== $this->getInnerText($childNode, true, true)) {
$p = $this->dom->createElement('p');
$p->setInnerHtml($childNode->nodeValue);
$p->setAttribute('data-readability-styled', 'true');
$childNode->parentNode->replaceChild($p, $childNode);
$node->replaceChild($p, $childNode);
$p->appendChild($childNode);
}
} elseif (null !== $p) {
while ($p->lastChild && '' === $this->getInnerText($p->lastChild, true, true)) {
Expand Down Expand Up @@ -1465,8 +1465,8 @@ private function getAncestors(DOMElement $node, int $maxDepth = 0): array
private function isPhrasingContent($node): bool
{
return \XML_TEXT_NODE === $node->nodeType
|| \in_array($node->nodeName, $this->phrasingElements, true)
|| (\in_array($node->nodeName, ['a', 'del', 'ins'], true) && !\in_array(false, array_map(function ($c) {
|| \in_array(strtoupper($node->nodeName), $this->phrasingElements, true)
|| (\in_array(strtoupper($node->nodeName), ['A', 'DEL', 'INS'], true) && !\in_array(false, array_map(function ($c) {
return $this->isPhrasingContent($c);
}, iterator_to_array($node->childNodes)), true));
}
Expand Down

0 comments on commit 2ab87d7

Please sign in to comment.