Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## python-markdown2 2.5.6 (not yet released)

- [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)
Expand Down
14 changes: 10 additions & 4 deletions lib/markdown2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'(?<![\`\\])\|', row)
]
cells, start = [], 0
for m in re.finditer(r'(?<!\\)\|', row):
# A pipe right after the backtick that opens a code span (`|`) stays in
# the cell; one right after a closing backtick is a cell border.
if m.start() and row[m.start() - 1] == '`' and row.count('`', 0, m.start()) % 2:
continue
cells.append(row[start:m.start()])
start = m.end()
cells.append(row[start:])
return [re.sub(r'\\\|', '|', cell.strip()) for cell in cells]

def sub(self, match: re.Match[str]) -> str:
head, underline, body = match.groups()
Expand Down
18 changes: 18 additions & 0 deletions test/tm-cases/tables_code_span_adjacent_pipe.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<table>
<thead>
<tr>
<th>Flag</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>-v</code></td>
<td>verbose</td>
</tr>
<tr>
<td><code>-q</code></td>
<td><code>quiet</code></td>
</tr>
</tbody>
</table>
1 change: 1 addition & 0 deletions test/tm-cases/tables_code_span_adjacent_pipe.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"extras": ["tables"]}
4 changes: 4 additions & 0 deletions test/tm-cases/tables_code_span_adjacent_pipe.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
|Flag|Meaning|
|-|-|
|`-v`|verbose|
|`-q`|`quiet`|
Loading