fix(mdx): collapse blank lines between JSX table elements on serialize#1444
Open
jesseyowell wants to merge 1 commit into
Open
fix(mdx): collapse blank lines between JSX table elements on serialize#1444jesseyowell wants to merge 1 commit into
jesseyowell wants to merge 1 commit into
Conversation
mdast-util-mdx-jsx's containerFlow function inserts \n\n between all children of flow JSX elements. For tables converted to JSX (via tables-to-jsx), this introduces blank lines between sibling elements like </th> and <th>, </thead> and <tbody>, etc. The MDX renderer treats these blank lines as new AST nodes, breaking table structure. Post-process the serialized MDX string to collapse \n\n → \n specifically between closing/opening table element tags. Blank lines inside cell content (intentional paragraph breaks) are preserved. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When the MDX serializer outputs a JSX table (i.e. a table with flow content like lists, code blocks, or paragraph breaks in cells), blank lines are introduced between every pair of sibling table elements:
This happens between
</th>↔<th>,</td>↔<td>,</thead>↔<tbody>, and</tr>↔<tr>. The MDX renderer treats these blank lines as new AST nodes, which breaks table structure on re-parse.Root cause
mdast-util-mdx-jsx'scontainerFlowfunction unconditionally inserts\n\nbetween all children of flow JSX elements. This is correct for most block elements, but for table sub-elements (<thead>,<tbody>,<tr>,<th>,<td>) it produces whitespace that breaks the table when the MDX is later parsed.Fix
Post-process the serialized MDX string in
lib/mdx.tsto collapse\n\n→\nspecifically between closing and opening table element tags:The regex only matches tag boundaries, so blank lines inside cell content (intentional paragraph breaks) are preserved.
Before
After
Tests
All 1993 tests pass. 11 inline snapshots updated across 4 test files to reflect the removed blank lines:
__tests__/compilers/tables.test.js— 6 snapshots (core table serialization)__tests__/migration/tables.test.ts— 3 snapshots (RDMD → MDX migration)__tests__/compilers/compatability.test.tsx— 1 snapshot__tests__/migration/link-reference.test.ts— 1 snapshot🤖 Generated with Claude Code