From 96a25cfbf3c4b00d226d20ee97d9d7f39c2c60e0 Mon Sep 17 00:00:00 2001 From: AlexVonB Date: Tue, 26 Mar 2024 21:05:31 +0100 Subject: [PATCH] added tests for linebreaks in table cells --- markdownify/__init__.py | 2 +- tests/test_tables.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/markdownify/__init__.py b/markdownify/__init__.py index eaa58c1..f9b5f9b 100644 --- a/markdownify/__init__.py +++ b/markdownify/__init__.py @@ -370,7 +370,7 @@ def convert_table(self, el, text, convert_as_inline): return '\n\n' + text + '\n' def convert_td(self, el, text, convert_as_inline): - return ' ' + text.strip() + ' |' + return ' ' + text.strip().replace("\n", " ") + ' |' def convert_th(self, el, text, convert_as_inline): return ' ' + text + ' |' diff --git a/tests/test_tables.py b/tests/test_tables.py index e0c07ea..334bfb7 100644 --- a/tests/test_tables.py +++ b/tests/test_tables.py @@ -57,6 +57,26 @@ """ +table_with_linebreaks = """ + + + + + + + + + + + + + + + +
FirstnameLastnameAge
JillSmith + Jackson50
EveJackson + Smith94
""" + table_with_header_column = """ @@ -164,6 +184,7 @@ def test_table(): assert md(table) == '\n\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n| Jill | Smith | 50 |\n| Eve | Jackson | 94 |\n\n' assert md(table_with_html_content) == '\n\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n| **Jill** | *Smith* | [50](#) |\n| Eve | Jackson | 94 |\n\n' assert md(table_with_paragraphs) == '\n\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n| Jill | Smith | 50 |\n| Eve | Jackson | 94 |\n\n' + assert md(table_with_linebreaks) == '\n\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n| Jill | Smith Jackson | 50 |\n| Eve | Jackson Smith | 94 |\n\n' assert md(table_with_header_column) == '\n\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n| Jill | Smith | 50 |\n| Eve | Jackson | 94 |\n\n' assert md(table_head_body) == '\n\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n| Jill | Smith | 50 |\n| Eve | Jackson | 94 |\n\n' assert md(table_missing_text) == '\n\n| | Lastname | Age |\n| --- | --- | --- |\n| Jill | | 50 |\n| Eve | Jackson | 94 |\n\n'