(element, blocklist=None)
return blocklist
Recursively parse an element of the document tree.
Recursively parse an element of the document tree.
Recursively parse an element of the document tree .
def _parse_element(element, blocklist=None):
    """Recursively parse an element of the document tree."""
    if not blocklist:
        blocklist = [TextBlock()]
    last_indent = blocklist[-1].indent
    tag = element.tag.upper()
    inner = element.text if element.text else ''
    tail = element.tail if element.tail else ''
    if tag in UPPER_TAGS:
        inner = inner.upper()
    break_after = (tag in BREAK_AFTER_TAGS or element.get('class') == 'block')
    if tag in BLOCK_TAGS or element.get('class') == 'block':
        blocklist.append(TextBlock(last_indent, '', break_after))
    elif tag in INDENT_TAGS:
        blocklist.append(TextBlock(last_indent+1, '', break_after))
    blocklist[-1].content += inner
    for child in element.iterchildren(tag=etree.Element):
        blocklist = _parse_element(child, blocklist)
    if (tag in INDENT_TAGS + BLOCK_TAGS or blocklist[-1].indent != last_indent):
        break_after = blocklist[-1].break_after
        blocklist.append(TextBlock(last_indent, tail, break_after))
    else:
        blocklist[-1].content += tail
    return blocklist
def _parse_element ( element , blocklist = None ) : if not blocklist : blocklist = [ TextBlock ( ) ] last_indent = blocklist [ - 1 ] . indent tag = element . tag . upper ( ) inner = element . text if element . text else '' tail = element . tail if element . tail else '' if tag in UPPER_TAGS : inner = inner . upper ( ) break_after = ( tag in BREAK_AFTER_TAGS or element . get ( 'class' ) == 'block' ) if tag in BLOCK_TAGS or element . get ( 'class' ) == 'block' : blocklist . append ( TextBlock ( last_indent , '' , break_after ) ) elif tag in INDENT_TAGS : blocklist . append ( TextBlock ( last_indent + 1 , '' , break_after ) ) blocklist [ - 1 ] . content += inner for child in element . iterchildren ( tag = etree . Element ) : blocklist = _parse_element ( child , blocklist ) if ( tag in INDENT_TAGS + BLOCK_TAGS or blocklist [ - 1 ] . indent != last_indent ) : break_after = blocklist [ - 1 ] . break_after blocklist . append ( TextBlock ( last_indent , tail , break_after ) ) else : blocklist [ - 1 ] . content += tail return blocklist