diff --git a/markdownify/__init__.py b/markdownify/__init__.py
index 1e7b787..b67c32b 100644
--- a/markdownify/__init__.py
+++ b/markdownify/__init__.py
@@ -377,7 +377,11 @@ def convert_th(self, el, text, convert_as_inline):
def convert_tr(self, el, text, convert_as_inline):
cells = el.find_all(['td', 'th'])
- is_headrow = all([cell.name == 'th' for cell in cells])
+ is_headrow = (
+ all([cell.name == 'th' for cell in cells])
+ or (not el.previous_sibling and not el.parent.name == 'tbody')
+ or (not el.previous_sibling and el.parent.name == 'tbody' and len(el.parent.parent.find_all(['thead'])) < 1)
+ )
overline = ''
underline = ''
if is_headrow and not el.previous_sibling:
diff --git a/tests/test_tables.py b/tests/test_tables.py
index 334bfb7..ebbb146 100644
--- a/tests/test_tables.py
+++ b/tests/test_tables.py
@@ -119,6 +119,28 @@
"""
+table_head_body_missing_head = """
+
+
+ Firstname |
+ Lastname |
+ Age |
+
+
+
+
+ Jill |
+ Smith |
+ 50 |
+
+
+ Eve |
+ Jackson |
+ 94 |
+
+
+
"""
+
table_missing_text = """
@@ -187,6 +209,7 @@ def test_table():
assert md(table_with_linebreaks) == '\n\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n| Jill | Smith Jackson | 50 |\n| Eve | Jackson Smith | 94 |\n\n'
assert md(table_with_header_column) == '\n\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n| Jill | Smith | 50 |\n| Eve | Jackson | 94 |\n\n'
assert md(table_head_body) == '\n\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n| Jill | Smith | 50 |\n| Eve | Jackson | 94 |\n\n'
+ assert md(table_head_body_missing_head) == '\n\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n| Jill | Smith | 50 |\n| Eve | Jackson | 94 |\n\n'
assert md(table_missing_text) == '\n\n| | Lastname | Age |\n| --- | --- | --- |\n| Jill | | 50 |\n| Eve | Jackson | 94 |\n\n'
- assert md(table_missing_head) == '\n\n| | | |\n| --- | --- | --- |\n| Firstname | Lastname | Age |\n| Jill | Smith | 50 |\n| Eve | Jackson | 94 |\n\n'
- assert md(table_body) == '\n\n| | | |\n| --- | --- | --- |\n| Firstname | Lastname | Age |\n| Jill | Smith | 50 |\n| Eve | Jackson | 94 |\n\n'
+ assert md(table_missing_head) == '\n\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n| Jill | Smith | 50 |\n| Eve | Jackson | 94 |\n\n'
+ assert md(table_body) == '\n\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n| Jill | Smith | 50 |\n| Eve | Jackson | 94 |\n\n'