Skip to content

Commit 96a25cf

Browse files
committed
added tests for linebreaks in table cells
1 parent 0477a0c commit 96a25cf

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

markdownify/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ def convert_table(self, el, text, convert_as_inline):
370370
return '\n\n' + text + '\n'
371371

372372
def convert_td(self, el, text, convert_as_inline):
373-
return ' ' + text.strip() + ' |'
373+
return ' ' + text.strip().replace("\n", " ") + ' |'
374374

375375
def convert_th(self, el, text, convert_as_inline):
376376
return ' ' + text + ' |'

tests/test_tables.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,26 @@
5757
</tr>
5858
</table>"""
5959

60+
table_with_linebreaks = """<table>
61+
<tr>
62+
<th>Firstname</th>
63+
<th>Lastname</th>
64+
<th>Age</th>
65+
</tr>
66+
<tr>
67+
<td>Jill</td>
68+
<td>Smith
69+
Jackson</td>
70+
<td>50</td>
71+
</tr>
72+
<tr>
73+
<td>Eve</td>
74+
<td>Jackson
75+
Smith</td>
76+
<td>94</td>
77+
</tr>
78+
</table>"""
79+
6080

6181
table_with_header_column = """<table>
6282
<tr>
@@ -164,6 +184,7 @@ def test_table():
164184
assert md(table) == '\n\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n| Jill | Smith | 50 |\n| Eve | Jackson | 94 |\n\n'
165185
assert md(table_with_html_content) == '\n\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n| **Jill** | *Smith* | [50](#) |\n| Eve | Jackson | 94 |\n\n'
166186
assert md(table_with_paragraphs) == '\n\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n| Jill | Smith | 50 |\n| Eve | Jackson | 94 |\n\n'
187+
assert md(table_with_linebreaks) == '\n\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n| Jill | Smith Jackson | 50 |\n| Eve | Jackson Smith | 94 |\n\n'
167188
assert md(table_with_header_column) == '\n\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n| Jill | Smith | 50 |\n| Eve | Jackson | 94 |\n\n'
168189
assert md(table_head_body) == '\n\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n| Jill | Smith | 50 |\n| Eve | Jackson | 94 |\n\n'
169190
assert md(table_missing_text) == '\n\n| | Lastname | Age |\n| --- | --- | --- |\n| Jill | | 50 |\n| Eve | Jackson | 94 |\n\n'

0 commit comments

Comments
 (0)