Skip to content
Closed
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
2 changes: 2 additions & 0 deletions html2text/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ def reformat_table(lines: List[str], right_margin: int) -> List[str]:
Given the lines of a table
padds the cells and returns the new lines
"""
if not lines:
return lines
# find the maximum width of the columns
max_width = [len(x.rstrip()) + right_margin for x in lines[0].split("|")]
max_cols = len(max_width)
Expand Down
11 changes: 11 additions & 0 deletions test/test_html2text.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,14 @@ def test_strong_emptied() -> None:
h.strong_mark = ""
string = "A <b>B</b> <i>C</i>."
assert h.handle(string) == "A B _C_.\n\n"


def test_pad_tables_empty_table() -> None:
"""An empty table block should not crash table padding."""
from html2text import config
from html2text.utils import pad_tables_in_text

# Two consecutive markers leave the table buffer empty, which used to
# raise IndexError on lines[0].
marker = config.TABLE_MARKER_FOR_PAD
pad_tables_in_text(f"{marker}\n{marker}\n")