Skip to content

Escape pipes in table cell content - #319

Open
draarivpatel-ui wants to merge 1 commit into
matthewwithanm:developfrom
draarivpatel-ui:fix/escape-table-cell-pipes
Open

draarivpatel-ui wants to merge 1 commit into
matthewwithanm:developfrom
draarivpatel-ui:fix/escape-table-cell-pipes

Conversation

@draarivpatel-ui

Copy link
Copy Markdown

A literal | in a table cell was emitted verbatim:

>>> markdownify("<table><tr><th>H</th></tr><tr><td>a|b</td></tr></table>")
'\n\n| H |\n| --- |\n| a|b |\n\n'

The pipe ends the cell when the Markdown is re-parsed, so one row becomes two cells and the remaining columns shift. escape_misc=True masks the problem for plain text, but pipes inside <code> (which deliberately skips escaping for preformatted content) still break the table, and the default output is wrong either way.

Escape unescaped pipes when a cell is emitted, and leave already-escaped pipes alone so escape_misc=True does not end up with a doubled backslash. Added regression tests for plain text, code spans, and escape_misc=True; the full suite passes.

A literal '|' in a <td> or <th> was written to the Markdown table
as-is, so it ended the cell early: '<td>a|b</td>' produced
'| a|b |', which re-parses as two cells and shifts the rest of the row.
escape_misc=True happened to escape the pipe, but the default output
and pipes inside <code> (which skips escaping for preformatted
content) were still broken.

Escape unescaped pipes when emitting a cell. Already-escaped pipes are
left alone so escape_misc output does not gain a second backslash.
Copilot AI balanced review requested due to automatic review settings November 26, 2026 01:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants