From 9b0c58b8a610d109e88b22ba5377576f2fe4a575 Mon Sep 17 00:00:00 2001 From: "FiveFilters.org" Date: Fri, 20 Aug 2021 15:54:08 +0200 Subject: Add method to unwrap img inside noscript https://github.com/mozilla/readability/commit/d784bf7e20e25ec1b3a6102a20c83d35fe3ef87d (but code based on current version of Readability.js) --- src/Nodes/DOM/DOMElement.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/Nodes/DOM/DOMElement.php') diff --git a/src/Nodes/DOM/DOMElement.php b/src/Nodes/DOM/DOMElement.php index 900ad56..7486bad 100644 --- a/src/Nodes/DOM/DOMElement.php +++ b/src/Nodes/DOM/DOMElement.php @@ -7,4 +7,39 @@ use fivefilters\Readability\Nodes\NodeTrait; class DOMElement extends \DOMElement { use NodeTrait; + + /** + * Returns the child elements of this element. + * + * To get all child nodes, including non-element nodes like text and comment nodes, use childNodes. + * + * @return DOMNodeList + */ + public function children() + { + $newList = new DOMNodeList(); + foreach ($this->childNodes as $node) { + if ($node->nodeType === XML_ELEMENT_NODE) { + $newList->add($node); + } + } + return $newList; + } + + /** + * Returns the Element immediately prior to the specified one in its parent's children list, or null if the specified element is the first one in the list. + * + * @see https://wiki.php.net/rfc/dom_living_standard_api + * @return DOMElement|null + */ + public function previousElementSibling() + { + $previous = $this->previousSibling; + do { + if ($previous->nodeType === XML_ELEMENT_NODE) { + return $previous; + } + } while ($previous = $previous->previousSibling); + return null; + } } -- cgit v1.2.3