diff options
-rw-r--r-- | src/NodeClass/NodeClassTrait.php | 39 | ||||
-rw-r--r-- | src/NodeUtility.php | 10 | ||||
-rw-r--r-- | src/Readability.php | 8 |
3 files changed, 9 insertions, 48 deletions
diff --git a/src/NodeClass/NodeClassTrait.php b/src/NodeClass/NodeClassTrait.php index 0fad1f2..678b41e 100644 --- a/src/NodeClass/NodeClassTrait.php +++ b/src/NodeClass/NodeClassTrait.php @@ -220,45 +220,6 @@ trait NodeClassTrait } /** - * Returns the next node. First checks for children (if the flag allows it), then for siblings, and finally - * for parents. - * - * @param DOMNode|DOMText $originalNode - * @param bool $ignoreSelfAndKids - * - * @return DOMNode - */ - public function getNextNode($originalNode, $ignoreSelfAndKids = false) - { - /* - * Traverse the DOM from node to node, starting at the node passed in. - * Pass true for the second parameter to indicate this node itself - * (and its kids) are going away, and we want the next node over. - * - * Calling this in a loop will traverse the DOM depth-first. - */ - - // First check for kids if those aren't being ignored - if (!$ignoreSelfAndKids && $originalNode->firstChild) { - return $originalNode->firstChild; - } - - // Then for siblings... - if ($originalNode->nextSibling) { - return $originalNode->nextSibling; - } - - // And finally, move up the parent chain *and* find a sibling - // (because this is depth-first traversal, we will have already - // seen the parent nodes themselves). - do { - $originalNode = $originalNode->parentNode; - } while ($originalNode && !$originalNode->nextSibling); - - return ($originalNode) ? $originalNode->nextSibling : $originalNode; - } - - /** * Creates a new node based on the text content of the original node. * * @param $originalNode DOMElement diff --git a/src/NodeUtility.php b/src/NodeUtility.php index 1743aba..ca34c8c 100644 --- a/src/NodeUtility.php +++ b/src/NodeUtility.php @@ -58,7 +58,7 @@ class NodeUtility * Imported from the Element class on league\html-to-markdown * * @param $node - * @return mixed + * @return DOMElement */ public static function nextElement($node) { @@ -124,13 +124,13 @@ class NodeUtility } /** - * Remove the passed node. + * Remove the selected node. * - * @param DOMElement $node + * @param $node DOMElement * * @return void **/ - public static function removeNode(DOMElement $node) + public static function removeNode($node) { $parent = $node->parentNode; if ($parent) { @@ -140,7 +140,7 @@ class NodeUtility /** - * Returns the next node. First checks for childs (if the flag allows it), then for siblings, and finally + * Returns the next node. First checks for children (if the flag allows it), then for siblings, and finally * for parents. * * @param DOMNode $originalNode diff --git a/src/Readability.php b/src/Readability.php index 0684b7b..b80641e 100644 --- a/src/Readability.php +++ b/src/Readability.php @@ -563,7 +563,7 @@ class Readability } } - $node = $node->getNextNode($node); + $node = NodeUtility::getNextNode($node); } return $elementsToScore; @@ -1172,13 +1172,13 @@ class Readability **/ public function _cleanMatchedNodes($node, $regex) { - $endOfSearchMarkerNode = $node->getNextNode($node, true); - $next = $node->getNextNode($node); + $endOfSearchMarkerNode = NodeUtility::getNextNode($node, true); + $next = NodeUtility::getNextNode($node); while ($next && $next !== $endOfSearchMarkerNode) { if (preg_match($regex, sprintf('%s %s', $next->getAttribute('class'), $next->getAttribute('id')))) { $next = NodeUtility::removeAndGetNext($next); } else { - $next = $next->getNextNode($next); + $next = NodeUtility::getNextNode($next); } } } |