From 2a67426724ac3ea100bd713ee739b4ba64752d33 Mon Sep 17 00:00:00 2001 From: mika <211269698+mikamikasuki@users.noreply.github.com> Date: Fri, 2 Oct 2026 20:22:11 -0700 Subject: [PATCH 1/2] Fix table boundaries around multi-backtick code spans --- CHANGES.md | 1 + README.md | 4 +++ lib/markdown2.py | 15 +++++--- .../tables_multibacktick_code_spans.html | 34 +++++++++++++++++++ .../tables_multibacktick_code_spans.opts | 1 + .../tables_multibacktick_code_spans.text | 8 +++++ 6 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 test/tm-cases/tables_multibacktick_code_spans.html create mode 100644 test/tm-cases/tables_multibacktick_code_spans.opts create mode 100644 test/tm-cases/tables_multibacktick_code_spans.text diff --git a/CHANGES.md b/CHANGES.md index fa0cf274..9fbea942 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,7 @@ ## python-markdown2 2.5.6 (not yet released) +- Fix `tables` extra splitting multi-backtick code spans at a leading pipe and merging cells after a code span containing literal backticks. - [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) diff --git a/README.md b/README.md index 2c3a988c..59539f63 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,10 @@ as a script: The `footnotes` extra keeps the same number when a footnote is referenced more than once. +The `tables` extra supports code spans delimited by single or multiple backticks, +including an operator cell such as ```` ``|`` ````. A pipe immediately after the +closing delimiter separates the next cell. + There are a number of currently implemented extras for tables, footnotes, syntax coloring of `
`-blocks, auto-linking patterns, table of contents,
 Smarty Pants (for fancy quotes, dashes, etc.) and more. See the [Extras
diff --git a/lib/markdown2.py b/lib/markdown2.py
index 9243bee8..b3c29847 100755
--- a/lib/markdown2.py
+++ b/lib/markdown2.py
@@ -4260,12 +4260,19 @@ 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('|')
+        code_spans = list(Markdown._code_span_re.finditer(row))
+        code_starts = {m.start(2) for m in code_spans}
+        code_ends = {m.end() for m in code_spans}
         cells, start = [], 0
         for m in re.finditer(r'(?
+
+
+  Operator
+  Meaning
+
+
+
+
+  |
+  bitwise or
+
+
+  |
+  bitwise or
+
+
+  |
+  bitwise or
+
+
+  x`y
+  literal backtick
+
+
+  x``y
+  two literal backticks
+
+
+  |
+  or
+
+
+
diff --git a/test/tm-cases/tables_multibacktick_code_spans.opts b/test/tm-cases/tables_multibacktick_code_spans.opts
new file mode 100644
index 00000000..23983798
--- /dev/null
+++ b/test/tm-cases/tables_multibacktick_code_spans.opts
@@ -0,0 +1 @@
+{"extras": ["tables"]}
diff --git a/test/tm-cases/tables_multibacktick_code_spans.text b/test/tm-cases/tables_multibacktick_code_spans.text
new file mode 100644
index 00000000..09c72e5f
--- /dev/null
+++ b/test/tm-cases/tables_multibacktick_code_spans.text
@@ -0,0 +1,8 @@
+| Operator | Meaning |
+| --- | --- |
+| `|` | bitwise or |
+| ``|`` | bitwise or |
+| ````|```` | bitwise or |
+|``x`y``|literal backtick|
+|````x``y````|two literal backticks|
+|``|``|`or`|

From ff030667fcd01396bad61691ba7b59db2bf310ae Mon Sep 17 00:00:00 2001
From: mika <211269698+mikamikasuki@users.noreply.github.com>
Date: Sun, 4 Oct 2026 13:14:57 -0700
Subject: [PATCH 2/2] Fix changelog entry format

---
 CHANGES.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/CHANGES.md b/CHANGES.md
index 9fbea942..8911b5cb 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -2,7 +2,7 @@
 
 ## python-markdown2 2.5.6 (not yet released)
 
-- Fix `tables` extra splitting multi-backtick code spans at a leading pipe and merging cells after a code span containing literal backticks.
+- [pull #730] Fix `tables` extra splitting multi-backtick code spans at a leading pipe and merging cells after a code span containing literal backticks.
 - [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)