From 8c28ade348d766705513e07ecb700718a1eb7f2c Mon Sep 17 00:00:00 2001 From: Bruno Miguens Date: Mon, 8 Feb 2021 20:50:15 +0000 Subject: [PATCH] Remove empty header validation to allow empty header --- markdownify/__init__.py | 3 +-- tests/test_conversions.py | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/markdownify/__init__.py b/markdownify/__init__.py index 5fdcbf3..fcdc32a 100644 --- a/markdownify/__init__.py +++ b/markdownify/__init__.py @@ -245,12 +245,11 @@ 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: columns = [colm.text.strip() for colm in columns] - text_data.append(' | '.join([colm for colm in columns if colm])) + text_data.append(' | '.join(columns)) else: continue return '\n'.join(text_data) diff --git a/tests/test_conversions.py b/tests/test_conversions.py index cff19bd..2d2e825 100644 --- a/tests/test_conversions.py +++ b/tests/test_conversions.py @@ -67,6 +67,30 @@ table_head_body = re.sub(r'\s+', '', """ """) +table_missing_header = re.sub(r'\s+', '', """ + + + + + + + + + + + + + + + + + + + + +
LastnameAge
JillSmith50
EveJackson94
+""") + def test_chomp(): assert md(' ') == ' ' @@ -267,3 +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'