From f93c71eb317daad886cff829678da4db44eb2a9e Mon Sep 17 00:00:00 2001 From: Raul Bocanegra Algarra Date: Wed, 18 Dec 2024 00:34:49 +0100 Subject: [PATCH 1/7] fix: make tables without body gfm compatible --- lib/markdown2.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/markdown2.py b/lib/markdown2.py index 72e56327..f7fc207b 100755 --- a/lib/markdown2.py +++ b/lib/markdown2.py @@ -3379,7 +3379,7 @@ def run(self, text): (?: ^[ ]{0,%d}(?!\ ) # ensure line begins with 0 to less_than_tab spaces .*\|.*[ ]*\n - )+ + )* ) ''' % (less_than_tab, less_than_tab, less_than_tab), re.M | re.X) return table_re.sub(self.sub, text) @@ -3415,17 +3415,19 @@ def sub(self, match: re.Match) -> str: hlines.append('') # tbody - hlines.append('') - for line in body.strip('\n').split('\n'): - hlines.append('') - cols = [re.sub(escape_bar_re, '|', cell.strip()) for cell in re.split(split_bar_re, re.sub(trim_bar_re, "", re.sub(trim_space_re, "", line)))] - for col_idx, col in enumerate(cols): - hlines.append(' {}'.format( - align_from_col_idx.get(col_idx, ''), - self.md._run_span_gamut(col) - )) - hlines.append('') - hlines.append('') + body = body.strip('\n') + if body: + hlines.append('') + for line in body.strip('\n').split('\n'): + hlines.append('') + cols = [re.sub(escape_bar_re, '|', cell.strip()) for cell in re.split(split_bar_re, re.sub(trim_bar_re, "", re.sub(trim_space_re, "", line)))] + for col_idx, col in enumerate(cols): + hlines.append(' {}'.format( + align_from_col_idx.get(col_idx, ''), + self.md._run_span_gamut(col) + )) + hlines.append('') + hlines.append('') hlines.append('') return '\n'.join(hlines) + '\n' From c74a174c4fb9bf9c4984c3352a53acb45bb036c4 Mon Sep 17 00:00:00 2001 From: Raul Bocanegra Algarra Date: Wed, 18 Dec 2024 00:41:03 +0100 Subject: [PATCH 2/7] add test to tables.text --- test/tm-cases/tables.text | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/tm-cases/tables.text b/test/tm-cases/tables.text index 0cd4e53c..7badef2d 100644 --- a/test/tm-cases/tables.text +++ b/test/tm-cases/tables.text @@ -156,3 +156,9 @@ the rule is it must have at least a single dash in there. | A | \| | C \| C | |--- |--- | ------ | |\|\|| BB | C | + +# table without rows + +| abc | def | +| --- | --- | + From 381f60f4b0b9dd4ffa603d8a0b1a5e6116380d69 Mon Sep 17 00:00:00 2001 From: Raul Bocanegra Algarra Date: Wed, 18 Dec 2024 00:43:30 +0100 Subject: [PATCH 3/7] Update tables.html --- test/tm-cases/tables.html | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/tm-cases/tables.html b/test/tm-cases/tables.html index 7a262d81..12b64529 100644 --- a/test/tm-cases/tables.html +++ b/test/tm-cases/tables.html @@ -394,3 +394,15 @@

escaping of pipes

+ +

tables without rows

+ + + + + + + + +
abcdef
+ From eea893c6f7eaa4d1453d2020f268ade9fe5d83ff Mon Sep 17 00:00:00 2001 From: Raul Bocanegra Algarra Date: Wed, 18 Dec 2024 00:46:34 +0100 Subject: [PATCH 4/7] Update markdown2.py --- lib/markdown2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/markdown2.py b/lib/markdown2.py index f7fc207b..01380593 100755 --- a/lib/markdown2.py +++ b/lib/markdown2.py @@ -3418,7 +3418,7 @@ def sub(self, match: re.Match) -> str: body = body.strip('\n') if body: hlines.append('') - for line in body.strip('\n').split('\n'): + for line in body.split('\n'): hlines.append('') cols = [re.sub(escape_bar_re, '|', cell.strip()) for cell in re.split(split_bar_re, re.sub(trim_bar_re, "", re.sub(trim_space_re, "", line)))] for col_idx, col in enumerate(cols): From adba6980188d2f6fb7cf964a9331d68a45e7d59e Mon Sep 17 00:00:00 2001 From: Raul Bocanegra Algarra Date: Wed, 18 Dec 2024 00:57:29 +0100 Subject: [PATCH 5/7] Update tables.html --- test/tm-cases/tables.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tm-cases/tables.html b/test/tm-cases/tables.html index 12b64529..885387af 100644 --- a/test/tm-cases/tables.html +++ b/test/tm-cases/tables.html @@ -395,7 +395,7 @@

escaping of pipes

-

tables without rows

+

table without rows

From 096fbb234c68eb747e344cf5fc5f92774761685d Mon Sep 17 00:00:00 2001 From: Raul Bocanegra Algarra Date: Wed, 18 Dec 2024 00:59:23 +0100 Subject: [PATCH 6/7] Update tables.text --- test/tm-cases/tables.text | 1 - 1 file changed, 1 deletion(-) diff --git a/test/tm-cases/tables.text b/test/tm-cases/tables.text index 7badef2d..ed7512ae 100644 --- a/test/tm-cases/tables.text +++ b/test/tm-cases/tables.text @@ -161,4 +161,3 @@ the rule is it must have at least a single dash in there. | abc | def | | --- | --- | - From 1dfef834bb125c5ce9e5aa946478b7dd4bc19e35 Mon Sep 17 00:00:00 2001 From: Raul Bocanegra Algarra Date: Wed, 18 Dec 2024 01:01:14 +0100 Subject: [PATCH 7/7] Update tables.html --- test/tm-cases/tables.html | 1 - 1 file changed, 1 deletion(-) diff --git a/test/tm-cases/tables.html b/test/tm-cases/tables.html index 885387af..3f919a1e 100644 --- a/test/tm-cases/tables.html +++ b/test/tm-cases/tables.html @@ -405,4 +405,3 @@

table without rows

-