Skip to content

fix: handle escaped pipe characters in markdown table cells#2503

Open
Br1an67 wants to merge 1 commit intoQwenLM:mainfrom
Br1an67:fix/table-pipe-escape
Open

fix: handle escaped pipe characters in markdown table cells#2503
Br1an67 wants to merge 1 commit intoQwenLM:mainfrom
Br1an67:fix/table-pipe-escape

Conversation

@Br1an67
Copy link
Copy Markdown
Contributor

@Br1an67 Br1an67 commented Mar 19, 2026

TLDR

Table cells containing literal | characters (e.g. A|B) were incorrectly split across columns. This fixes the markdown table parser to respect escaped \| sequences.

Dive Deeper

The MarkdownDisplay.tsx component parses markdown tables by splitting rows on | using split("|"). This treats every | as a column delimiter, even when the character is part of the cell content (e.g. type unions A|B, regex patterns [a|b]).

Root cause: Lines 114 and 130 of MarkdownDisplay.tsx used naive split("|").

Fix: Added a splitTableCells() helper that:

  1. Splits on unescaped | only, using a negative lookbehind regex: /(?<!\\)\|/
  2. Un-escapes \| back to | in each cell via .replace(/\\\|/g, "|")

This follows standard markdown table escaping conventions (e.g. GitHub Flavored Markdown).

Testing Matrix

  • Existing 32 MarkdownDisplay tests pass
  • New test: table with A\|B renders as A|B in a single cell
  • New test: verifies \| is not left as literal escaped text

Closes #2461

Table cells containing literal `|` characters (e.g. `A|B`) were
incorrectly split across columns because the parser used a naive
`split('|')`. This adds a `splitTableCells` helper that splits on
unescaped `|` only (using a negative lookbehind) and then un-escapes
`\\\|` back to `|` in each cell.

Closes QwenLM#2461
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.

The | character is missing from the output of tables.

1 participant