(element, indent=0, inside=False)
return inner + children + tail
Recursively convert HTML element to troff.
Recursively convert HTML element to troff.
Recursively convert HTML element to troff .
def _convert_element(element, indent=0, inside=False):
    """Recursively convert HTML element to troff."""
    inner = _text_to_man(element.text) if element.text else ''
    tail = _text_to_man(element.tail) if element.tail else ''
    tag = element.tag.upper()
    children = ''.join(
        _convert_element(child, 1+indent, inside or tag == 'DD')
        for child in element.iterchildren(tag=etree.Element)
    )
    if tag == 'H1':
        return '\n.SH NAME\n' + inner.lower().replace('\\-', '') + ' \\- '
    if tag in ('H2', 'H3'):
        return '\n.SH ' + inner.upper() + children.upper() + '\n' + tail
    if tag in ('VAR', 'I'):
        return '\\fI' + inner + children + '\\fR' + tail
    if tag == 'B':
        return '\\fB' + inner + children + '\\fR' + tail
    if tag == 'DT':
        if inside:
            return '\n\n'+ inner + children + '\t' + tail
        return '\n.IP "' + inner + children + '"\n' + tail
    if tag == 'P':
        return '\n'+ inner + children + '\n' +tail
    if tag in ('DD', 'DL'):
        return inner + children + '\n' +tail
    return inner + children + tail
def _convert_element ( element , indent = 0 , inside = False ) : inner = _text_to_man ( element . text ) if element . text else '' tail = _text_to_man ( element . tail ) if element . tail else '' tag = element . tag . upper ( ) children = '' . join ( _convert_element ( child , 1 + indent , inside or tag == 'DD' ) for child in element . iterchildren ( tag = etree . Element ) ) if tag == 'H1' : return '\n.SH NAME\n' + inner . lower ( ) . replace ( '\\-' , '' ) + ' \\- ' if tag in ( 'H2' , 'H3' ) : return '\n.SH ' + inner . upper ( ) + children . upper ( ) + '\n' + tail if tag in ( 'VAR' , 'I' ) : return '\\fI' + inner + children + '\\fR' + tail if tag == 'B' : return '\\fB' + inner + children + '\\fR' + tail if tag == 'DT' : if inside : return '\n\n' + inner + children + '\t' + tail return '\n.IP "' + inner + children + '"\n' + tail if tag == 'P' : return '\n' + inner + children + '\n' + tail if tag in ( 'DD' , 'DL' ) : return inner + children + '\n' + tail return inner + children + tail