Revert header validation and leave possibility to empty column

This commit is contained in:
Bruno Miguens
2021-02-08 20:56:18 +00:00
parent 8c28ade348
commit de6f91af0e
2 changed files with 5 additions and 4 deletions

View File

@@ -245,6 +245,7 @@ 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:

View File

@@ -67,11 +67,11 @@ table_head_body = re.sub(r'\s+', '', """
</table>
""")
table_missing_header = re.sub(r'\s+', '', """
table_missing_text = re.sub(r'\s+', '', """
<table>
<thead>
<tr>
<th></th>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
@@ -79,7 +79,7 @@ table_missing_header = re.sub(r'\s+', '', """
<tbody>
<tr>
<td>Jill</td>
<td>Smith</td>
<td></td>
<td>50</td>
</tr>
<tr>
@@ -291,4 +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'
assert md(table_missing_text) == 'Firstname | Lastname | Age\n--- | --- | ---\nJill | | 50\nEve | Jackson | 94'