summaryrefslogtreecommitdiff
path: root/src/Nodes/DOM/DOMElement.php
diff options
context:
space:
mode:
authorFiveFilters.org <[email protected]>2021-08-20 15:54:08 +0200
committerFiveFilters.org <[email protected]>2021-08-20 15:54:08 +0200
commit9b0c58b8a610d109e88b22ba5377576f2fe4a575 (patch)
treee66ef2ec6ad82f0088cc856bb0123efdc00b422a /src/Nodes/DOM/DOMElement.php
parent37196ac5c2ee73ef113fccb2daa39d1fb8bfb52b (diff)
Add method to unwrap img inside noscript
https://github.com/mozilla/readability/commit/d784bf7e20e25ec1b3a6102a20c83d35fe3ef87d (but code based on current version of Readability.js)
Diffstat (limited to 'src/Nodes/DOM/DOMElement.php')
-rw-r--r--src/Nodes/DOM/DOMElement.php35
1 files changed, 35 insertions, 0 deletions
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;
+ }
}