예제 #1
0
파일: html.py 프로젝트: dal-bhaat/stack5
def fix_tables(dom):
    # Show table row insertions
    tags = set()
    for node in list(dom.getElementsByTagName('tr')):
        parent = node.parentNode
        if parent.tagName in ('ins', 'del'):
            tags.add(parent)
    for tag in tags:
        distribute(tag)
    # Show table cell insertions
    tags = set()
    for node in list(dom.getElementsByTagName('td') +
                     dom.getElementsByTagName('th')):
        parent = node.parentNode
        if parent.tagName in ('ins', 'del'):
            tags.add(parent)
    for tag in tags:
        distribute(tag)
    # All other ins and del tags inside a table but not in a cell are invalid,
    # so remove them.
    for node in list(dom.getElementsByTagName('ins') +
                     dom.getElementsByTagName('del')):
        parent = node.parentNode
        if parent.tagName in ['table', 'tbody', 'thead', 'tfoot', 'tr']:
            remove_node(node)
 def action_delete(self, node):
     parent = node.parentNode
     next_sibling = node.nextSibling
     remove_node(node)
     node.orig_parent = parent
     node.orig_next_sibling = next_sibling
     self.del_nodes.append(node)
예제 #3
0
def fix_tables(dom):
    # Show table row insertions
    tags = set()
    for node in list(dom.getElementsByTagName('tr')):
        parent = node.parentNode
        if parent.tagName in ('ins', 'del'):
            tags.add(parent)
    for tag in tags:
        distribute(tag)
    # Show table cell insertions
    tags = set()
    for node in list(
            dom.getElementsByTagName('td') + dom.getElementsByTagName('th')):
        parent = node.parentNode
        if parent.tagName in ('ins', 'del'):
            tags.add(parent)
    for tag in tags:
        distribute(tag)
    # All other ins and del tags inside a table but not in a cell are invalid,
    # so remove them.
    for node in list(
            dom.getElementsByTagName('ins') + dom.getElementsByTagName('del')):
        parent = node.parentNode
        if parent.tagName in ['table', 'tbody', 'thead', 'tfoot', 'tr']:
            remove_node(node)
예제 #4
0
 def action_delete(self, node):
     parent = node.parentNode
     next_sibling = node.nextSibling
     remove_node(node)
     node.orig_parent = parent
     node.orig_next_sibling = next_sibling
     self.del_nodes.append(node)
예제 #5
0
파일: changes.py 프로젝트: dal-bhaat/stack5
def split_node(node):
    # Split text node in into user-friendly chunks.
    pieces = split_text(node.nodeValue)
    if len(pieces) <= 1:
        return
    parent = node.parentNode
    for piece in pieces:
        piece_node = node.ownerDocument.createTextNode(piece)
        parent.insertBefore(piece_node, node)
    remove_node(node)
예제 #6
0
def split_node(node):
    # Split text node in into user-friendly chunks.
    pieces = split_text(node.nodeValue)
    if len(pieces) <= 1:
        return
    parent = node.parentNode
    for piece in pieces:
        piece_node = node.ownerDocument.createTextNode(piece)
        parent.insertBefore(piece_node, node)
    remove_node(node)
예제 #7
0
파일: changes.py 프로젝트: dal-bhaat/stack5
def merge_adjacent(dom, tag_name):
    """
    Merge all adjacent tags with the specified tag name.
    Return the number of merges performed.
    """
    for node in dom.getElementsByTagName(tag_name):
        prev_sib = node.previousSibling
        if prev_sib and prev_sib.nodeName == node.tagName:
            for child in list(node.childNodes):
                prev_sib.appendChild(child)
            remove_node(node)
예제 #8
0
def merge_adjacent(dom, tag_name):
    """
    Merge all adjacent tags with the specified tag name.
    Return the number of merges performed.
    """
    for node in dom.getElementsByTagName(tag_name):
        prev_sib = node.previousSibling
        if prev_sib and prev_sib.nodeName == node.tagName:
            for child in list(node.childNodes):
                prev_sib.appendChild(child)
            remove_node(node)
예제 #9
0
 def delete(self, location, node):
     # delete from the bottom up, children before parent, right to left
     for child_index, child in reversed(list(enumerate(node.childNodes))):
         self.delete(location + [child_index], child)
     # write deletion to the edit script
     self.edit_script.append((
         'delete',
         location,
         node_properties(node),
     ))
     # actually delete the node
     assert node.parentNode == get_location(self.old_dom, location[:-1])
     assert node.ownerDocument == self.old_dom
     remove_node(node)
예제 #10
0
 def delete(self, location, node):
     # delete from the bottom up, children before parent, right to left
     for child_index, child in reversed(list(enumerate(node.childNodes))):
         self.delete(location + [child_index], child)
     # write deletion to the edit script
     self.edit_script.append((
         'delete',
         location,
         node_properties(node),
     ))
     # actually delete the node
     assert node.parentNode == get_location(self.old_dom, location[:-1])
     assert node.ownerDocument == self.old_dom
     remove_node(node)
예제 #11
0
파일: changes.py 프로젝트: dal-bhaat/stack5
def _strip_changes_old(node):
    for ins_node in node.getElementsByTagName('ins'):
        remove_node(ins_node)
    for del_node in node.getElementsByTagName('del'):
        unwrap(del_node)
예제 #12
0
def _strip_changes_old(node):
    for ins_node in node.getElementsByTagName('ins'):
        remove_node(ins_node)
    for del_node in node.getElementsByTagName('del'):
        unwrap(del_node)