Remove empty header validation to allow empty header

This commit is contained in:
Bruno Miguens
2021-02-08 20:50:15 +00:00
parent a152c5b706
commit 8c28ade348
2 changed files with 26 additions and 2 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)))
elif len(columns) > 0:
columns = [colm.text.strip() for colm in columns]
text_data.append(' | '.join([colm for colm in columns if colm]))
text_data.append(' | '.join(columns))
else:
continue
return '\n'.join(text_data)

View File

@@ -67,6 +67,30 @@ table_head_body = re.sub(r'\s+', '', """
</table>
""")
table_missing_header = re.sub(r'\s+', '', """
<table>
<thead>
<tr>
<th></th>
<th>Lastname</th>
<th>Age</th>
</tr>
</thead>
<tbody>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</tbody>
</table>
""")
def test_chomp():
assert md(' <b></b> ') == ' '
@@ -267,3 +291,4 @@ def test_div():
def test_table():
assert md(table) == 'Firstname | Lastname | Age\n--- | --- | ---\nJill | Smith | 50\nEve | Jackson | 94'
assert md(table_head_body) == 'Firstname | Lastname | Age\n--- | --- | ---\nJill | Smith | 50\nEve | Jackson | 94'
assert md(table_missing_header) == ' | Lastname | Age\n--- | --- | ---\nJill | Smith | 50\nEve | Jackson | 94'