Skip to content

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

Closed
Br1an67 wants to merge 1 commit intoQwenLM:mainfrom
Br1an67:fix/table-pipe-split
Closed

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

Conversation

@Br1an67
Copy link
Copy Markdown
Contributor

@Br1an67 Br1an67 commented Mar 19, 2026

TLDR

Fixes table rendering when cells contain literal | characters (e.g. A|B). Previously, the naive .split("|") incorrectly broke such content into separate columns. Now uses a regex split on unescaped pipes with \|| unescaping.

Dive Deeper

Root cause: MarkdownDisplay.tsx lines 114 and 130 used .split("|") to parse table rows, which cannot distinguish between structural column delimiters and literal pipe characters in cell content.

Fix: Added a splitTableRow() helper that:

  1. Splits on unescaped pipes using negative lookbehind: (?<!\\)\|
  2. Unescapes \|| in the resulting cell text
  3. Trims whitespace from each cell

LLMs can output A\|B in table cells and it renders correctly as A|B in a single column. This follows the standard Markdown table escaping convention.

Reviewer Test Plan

  1. Ask the model to output a table where cells contain | (e.g. union types like string|number)
  2. In the system prompt or QWEN.md, instruct the model to escape pipes as \| in tables
  3. Verify the table renders with correct column alignment

Testing Matrix

🍏 🪟 🐧
npm run
npx

Linked issues / bugs

Fixes #2461

Table cells containing literal pipe characters (e.g. `A|B`) were
incorrectly split into separate columns because the parser used a naive
`.split('|')`. This replaces it with a regex split on unescaped pipes

LLMs can now output `A\|B` in table cells and it will render correctly
as `A|B` in a single column.

Fixes QwenLM#2461

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Br1an67
Copy link
Copy Markdown
Contributor Author

Br1an67 commented Mar 20, 2026

Closing in favor of #2503 which has the cleaner implementation with a dedicated splitTableCells() helper.

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