'Converts an HTML document to plain text.'

def _html2plaintext(self, html_content):

    content = html_content.replace('\r\n', '\n')
    content = re.sub('<br[     DCTB \r\n\x0b\x0c]*.*/>', '\n', content)
    content = re.sub('<p[     DCTB \r\n\x0b\x0c]*.*/>', '\n', content)
    content = re.sub('<p>', '', content)
    content = re.sub('</p>', '\n', content)
    content = re.sub('<.+/>', '', content)
    content = re.sub('<.+>', '', content)
    content = re.sub('</.+>', '', content)
    content = re.sub('[\n]+', '\n', content)
    content = re.sub('[     DCTB \x0b\x0c]+', '    ', content)
    parsed_html_content = u''
    for line in content.split('\n'):
        trimmed_line = line.strip()
        if trimmed_line:
            parsed_html_content += (trimmed_line + u'\n')
    return parsed_html_content
