diff options
| author | Michael Williamson <mike@zwobble.org> | 2017-05-24 23:05:13 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2017-05-24 23:05:13 +0100 |
| commit | 803e22c8b95faa99aad82a4c9a30aa132f123416 (patch) | |
| tree | 4c6cd38d06a9878912108570a313002b5136c31e | |
| parent | b85162078e74dd3f523ce01c96ed2d27e1cda118 (diff) | |
Handle unexpected children in table
| -rw-r--r-- | mammoth/conversion.py | 5 | ||||
| -rw-r--r-- | tests/conversion_tests.py | 10 |
2 files changed, 14 insertions, 1 deletions
diff --git a/mammoth/conversion.py b/mammoth/conversion.py index cbe207a..eb09ded 100644 --- a/mammoth/conversion.py +++ b/mammoth/conversion.py @@ -166,7 +166,10 @@ class _DocumentConverter(documents.element_visitor(args=1)): def visit_table(self, table, context): - body_index = find_index(lambda child: not child.is_header, table.children) + body_index = find_index( + lambda child: not isinstance(child, documents.TableRow) or not child.is_header, + table.children, + ) if body_index is None: body_index = len(table.children) diff --git a/tests/conversion_tests.py b/tests/conversion_tests.py index 3fd9e34..9b81bf1 100644 --- a/tests/conversion_tests.py +++ b/tests/conversion_tests.py @@ -346,6 +346,16 @@ def tbody_is_omitted_if_all_rows_are_headers(): @istest +def unexpected_table_children_do_not_cause_error(): + table = documents.table([ + documents.tab(), + ]) + result = convert_document_element_to_html(table) + expected_html = "<table>\t</table>" + assert_equal(expected_html, result.value) + + +@istest def empty_cells_are_preserved_in_table(): table = documents.table([ documents.table_row([ |
