Skip to content

fix(frontend): preserve code during Markdown table normalization - #3981

Draft
cangen185-sudo wants to merge 1 commit into
Tencent:mainfrom
cangen185-sudo:codex/fix-markdown-table-code-preservation
Draft

cangen185-sudo wants to merge 1 commit into
Tencent:mainfrom
cangen185-sudo:codex/fix-markdown-table-code-preservation

Conversation

@cangen185-sudo

Copy link
Copy Markdown

Description

The document chunk preview runs normalizeSpuriousTablePrefixes() before marked.parse(). It currently repairs pipe-delimited rows even inside literal Markdown code blocks. A fenced table example gains an extra separator row; examples of MarkItDown's empty-prefix output lose their first two rows. Four-space/tab-indented code can also be changed.

Limit table repair to non-code rows and track backtick/tilde fences, including the same-character/minimum-length closing rule, indentation, unterminated fences and backticks in info strings. No dependencies or public APIs change. Ordinary MarkItDown tables keep their existing repair behavior.

Type of Change

  • Bug fix
  • Test

Related Issue

New locally reproduced defect. This does not address #3962; that single-tilde rendering issue already has #3963.

Testing

Baseline: bccb4b151bae403508da77fbb174efc79dc47c1a (main). Windows, Node.js 24.16.0.

  • The same 10 added regressions on unchanged source: 8 failed, 2 passed.
  • With the fix: 10 passed.
  • npm test -- src/utils/markdownTableNormalize.test.ts src/utils/documentPreviewMarkdown.test.ts src/utils/chatMarkdownRenderer.test.ts: 59 passed.
  • npm ci --ignore-scripts --no-audit --no-fund: passed; package-lock unchanged.
  • npm run type-check: passed.
  • git diff --check: passed.

No live backend/model or full-repository suite was run. The tests cover this preprocessing function and adjacent Markdown renderers. This is a targeted fence guard, not a full Markdown parser or an overhaul of table recognition.

Checklist

  • Diff has no whitespace errors
  • Changed source follows the existing formatting
  • Targeted tests pass
  • Full-repository checks not run; scope documented above
  • Added regression tests
  • Updated the function's documentation
  • No breaking public API change
  • Contributor's human review

Screenshots / Recordings

The defect can be reproduced without a server using this input:

```markdown
| A | B |
| x | y |
```

Before: the rendered code gains | --- | --- | between its two rows. After: both literal rows are unchanged. The dedicated tests assert exact source preservation. No CSS/layout changes are made.

AI assistance

Codex assisted with source audit, reproduction, implementation and local tests. This PR is submitted as a draft for contributor review; no human review or maintainer acceptance is claimed.

This branch has not been deployed

No deployments
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.

1 participant