Skip to content

fix(mdxish): render block markers in single-line JSX table cells as text - #1497

Open
maximilianfalco wants to merge 6 commits into
nextfrom
falco/rm-16838-lone-rendered-as-bullet-list-in-html-table-and-table-cells
Open

maximilianfalco wants to merge 6 commits into
nextfrom
falco/rm-16838-lone-rendered-as-bullet-list-in-html-table-and-table-cells

Conversation

@maximilianfalco

@maximilianfalco maximilianfalco commented May 29, 2026 •

Copy link
Copy Markdown
Contributor
🎫 Resolve RM-16838

🎯 What does this PR do?

Cells in <table> / <Table> whose text starts on the opener line now render that text literally, matching MDX and legacy:

  • <td>- foo</td>, <td>-</td>, <td>#</td>, <td>---</td>, <td>1.</td>, <td>> quote</td> → literal text (was a list / heading / <hr> / blockquote)
  • \-, \#, \*a\* need a single backslash (was two)
  • Inline markdown (*em*, **strong**, code, links, emoji, <<var>>, {expr}) is unchanged

Why it was broken: processTableNode re-parsed every text-only cell as its own document. The table parse had already read that text inline, so the second pass turned line-start markers into blocks and unescaped \ / entities a second time (&lt;b&gt; became a live tag, \{1+1\} was evaluated).

Fix: Delete the per-cell re-parse and its helpers, we don't need it anymore. It's a bigger overall change but it also solves this issue.

Content on its own lines (<td>\n- foo\n</td>) still parses as blocks, same as MDX. A lone - there stays an empty list item, as in MDX; write \- for a literal dash.

🧪 QA tips

<table>
<thead><tr><th>-</th><th>#</th><th>---</th></tr></thead>
<tbody><tr><td>- fqefeq</td><td>\- hello</td><td>*kept*</td></tr></tbody>
</table>

<Table>
  <thead>
    <tr><th>-</th><th>\#</th><th>1.</th></tr>
  </thead>
  <tbody>
    <tr><td>- fqefeq</td><td>## heading</td><td>> quote</td></tr>
  </tbody>
</Table>
  • every cell renders its text literally; *kept* is still italic
  • docs that used the old \\- workaround now show one backslash, as in MDX

📸 Screenshot or Loom

Screen.Recording.2026-05-29.at.20.35.33.mov

@maximilianfalco
maximilianfalco marked this pull request as draft May 29, 2026 13:45
@maximilianfalco
maximilianfalco marked this pull request as ready for review June 1, 2026 07:27
@maximilianfalco
maximilianfalco requested review from eaglethrost, jamestclark and kevinports and removed request for eaglethrost June 1, 2026 07:27
@maximilianfalco maximilianfalco changed the title fix(mdxish): honor backslash escaped list and hash markers in JSX table cells fix(mdxish): render lone and escaped block markers as text in JSX table cells Jun 1, 2026

@jamestclark jamestclark left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of blockers below. Separately, this is 155 commits behind next and mdxish-tables.ts has moved a fair bit there since the merge base, so it'll want a rebase and a re-run of the new tests before it goes in.


// Restore the `\` so `\- foo` re-parses as text.
const cellSrc = sliceCellSource(tableSource, cell.position, tableBaseOffset);
const textContent = cellSrc && cellSourceHasEscapedMarker(cellSrc) ? `\\${originalText}` : originalText;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the backslash end up in the right place when there's whitespace after the open tag? The regex on :42 starts with ^\s* so it matches <td> \- foo</td>, but here we prepend to the whole of originalText, which still has those spaces, so the inner parser gets \ - foo. A backslash before a space isn't an escape, so it survives into the output. I get <td>\ - foo</td>, and <td> \# heading</td> gives \ # heading. Before this change both rendered a bullet list, so I think we've traded one wrong output for a slightly worse looking one.

Could we just put it after the whitespace?

const textContent = cellSrc && cellSourceHasEscapedMarker(cellSrc)
  ? originalText.replace(/^(\s*)/, '$1\\')
  : originalText;

Would you mind adding a test with a space between <td> and \-?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks! I ended up ripping out the cell re-parse entirely, since the table parse already handles the cell text inline. So there’s no backslash juggling anymore. - foo now renders - foo, and I added a test for it.


// Re-parse text-only cells through markdown and detect flow content
visit(node as Node, isTableCell, (cell: MdxJsxTableCell) => {
if (!isTextOnly(cell.children as unknown[])) return;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this cover the case in the ticket where the cell content sits on its own line? I think isTextOnly bails before either fix gets a look in. For this:

<tr>
<td>
-
</td>
</tr>

the outer parse has already made the cell's children a list, so we return here and the output is still <td><ul><li></li></ul></td>. # gives <td><h1 id=""></h1></td>. Same on <Table> with the <td> on its own lines. That's the RM-16838 symptom, and it's a pretty common way to hand write a table, so I'm not sure we can close the ticket on this one. Would you mind adding a test for that shape either way?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a test for that shape. It still renders an empty list, but that’s what MDX does too so I'm inclined to make it consistent.

@kevinports
kevinports removed their request for review October 21, 2026 14:49
…endered-as-bullet-list-in-html-table-and-table-cells

# Conflicts:
#	__tests__/transformers/mdxish-tables.test.ts
#	package.json
#	processor/transform/mdxish/tables/mdxish-tables.ts
@eaglethrost eaglethrost changed the title fix(mdxish): render lone and escaped block markers as text in JSX table cells fix(mdxish): render block markers in single-line JSX table cells as text Nov 16, 2026

@jamestclark jamestclark left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

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.

3 participants