Skip to content

Commit

Permalink
reformatting adds space after table.
Browse files Browse the repository at this point in the history
  • Loading branch information
theSage21 committed May 28, 2016
1 parent 1b78d10 commit f84b591
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
2 changes: 2 additions & 0 deletions html2text/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Use Unicode characters instead of their ascii psuedo-replacements
UNICODE_SNOB = 0

# Marker to use for marking tables for padding post processing
TABLE_MARKER_FOR_PAD = "special_marker_for_table_padding"
# Escape all special characters. Output is less readable, but avoids
# corner case formatting issues.
ESCAPE_SNOB = 0
Expand Down
22 changes: 13 additions & 9 deletions html2text/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ def reformat_table(lines, right_margin):
max_width = [len(x.rstrip()) + right_margin for x in lines[0].split('|')]
for line in lines:
cols = [x.rstrip() for x in line.split('|')]
max_width = [max(len(x) + right_margin, old_len) for x, old_len in zip(cols, max_width)]
max_width = [max(len(x) + right_margin, old_len)
for x, old_len in zip(cols, max_width)]

# reformat
new_lines = []
Expand All @@ -276,19 +277,22 @@ def pad_tables_in_text(text, right_margin=1):
Provide padding for tables in the text
"""
lines = text.split('\n')
table_buffer, altered_lines, table_widths, within_table = [], [], [], False
table_buffer, altered_lines, table_widths, table_started = [], [], [], False
new_lines = []
for line in lines:
if '|' in line:
if not within_table:
within_table = True
table_buffer.append(line)
else:
if within_table:
# Toogle table started
if (config.TABLE_MARKER_FOR_PAD in line):
table_started = not table_started
if not table_started:
table = reformat_table(table_buffer, right_margin)
new_lines.extend(table)
table_buffer = []
within_table = False
new_lines.append('')
continue
# Process lines
if table_started:
table_buffer.append(line)
else:
new_lines.append(line)
new_text = '\n'.join(new_lines)
return new_text

0 comments on commit f84b591

Please sign in to comment.