def action_insert_node(self, parent, child_index, node): previous_sibling = get_child(parent, child_index - 1) 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)