Skip to content

Commit

Permalink
Merge pull request j0k3r#73 from Kdecherf/fix/impr
Browse files Browse the repository at this point in the history
Fix `isPhrasingContent` conditions, text node replacement
  • Loading branch information
j0k3r authored Feb 15, 2022
2 parents 8af69ad + 2ab87d7 commit 0c0653d
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 0c0653d

Please sign in to comment.