@@ -1035,8 +1035,8 @@ protected function grabArticle(?JSLikeHTMLElement $page = null): ?JSLikeHTMLElem
10351035 }
10361036 }
10371037
1038- if ( $ this ->hasSingleTagInsideElement ($ node , 'p ' ) && $ this -> getLinkDensity ( $ node ) < 0.25 ) {
1039- $ newNode = $ node -> childNodes -> item ( 0 );
1038+ $ newNode = $ this ->getSingleTagInsideElement ($ node , 'p ' );
1039+ if ( null !== $ newNode && $ this -> getLinkDensity ( $ node ) < 0.25 ) {
10401040 $ node ->parentNode ->replaceChild ($ newNode , $ node );
10411041 $ nodesToScore [] = $ newNode ;
10421042 }
@@ -1538,10 +1538,10 @@ private function isPhrasingContent($node): bool
15381538
15391539 /**
15401540 * Checks if `$node` has only whitespace and a single element with `$tag` for the tag name.
1541- * Returns false if `$node` contains non-empty text nodes
1541+ * Returns the matched element, or `null` if `$node` contains non-empty text nodes
15421542 * or if it contains no element with given tag or more than 1 element.
15431543 */
1544- private function hasSingleTagInsideElement (JSLikeHTMLElement $ node , string $ tag ): bool
1544+ private function getSingleTagInsideElement (JSLikeHTMLElement $ node , string $ tag ): ? JSLikeHTMLElement
15451545 {
15461546 $ childNodes = iterator_to_array ($ node ->childNodes );
15471547 $ children = array_filter ($ childNodes , fn ($ childNode ) => $ childNode instanceof \DOMElement);
@@ -1554,7 +1554,7 @@ private function hasSingleTagInsideElement(JSLikeHTMLElement $node, string $tag)
15541554 // And there should be no text nodes with real content
15551555 $ a = array_filter ($ childNodes , fn ($ childNode ) => $ childNode instanceof \DOMText && preg_match ($ this ->regexps ['hasContent ' ], $ this ->getInnerText ($ childNode )));
15561556
1557- return 0 === \count ($ a );
1557+ return 0 === \count ($ a ) ? $ children [ 0 ] : null ;
15581558 }
15591559
15601560 /**
0 commit comments