@@ -383,13 +383,13 @@ class MarkdownConverter(object):
|
||||
|
||||
def convert_td(self, el, text, convert_as_inline):
|
||||
colspan = 1
|
||||
if 'colspan' in el.attrs:
|
||||
if 'colspan' in el.attrs and el['colspan'].isdigit():
|
||||
colspan = int(el['colspan'])
|
||||
return ' ' + text.strip().replace("\n", " ") + ' |' * colspan
|
||||
|
||||
def convert_th(self, el, text, convert_as_inline):
|
||||
colspan = 1
|
||||
if 'colspan' in el.attrs:
|
||||
if 'colspan' in el.attrs and el['colspan'].isdigit():
|
||||
colspan = int(el['colspan'])
|
||||
return ' ' + text.strip().replace("\n", " ") + ' |' * colspan
|
||||
|
||||
@@ -406,7 +406,7 @@ class MarkdownConverter(object):
|
||||
# first row and is headline: print headline underline
|
||||
full_colspan = 0
|
||||
for cell in cells:
|
||||
if "colspan" in cell.attrs:
|
||||
if 'colspan' in cell.attrs and cell['colspan'].isdigit():
|
||||
full_colspan += int(cell["colspan"])
|
||||
else:
|
||||
full_colspan += 1
|
||||
|
||||
@@ -215,7 +215,7 @@ table_with_colspan = """<table>
|
||||
<th>Age</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Jill</td>
|
||||
<td colspan="1">Jill</td>
|
||||
<td>Smith</td>
|
||||
<td>50</td>
|
||||
</tr>
|
||||
@@ -226,6 +226,17 @@ table_with_colspan = """<table>
|
||||
</tr>
|
||||
</table>"""
|
||||
|
||||
table_with_undefined_colspan = """<table>
|
||||
<tr>
|
||||
<th colspan="undefined">Name</th>
|
||||
<th>Age</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="-1">Jill</td>
|
||||
<td>Smith</td>
|
||||
</tr>
|
||||
</table>"""
|
||||
|
||||
|
||||
def test_table():
|
||||
assert md(table) == '\n\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n| Jill | Smith | 50 |\n| Eve | Jackson | 94 |\n\n'
|
||||
@@ -240,3 +251,4 @@ def test_table():
|
||||
assert md(table_body) == '\n\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n| Jill | Smith | 50 |\n| Eve | Jackson | 94 |\n\n'
|
||||
assert md(table_with_caption) == 'TEXT\n\nCaption\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n\n'
|
||||
assert md(table_with_colspan) == '\n\n| Name | | Age |\n| --- | --- | --- |\n| Jill | Smith | 50 |\n| Eve | Jackson | 94 |\n\n'
|
||||
assert md(table_with_undefined_colspan) == '\n\n| Name | Age |\n| --- | --- |\n| Jill | Smith |\n\n'
|
||||
|
||||
Reference in New Issue
Block a user