fix(markdown): preserve table cells during MDX fallback#5007
fix(markdown): preserve table cells during MDX fallback#5007kiranmagic7 wants to merge 1 commit into
Conversation
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
🦋 Changeset detectedLatest commit: bb2dbcf The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
cb9ae4c to
bb2dbcf
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bb2dbcfbe3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (fallbackTable) { | ||
| return [...completeNodes.slice(0, -1), fallbackTable]; |
There was a problem hiding this comment.
Preserve blocks after the fallback table
When the < that triggers MDX fallback is inside a table cell but the markdown continues after that table, withoutMdxNodes contains the repaired table plus the following blocks, while this return keeps only fallbackTable. For input shaped like a GFM table row containing a<b followed by \n\nAfter, the trailing paragraph is silently dropped; splice the fallback table together with the subsequent fallback nodes instead of returning only the table.
Useful? React with 👍 / 👎.
| lastChild.text += inlineNodes | ||
| .map((inlineNode) => inlineNode.text) | ||
| .join(''); |
There was a problem hiding this comment.
Avoid merging fallback text into marked leaves
When the complete prefix ends in a formatted text leaf, e.g. **bold**<u>, this branch appends the literal fallback text into that same leaf and preserves its marks, so <u> becomes bold text. The previous behavior appended the fallback inline nodes separately, which kept the incomplete MDX literal from inheriting formatting that only applied to the preceding markdown span.
Useful? React with 👍 / 👎.
| const fallbackTable = withoutMdxNodes | ||
| .filter((node) => ElementApi.isElement(node) && node.type === tableType) | ||
| .at(-1); |
There was a problem hiding this comment.
Match the fallback table to the split point
If the cell containing the plain less-than text is followed later by another GFM table, this picks the last table from the full non-MDX parse rather than the table that was partial in completeNodes. In that case the broken table is replaced with the later table and the original repaired table is lost; the fallback needs to identify the table corresponding to the split position, not just .at(-1) across the whole document.
Useful? React with 👍 / 👎.
Summary
Fixes #5006.
When MDX parsing fails on plain less-than text inside a GFM table cell, the safe Markdown fallback now keeps the table structure valid instead of appending fallback inline text directly under the table node. If the incomplete MDX tail belongs to a table, the fallback replaces the partial table with the non-MDX parsed table while preserving completed blocks before it.
Testing
./node_modules/.bin/bun test packages/markdown/src/lib/table.spec.ts packages/markdown/src/lib/deserializer/utils/markdownToSlateNodesSafely.spec.tsx-> 7 passedPATH="$PWD/node_modules/.bin:$PATH" pnpm --filter @platejs/markdown lint-> passedpnpm turbo build --filter=./packages/markdown-> 11 tasks passed./node_modules/.bin/biome check packages/markdown/src/lib/deserializer/utils/markdownToSlateNodesSafely.ts packages/markdown/src/lib/table.spec.ts .changeset/green-plants-fix.md-> passedgit diff --check-> passedNotes
./node_modules/.bin/bun test packages/markdown/src/libreached 210 passing tests, then stopped on an existing local module-resolution issue for@platejs/list-classic/reactinstandardList.spec.tsx.pnpm turbo typecheck --filter=./packages/markdownalso fails in this checkout on existing unresolved local workspace/test imports such as@platejs/basic-nodes,@platejs/test-utils, and@platejs/table, not on this change.codex review --base origin/mainwas not run becausecodexis not installed in this environment.AI-assisted: yes. I understand the change and verified the focused regression locally.