diff --git a/CHANGES.md b/CHANGES.md index fa0cf274..8911b5cb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,7 @@ ## python-markdown2 2.5.6 (not yet released) +- [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) 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`|