Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion html2text.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ def has_key(x, y):
try: from textwrap import wrap
except: pass

#support the python3 API
if sys.version_info[0] == 3:
unichr=chr
xrange=range

# Use Unicode characters instead of their ascii psuedo-replacements
UNICODE_SNOB = 0

Expand Down Expand Up @@ -543,7 +548,7 @@ def handle_tag(self, tag, attrs, start):
nest_count = self.google_nest_count(tag_style)
else:
nest_count = len(self.list)
self.o(" " * nest_count) #TODO: line up <ol><li>s > 9 correctly.
self.o(" " * int(nest_count)) #TODO: line up <ol><li>s > 9 correctly.
if li['name'] == "ul": self.o(self.ul_item_mark + " ")
elif li['name'] == "ol":
li['num'] += 1
Expand Down
18 changes: 14 additions & 4 deletions test/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,18 @@ def test_module(fn, google_doc=False, **kwargs):
h.body_width = 0
h.hide_strikethrough = True

for k, v in kwargs.iteritems():
setattr(h, k, v)
if sys.version_info[0] == 3:
for k, v in kwargs.items():
setattr(h, k, v)
else:
for k, v in kwargs.iteritems():
setattr(h, k, v)

result = get_baseline(fn)
actual = h.handle(file(fn).read())
if sys.version_info[0] == 3:
actual = h.handle(codecs.open(fn, mode='r', encoding='utf8').read())
else:
actual = h.handle(file(fn).read())
return print_result(fn, 'module', result, actual)

def test_command(fn, *args):
Expand All @@ -43,7 +50,10 @@ def test_command(fn, *args):
cmd += [fn]

result = get_baseline(fn)
actual = subprocess.Popen(cmd, stdout=subprocess.PIPE).stdout.read()
if sys.version_info[0] == 3:
actual = subprocess.Popen(cmd, stdout=subprocess.PIPE).stdout.read().decode('utf8')
else:
actual = subprocess.Popen(cmd, stdout=subprocess.PIPE).stdout.read()

if os.name == 'nt':
# Fix the unwanted CR to CRCRLF replacement
Expand Down