protected function parse()
{
// add the root node
$this->root = new HtmlNode('root');
$activeNode = $this->root;
while (!is_null($activeNode)) {
$str = $this->content->copyUntil('<');
if ($str == '') {
$info = $this->parseTag();
if (!$info['status']) {
// we are done here
$activeNode = null;
continue;
}
// check if it was a closing tag
if ($info['closing']) {
$originalNode = $activeNode;
while ($activeNode->getTag()->name() != $info['tag']) {
$activeNode = $activeNode->getParent();
if (is_null($activeNode)) {
// we could not find opening tag
$activeNode = $originalNode;
break;
}
}
if (!is_null($activeNode)) {
$activeNode = $activeNode->getParent();
}
continue;
}
if (!isset($info['node'])) {
continue;
}
/** @var AbstractNode $node */
$node = $info['node'];
$activeNode->addChild($node);
// check if node is self closing
if (!$node->getTag()->isSelfClosing()) {
$activeNode = $node;
}
} else {
if ($this->options->whitespaceTextNode || trim($str) != '') {
// we found text we care about
$textNode = new TextNode($str);
$activeNode->addChild($textNode);
}
}
}
}