diff --git a/tabulate/__init__.py b/tabulate/__init__.py index 12a2950..9ba548b 100644 --- a/tabulate/__init__.py +++ b/tabulate/__init__.py @@ -204,6 +204,8 @@ def _html_begin_table_without_header(colwidths_ignore, colaligns_ignore): # this table header will be suppressed if there is a header row return "\n" +def _html_separating_line(colwidths, colaligns): + return "" % len(colwidths) def _html_row_with_attrs(celltag, unsafe, cell_values, colwidths, colaligns): alignment = { @@ -617,23 +619,23 @@ def escape_empty(val): ), "html": TableFormat( lineabove=_html_begin_table_without_header, - linebelowheader="", + linebelowheader=_html_separating_line, linebetweenrows=None, linebelow=Line("\n

", "", "", ""), headerrow=partial(_html_row_with_attrs, "th", False), datarow=partial(_html_row_with_attrs, "td", False), padding=0, - with_header_hide=["lineabove"], + with_header_hide=["lineabove","linebelowheader"], ), "unsafehtml": TableFormat( lineabove=_html_begin_table_without_header, - linebelowheader="", + linebelowheader=_html_separating_line, linebetweenrows=None, linebelow=Line("\n", "", "", ""), headerrow=partial(_html_row_with_attrs, "th", True), datarow=partial(_html_row_with_attrs, "td", True), padding=0, - with_header_hide=["lineabove"], + with_header_hide=["lineabove","linebelowheader"], ), "latex": TableFormat( lineabove=_latex_line_begin_tabular, diff --git a/test/test_output.py b/test/test_output.py index ea3da87..f9b21e2 100644 --- a/test/test_output.py +++ b/test/test_output.py @@ -2586,6 +2586,7 @@ def test_moinmoin_headerless(): _test_table_html_headers = ["", "<&numbers&>"] _test_table_html = [["spam >", 41.9999], ["eggs &", 451.0]] +_test_table_html_sepline = [["spam >", 41.9999], SEPARATING_LINE, ["eggs &", 451.0]] _test_table_unsafehtml_headers = ["strings", "numbers"] _test_table_unsafehtml = [ ["spam", '41.9999'], @@ -2655,6 +2656,41 @@ def test_html_headerless(): assert result._repr_html_() == result.str +def test_html_with_separating_line(): + expected = "\n".join( + [ + "", + "", + '', + '', + '', + "", + "
spam > 41.9999

eggs &451
", + ] + ) + result = tabulate(_test_table_html_sepline, tablefmt="html") + assert_equal(expected, result) + + +def test_html_headers_no_extra_line(): + # ensure that the extra hr isn't accidentally triggered + expected = "\n".join( + [ + "", + "", + '', + "", + "", + '', + '', + '', + "", + "
<strings> <&numbers&>
spam > 41.9999

eggs & 451
", + ] + ) + result = tabulate(_test_table_html_sepline,_test_table_html_headers, tablefmt="html") + assert_equal(expected, result) + def test_unsafehtml_headerless(): "Output: unsafe html without headers" expected = "\n".join(