def get_text_for_html(html_content):
soup = BeautifulSoup(html_content)<EOL>for script in soup(["<STR_LIT>", "<STR_LIT>"]):<EOL><INDENT>script.extract()    <EOL><DEDENT>for a in soup.findAll('<STR_LIT:a>', href=True):<EOL><INDENT>a.replaceWith('<STR_LIT>' % (a.string, a.get('<STR_LIT>')))<EOL><DEDENT>text = soup.get_text()<EOL>lines = (line.strip() for line in text.splitlines())<EOL>chunks = (phrase.strip() for line in lines for phrase in line.split("<STR_LIT:U+0020>"))<EOL>text = '<STR_LIT:\n>'.join(chunk for chunk in chunks if chunk)<EOL>return text<EOL>
Take the HTML content (from, for example, an email)
and construct a simple plain text version of that content
(for example, for inclusion in a multipart email message).