def _is_junk(hashable_node): if isinstance(hashable_node, six.string_types): return is_text_junk(hashable_node) # Nodes with no text or just whitespace are junk. for descendant in walk_dom(hashable_node.node): if is_text(descendant): if not is_text_junk(descendant.nodeValue): return False return True
def _is_junk(hashable_node): if isinstance(hashable_node, basestring): return is_text_junk(hashable_node) # Nodes with no text or just whitespace are junk. for descendant in walk_dom(hashable_node.node): if is_text(descendant): if not is_text_junk(descendant.nodeValue): return False return True
def sort_nodes(dom, cmp_func): """ Sort the nodes of the dom in-place, based on a comparison function. """ dom.normalize() for node in list(walk_dom(dom, elements_only=True)): prev_sib = node.previousSibling while prev_sib and cmp_func(prev_sib, node) == 1: node.parentNode.insertBefore(node, prev_sib) prev_sib = node.previousSibling
def split_text_nodes(dom): for text_node in list(walk_dom(dom)): if not is_text(text_node): continue split_node(text_node)