From a52b0c4f98ede2e9389a25592f0fa567e94f70e1 Mon Sep 17 00:00:00 2001 From: Crozzers Date: Sat, 24 May 2025 11:00:12 +0100 Subject: [PATCH] Fix nbsp breaking tables --- CHANGES.md | 1 + lib/markdown2.py | 2 +- test/tm-cases/tables_nbsp_issue629.html | 14 ++++++++++++++ test/tm-cases/tables_nbsp_issue629.opts | 1 + test/tm-cases/tables_nbsp_issue629.text | 3 +++ 5 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 test/tm-cases/tables_nbsp_issue629.html create mode 100644 test/tm-cases/tables_nbsp_issue629.opts create mode 100644 test/tm-cases/tables_nbsp_issue629.text diff --git a/CHANGES.md b/CHANGES.md index 1798e3d5..26cde7b0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,7 @@ - [pull #623] Don't escape plus signs in URLs (#621) - [pull #626] Fix XSS when encoding incomplete tags (#625) - [pull #628] Fix TypeError in MiddleWordEm extra when options was None (#627) +- [pull #630] Fix nbsp breaking tables (#629) ## python-markdown2 2.5.3 diff --git a/lib/markdown2.py b/lib/markdown2.py index 19cfca61..265bb7d1 100755 --- a/lib/markdown2.py +++ b/lib/markdown2.py @@ -3576,7 +3576,7 @@ def run(self, text): return table_re.sub(self.sub, text) def sub(self, match: re.Match) -> str: - trim_space_re = '^[ \t\n]+|[ \t\n]+$' + trim_space_re = r'^\s+|\s+$' trim_bar_re = r'^\||\|$' split_bar_re = r'^\||(? + + + A + B + + + + + Foo + 123 + + + diff --git a/test/tm-cases/tables_nbsp_issue629.opts b/test/tm-cases/tables_nbsp_issue629.opts new file mode 100644 index 00000000..0fe946d7 --- /dev/null +++ b/test/tm-cases/tables_nbsp_issue629.opts @@ -0,0 +1 @@ +{'extras': ['tables']} \ No newline at end of file diff --git a/test/tm-cases/tables_nbsp_issue629.text b/test/tm-cases/tables_nbsp_issue629.text new file mode 100644 index 00000000..56aaad75 --- /dev/null +++ b/test/tm-cases/tables_nbsp_issue629.text @@ -0,0 +1,3 @@ +| A | B | +|-----|-----|  +| Foo | 123 | \ No newline at end of file