Skip to content

Commit 53ac1a7

Browse files
committed
Fix width calculation for multiline cells
Use correct padding to fix the issue. This wasn't a problem for "grid" table formatting, but it was an issue for "simple". It seems that the root cause was a hard-coded pad value of 1 (see commit a93034a, tabulate.py line 1336).
1 parent a93034a commit 53ac1a7

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

tabulate.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,7 @@ def _append_multiline_row(lines, padded_multiline_cells, padded_widths, colalign
13331333
cells_lines = [(cl + [' '*w]*(nlines - len(cl))) for cl, w in zip(cells_lines, colwidths)]
13341334
lines_cells = [[cl[i] for cl in cells_lines] for i in range(nlines)]
13351335
for ln in lines_cells:
1336-
padded_ln = _pad_row(ln, 1)
1336+
padded_ln = _pad_row(ln, pad)
13371337
_append_basic_row(lines, padded_ln, colwidths, colaligns, rowfmt)
13381338
return lines
13391339

test/test_output.py

+15
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,21 @@ def test_simple():
4444
assert_equal(expected, result)
4545

4646

47+
def test_simple_multiline():
48+
"Output: simple with multiline cells"
49+
expected = "\n".join([
50+
" key value",
51+
"----- ---------",
52+
" foo bar",
53+
"spam multiline",
54+
" world",
55+
])
56+
table = [["key", "value"], ["foo", "bar"], ["spam", "multiline\nworld"]]
57+
result = tabulate(table, headers='firstrow', stralign="center",
58+
tablefmt="simple")
59+
assert_equal(expected, result)
60+
61+
4762
def test_simple_headerless():
4863
"Output: simple without headers"
4964
expected = "\n".join(['---- --------',

0 commit comments

Comments
 (0)