handle_starttag

[internal] handles start tags when constructing DOM tree.

Arguments

Source


def handle_starttag(self, tag, attrs):
        if not self._is_started:
            if tag.lower() == 'html':
                node = pyNode('html')
                self._is_started = True
                self._dom.append(node)
                self._nodes.append(node)
                for attr in attrs:
                    node.set_attr(attr[0], attr[1])
        else:
            node = pyNode(tag.lower())
            node.set_parent(self._dom[-1])
            self._dom[-1].add_child(node)
            if not is_self_closing(tag.lower()):
                self._dom.append(node)
            self._nodes.append(node)
            for attr in attrs:
                node.set_attr(attr[0], attr[1])