diff options
-rw-r--r-- | src/Nodes/NodeTrait.php | 8 | ||||
-rw-r--r-- | src/Readability.php | 4 |
2 files changed, 8 insertions, 4 deletions
diff --git a/src/Nodes/NodeTrait.php b/src/Nodes/NodeTrait.php index c08b59f..f641b2d 100644 --- a/src/Nodes/NodeTrait.php +++ b/src/Nodes/NodeTrait.php @@ -365,13 +365,13 @@ trait NodeTrait * Check if a given node has one of its ancestor tag name matching the * provided one. * - * @param DOMElement $node * @param string $tagName * @param int $maxDepth + * @param callable $filterFn * * @return bool */ - public function hasAncestorTag($tagName, $maxDepth = 3) + public function hasAncestorTag($tagName, $maxDepth = 3, callable $filterFn = null) { $depth = 0; $node = $this; @@ -380,9 +380,11 @@ trait NodeTrait if ($maxDepth > 0 && $depth > $maxDepth) { return false; } - if ($node->parentNode->nodeName === $tagName) { + + if ($node->parentNode->nodeName === $tagName && (!$filterFn || $filterFn($node->parentNode))) { return true; } + $node = $node->parentNode; $depth++; } diff --git a/src/Readability.php b/src/Readability.php index f4f38ae..eadd50d 100644 --- a/src/Readability.php +++ b/src/Readability.php @@ -1460,7 +1460,9 @@ class Readability $node = $DOMNodeList->item($length - 1 - $i); // First check if we're in a data table, in which case don't remove us. - if ($node->hasAncestorTag('table', -1) && $node->isReadabilityDataTable()) { + if ($node->hasAncestorTag('table', -1, function($node){ + return $node->isReadabilityDataTable(); + })) { continue; } |