html2text: Use the class if possible
This commit is contained in:
parent
362b441445
commit
72819cdb67
1 changed files with 23 additions and 9 deletions
|
|
@ -22,6 +22,20 @@ import warnings
|
||||||
__all__ = ['html2text']
|
__all__ = ['html2text']
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
from html2text import HTML2Text
|
||||||
|
|
||||||
|
def html2text(html):
|
||||||
|
h = HTML2Text()
|
||||||
|
h.unicode_snob = True
|
||||||
|
h.skip_internal_links = True
|
||||||
|
h.inline_links = False
|
||||||
|
h.links_each_paragraph = True
|
||||||
|
return unicode(h.handle(html))
|
||||||
|
|
||||||
|
except ImportError:
|
||||||
|
# Older versions of html2text do not have a class, so we have
|
||||||
|
# to configure the module globally.
|
||||||
try:
|
try:
|
||||||
import html2text as h2t
|
import html2text as h2t
|
||||||
h2t.UNICODE_SNOB = 1
|
h2t.UNICODE_SNOB = 1
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue