Fix detection of "first row, not headline" (#63)

Improved handling of "first row, not headline".

Works for tables with
1) neither thead nor tbody
2) tbody but no thead
This commit is contained in:
Mikko Korpela
2022-04-14 11:24:32 +03:00
committed by GitHub
parent 87b9f6c88e
commit ebb9ea713d
2 changed files with 28 additions and 2 deletions

View File

@@ -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'