Repository navigation
fix(mdxish): render block markers in single-line JSX table cells as text - #1497
maximilianfalco wants to merge 6 commits into
Conversation
jamestclark
left a comment
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 \-?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
…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
🎯 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)*em*,**strong**, code, links, emoji,<<var>>,{expr}) is unchangedWhy it was broken:
processTableNodere-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 (<b>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
*kept*is still italic\\-workaround now show one backslash, as in MDX📸 Screenshot or Loom
Screen.Recording.2026-05-29.at.20.35.33.mov