diff --git a/markdownify/__init__.py b/markdownify/__init__.py index d6d36a0..8461c1c 100644 --- a/markdownify/__init__.py +++ b/markdownify/__init__.py @@ -370,8 +370,13 @@ class MarkdownConverter(object): if is_headrow and not el.previous_sibling: # first row and is headline: print headline underline underline += '| ' + ' | '.join(['---'] * len(cells)) + ' |' + '\n' - elif not el.previous_sibling and not el.parent.name != 'table': - # first row, not headline, and the parent is sth. like tbody: + elif (not el.previous_sibling + and (el.parent.name == 'table' + or (el.parent.name == 'tbody' + and not el.parent.previous_sibling))): + # first row, not headline, and: + # - the parent is table or + # - the parent is tbody at the beginning of a table. # print empty headline above this row overline += '| ' + ' | '.join([''] * len(cells)) + ' |' + '\n' overline += '| ' + ' | '.join(['---'] * len(cells)) + ' |' + '\n' diff --git a/tests/test_tables.py b/tests/test_tables.py index 27d4403..e0c07ea 100644 --- a/tests/test_tables.py +++ b/tests/test_tables.py @@ -139,6 +139,26 @@ table_missing_head = """
| Firstname | +Lastname | +Age | +
| Jill | +Smith | +50 | +
| Eve | +Jackson | +94 | +