From 920a177434218af7fe02b6c7797c99c31fa499de Mon Sep 17 00:00:00 2001 From: KBS Date: Tue, 29 Sep 2026 15:48:51 +0900 Subject: [PATCH 1/2] Split table cells on a pipe that follows a closing code span backtick _split_row did not split on any pipe preceded by a backtick, to keep `|` inside a cell (#399). That also covered a pipe right after the backtick that closes a code span, so a compact row like |`-v`|verbose| put "verbose" into the first cell. Only keep the pipe when the backtick before it opens a code span. --- CHANGES.md | 1 + lib/markdown2.py | 14 ++++++++++---- .../tables_code_span_adjacent_pipe.html | 18 ++++++++++++++++++ .../tables_code_span_adjacent_pipe.opts | 1 + .../tables_code_span_adjacent_pipe.text | 4 ++++ 5 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 test/tm-cases/tables_code_span_adjacent_pipe.html create mode 100644 test/tm-cases/tables_code_span_adjacent_pipe.opts create mode 100644 test/tm-cases/tables_code_span_adjacent_pipe.text diff --git a/CHANGES.md b/CHANGES.md index b0c5e7bd..c7afd97e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,7 @@ ## python-markdown2 2.5.6 (not yet released) +- [pull #XXX] Fix `tables` extra merging cells when a pipe directly follows a code span, as in compact rows like `|`-v`|verbose|`. - [pull #725] Fix `tables` extra dropping escaped pipes at the end of header and body rows. - [pull #687] Fix AssertionError hashing HTML blocks spread over multiple lines (#686) - [pull #692] Fix XSS from code spans in link titles (#691) diff --git a/lib/markdown2.py b/lib/markdown2.py index 5fa8cf58..9243bee8 100755 --- a/lib/markdown2.py +++ b/lib/markdown2.py @@ -4260,10 +4260,16 @@ def _split_row(row: str) -> list[str]: # An escaped final pipe belongs to the last cell, not the table border. if not row.endswith(r'\|'): row = row.removesuffix('|') - return [ - re.sub(r'\\\|', '|', cell.strip()) - for cell in re.split(r'(? str: head, underline, body = match.groups() diff --git a/test/tm-cases/tables_code_span_adjacent_pipe.html b/test/tm-cases/tables_code_span_adjacent_pipe.html new file mode 100644 index 00000000..2fba4711 --- /dev/null +++ b/test/tm-cases/tables_code_span_adjacent_pipe.html @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + +
FlagMeaning
-vverbose
-qquiet
diff --git a/test/tm-cases/tables_code_span_adjacent_pipe.opts b/test/tm-cases/tables_code_span_adjacent_pipe.opts new file mode 100644 index 00000000..9625694e --- /dev/null +++ b/test/tm-cases/tables_code_span_adjacent_pipe.opts @@ -0,0 +1 @@ +{"extras": ["tables"]} \ No newline at end of file diff --git a/test/tm-cases/tables_code_span_adjacent_pipe.text b/test/tm-cases/tables_code_span_adjacent_pipe.text new file mode 100644 index 00000000..ea525d3b --- /dev/null +++ b/test/tm-cases/tables_code_span_adjacent_pipe.text @@ -0,0 +1,4 @@ +|Flag|Meaning| +|-|-| +|`-v`|verbose| +|`-q`|`quiet`| From 3e7637105f8b878f20cb1951a4bfe4ce18610b7a Mon Sep 17 00:00:00 2001 From: KBS Date: Tue, 29 Sep 2026 15:49:09 +0900 Subject: [PATCH 2/2] Add the PR number to the change note --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index c7afd97e..fa0cf274 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,7 +2,7 @@ ## python-markdown2 2.5.6 (not yet released) -- [pull #XXX] Fix `tables` extra merging cells when a pipe directly follows a code span, as in compact rows like `|`-v`|verbose|`. +- [pull #729] Fix `tables` extra merging cells when a pipe directly follows a code span, as in compact rows like `|`-v`|verbose|`. - [pull #725] Fix `tables` extra dropping escaped pipes at the end of header and body rows. - [pull #687] Fix AssertionError hashing HTML blocks spread over multiple lines (#686) - [pull #692] Fix XSS from code spans in link titles (#691)