guard table lines with pipes, resolves the empty header problem

This commit is contained in:
AlexVonB
2021-04-22 12:36:11 +02:00
parent de6f91af0e
commit e1dbbfad42
2 changed files with 7 additions and 8 deletions

View File

@@ -245,12 +245,11 @@ class MarkdownConverter(object):
columns = row.find_all('td')
if len(headers) > 0:
headers = [head.text.strip() for head in headers]
headers = [head for head in headers if head]
text_data.append(' | '.join(headers))
text_data.append(' | '.join(['---'] * len(headers)))
text_data.append('| ' + ' | '.join(headers) + ' |')
text_data.append('| ' + ' | '.join(['---'] * len(headers)) + ' |')
elif len(columns) > 0:
columns = [colm.text.strip() for colm in columns]
text_data.append(' | '.join(columns))
text_data.append('| ' + ' | '.join(columns) + ' |')
else:
continue
return '\n'.join(text_data)