From 6f7780ce5a8360a81568a099a1fa628afbc653b4 Mon Sep 17 00:00:00 2001 From: Crozzers Date: Sun, 10 Dec 2023 12:43:49 +0000 Subject: [PATCH 1/3] Fix tables with trailing whitespace not being recognized (#549) --- lib/markdown2.py | 8 +++---- test/tm-cases/trailing_table_whitespace.html | 22 ++++++++++++++++++++ test/tm-cases/trailing_table_whitespace.opts | 1 + test/tm-cases/trailing_table_whitespace.text | 5 +++++ 4 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 test/tm-cases/trailing_table_whitespace.html create mode 100644 test/tm-cases/trailing_table_whitespace.opts create mode 100644 test/tm-cases/trailing_table_whitespace.text diff --git a/lib/markdown2.py b/lib/markdown2.py index 7d36c1c3..1ec7da20 100755 --- a/lib/markdown2.py +++ b/lib/markdown2.py @@ -1241,21 +1241,21 @@ def _do_tables(self, text): (?:(?<=\n\n)|\A\n?) # leading blank line ^[ ]{0,%d} # allowed whitespace - (.*[|].*) \n # $1: header row (at least one pipe) + (.*[|].*)[ ]*\n # $1: header row (at least one pipe) ^[ ]{0,%d} # allowed whitespace ( # $2: underline row # underline row with leading bar - (?: \|\ *:?-+:?\ * )+ \|? \s? \n + (?: \|\ *:?-+:?\ * )+ \|? \s?[ ]*\n | # or, underline row without leading bar - (?: \ *:?-+:?\ *\| )+ (?: \ *:?-+:?\ * )? \s? \n + (?: \ *:?-+:?\ *\| )+ (?: \ *:?-+:?\ * )? \s?[ ]*\n ) ( # $3: data rows (?: ^[ ]{0,%d}(?!\ ) # ensure line begins with 0 to less_than_tab spaces - .*\|.* \n + .*\|.*[ ]*\n )+ ) ''' % (less_than_tab, less_than_tab, less_than_tab), re.M | re.X) diff --git a/test/tm-cases/trailing_table_whitespace.html b/test/tm-cases/trailing_table_whitespace.html new file mode 100644 index 00000000..e0a19866 --- /dev/null +++ b/test/tm-cases/trailing_table_whitespace.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + +
ProsCons
Unique and refreshing take on the genreMay not resonate with all viewers
Cult classic statusOver-the-top humor may polarize audiences
Influential in launching careersNiche appeal among comedy aficionados
diff --git a/test/tm-cases/trailing_table_whitespace.opts b/test/tm-cases/trailing_table_whitespace.opts new file mode 100644 index 00000000..23983798 --- /dev/null +++ b/test/tm-cases/trailing_table_whitespace.opts @@ -0,0 +1 @@ +{"extras": ["tables"]} diff --git a/test/tm-cases/trailing_table_whitespace.text b/test/tm-cases/trailing_table_whitespace.text new file mode 100644 index 00000000..08748799 --- /dev/null +++ b/test/tm-cases/trailing_table_whitespace.text @@ -0,0 +1,5 @@ +| Pros | Cons | +|-----------------------------------------|------------------------------------------------| +| Unique and refreshing take on the genre | May not resonate with all viewers | +| Cult classic status | Over-the-top humor may polarize audiences | +| Influential in launching careers | Niche appeal among comedy aficionados | From 3b3e84599968911ef2db5a719ff650106dd65ea4 Mon Sep 17 00:00:00 2001 From: Crozzers Date: Sun, 10 Dec 2023 12:45:41 +0000 Subject: [PATCH 2/3] Update changelog --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 2726cc8c..d8008741 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,7 +2,7 @@ ## python-markdown2 2.4.12 (not yet released) -(nothing yet) +- [pull #550] Fix tables with trailing whitespace not being recognized (#549) ## python-markdown2 2.4.11 From 68be7da8ede217aa72e32ce6a235acf7f7a94d6b Mon Sep 17 00:00:00 2001 From: Crozzers Date: Sun, 10 Dec 2023 12:47:31 +0000 Subject: [PATCH 3/3] Always normalise EOLs in test harness --- test/test_markdown2.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/test_markdown2.py b/test/test_markdown2.py index cc2a80b2..1f08afd5 100755 --- a/test/test_markdown2.py +++ b/test/test_markdown2.py @@ -345,8 +345,7 @@ def norm_html_from_html(html): html = html.decode('utf-8') html = _markdown_email_link_re.sub( _markdown_email_link_sub, html) - if sys.platform == "win32": - html = html.replace('\r\n', '\n') + html = html.replace('\r\n', '\n') return html