def delinkify_nodes(tree):
        """Remove <a> tags and replace them with their contents."""
        for node in tree.childNodes:
            if node.name == 'a':
                if 'href' not in node.attributes:
                    continue
                parts = urlparse.urlparse(node.attributes['href'])
                host = parts.hostname
                if any(_domain_match(host, d) for d in allow_domains):
                    continue
                if host is None and allow_relative:
                    continue
                # Replace the node with its children.
                # You can't nest <a> tags, and html5lib takes care of that
                # for us in the tree-building step.
                for n in node.childNodes:
                    tree.insertBefore(n, node)
                tree.removeChild(node)
            elif node.type != NODE_TEXT: # Don't try to delinkify text.
                delinkify_nodes(node)
Remove <a> tags and replace them with their contents.
v2ex/babel/ext/bleach/__init__.py