From de6f91af0e10e7ecaa8a758d216f24a15b99a44a Mon Sep 17 00:00:00 2001 From: Bruno Miguens Date: Mon, 8 Feb 2021 20:56:18 +0000 Subject: [PATCH] Revert header validation and leave possibility to empty column --- markdownify/__init__.py | 1 + tests/test_conversions.py | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/markdownify/__init__.py b/markdownify/__init__.py index fcdc32a..3bda85e 100644 --- a/markdownify/__init__.py +++ b/markdownify/__init__.py @@ -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: diff --git a/tests/test_conversions.py b/tests/test_conversions.py index 2d2e825..de3307f 100644 --- a/tests/test_conversions.py +++ b/tests/test_conversions.py @@ -67,11 +67,11 @@ table_head_body = re.sub(r'\s+', '', """ """) -table_missing_header = re.sub(r'\s+', '', """ +table_missing_text = re.sub(r'\s+', '', """ - + @@ -79,7 +79,7 @@ table_missing_header = re.sub(r'\s+', '', """ - + @@ -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'
Firstname Lastname Age
JillSmith 50