getTagName(); if (strtolower($value) === strtolower($tagName)) { return true; } return false; } /** * Checks if the current node has a single child and if that child is a P node. * Useful to convert

nodes to a single

node and avoid confusing the scoring system since div with p * tags are, in practice, paragraphs. * * @return bool */ public function hasSinglePNode() { if ($this->hasChildren()) { $children = $this->getChildren(); if (count($children) === 1) { if (strtolower($children[0]->getTagName()) === 'p') { return true; } } } return false; } /** * Get the ancestors of the current node. * * @param int $maxLevel Max amount of ancestors to get. * @return array */ public function getNodeAncestors($maxLevel = 3) { $ancestors = []; $level = 0; $node = $this; while ($node && $node->getParent()) { $ancestors[] = new static($node->node); $level++; if ($level >= $maxLevel) { break; } $node = $node->getParent(); } return $ancestors; } /** * Overloading the getParent function from League\HTMLToMarkdown\Element due to a bug when there are no more parents * on the selected element. * * @return DOMElementInterface|null */ public function getParent() { $node = $this->node->parentNode; return ($node) ? new static($node) : null; } }