/** * Loop over all the DOMNode recursively. * * @param \DOMNode $node * @param \DOMDocument $dom */ private function processDOM(\DOMNode $node, \DOMDocument $dom) { if ($node->hasChildNodes()) { $nodes = array(); foreach ($node->childNodes as $childNode) { if ($childNode instanceof \DOMElement && $childNode->tagName) { if (in_array($childNode->tagName, $this->protectedTags)) { continue; } } $nodes[] = $childNode; } $depth = $this->stateBag->getCurrentDepth(); foreach ($nodes as $childNode) { if ($childNode instanceof \DOMText && !$childNode->isWhitespaceInElementContent()) { $this->stateBag->setCurrentDepth($depth); $this->doFix($childNode, $node, $dom); } else { $this->stateBag->setCurrentDepth($this->stateBag->getCurrentDepth() + 1); $this->processDOM($childNode, $dom); } } } }