def action_insert_node(self, parent, child_index, node): next_sibling = get_child(parent, child_index) insert_or_append(parent, node, next_sibling) # add node to ins_nodes assert node.parentNode is not None node.orig_parent = parent node.orig_next_sibling = next_sibling self.ins_nodes.append(node)
def insert(self, location, node): # write insertion to the edit script self.edit_script.append(( 'insert', location, node_properties(node), )) # actually insert the node node_copy = node.cloneNode(deep=False) parent = get_location(self.old_dom, location[:-1]) next_sibling = get_child(parent, location[-1]) insert_or_append(parent, node_copy, next_sibling) # insert from the top down, parent before children, left to right for child_index, child in enumerate(node.childNodes): self.insert(location + [child_index], child)
def add_changes_markup(dom, ins_nodes, del_nodes): """ Add <ins> and <del> tags to the dom to show changes. """ # add markup for inserted and deleted sections for node in reversed(del_nodes): # diff algorithm deletes nodes in reverse order, so un-reverse the # order for this iteration insert_or_append(node.orig_parent, node, node.orig_next_sibling) wrap(node, 'del') for node in ins_nodes: wrap(node, 'ins') # Perform post-processing and cleanup. remove_nesting(dom, 'del') remove_nesting(dom, 'ins') sort_del_before_ins(dom) merge_adjacent(dom, 'del') merge_adjacent(dom, 'ins')