def remove_insignificant_text_nodes(dom):
nodes_to_remove = []<EOL>for node in walk_dom(dom):<EOL><INDENT>if is_text(node):<EOL><INDENT>text = node.nodeValue<EOL>if node.parentNode.tagName in _non_text_node_tags:<EOL><INDENT>nodes_to_remove.append(node)<EOL><DEDENT>else:<EOL><INDENT>node.nodeValue = re.sub(r'<STR_LIT>', '<STR_LIT:U+0020>', text)<EOL><DEDENT><DEDENT><DEDENT>for node in nodes_to_remove:<EOL><INDENT>remove_node(node)<EOL><DEDENT>
For html elements that should not have text nodes inside them, remove all
whitespace. For elements that may have text, collapse multiple spaces to a
single space.