Repository navigation
fix(mdxish): strip body indent from html in component bodies - #1694
eaglethrost wants to merge 3 commits into
Conversation
…rm-19815-mdxisheditor-html-inside-a-callout-shows-its
[Medium impact] The change reaches MDXish component-body parsing in both editor and renderer workflows. The PR appears safe to merge, with a non-blocking whitespace regression in unevenly indented Findings
Reviews (1) · Last reviewed commit: "Merge branch 'next' of https://github.co..." · Reviewed by Greptile |
| const sharesIndent = lines.every(line => !line.trim() || indentWidth(line) >= indent); | ||
| const [first, ...rest] = lines; | ||
| const strippedLines = sharesIndent ? dedentLines(lines, indent) : [...dedentLines([first], indent), ...rest]; | ||
| node.value = strippedLines.join('\n'); |
There was a problem hiding this comment.
HTMLBlock content gains spaces. When an indented
HTMLBlock payload has a shallower line, this removes only the opening line's indent. splitRawHtmlBlocks then computes openingTagIndent as zero, so formatHtmlForMdxish stops removing the wrapper's indent from the payload.
For example:
<Callout>
<HTMLBlock>{`
<pre>
bar
</pre>
`}</HTMLBlock>
</Callout>The bar line now renders with two leading spaces instead of none. Preserve HTMLBlock's existing deindent behavior when normalizing these raw nodes.
🎯 What does this PR do?
HTML inside a Callout body kept the body's 2-space indent in its
value, so after a raw mode edit the editor showed it with leading spaces in rich mode. The first-line case regressed in #1583, when.trim()on the body becametrimBlankEdges.mdx-blocks.ts: bodies under 4 columns skipsafeDeindent, & CommonMark html blocks keep their indent. After the body is parsed I now strip that indent from each top-level html node & start it at the<, same shape as html in a list item. Later lines are only stripped when none sits shallower, so<pre>content stays as written.<style>/ multi-line<div>in a Callout no longer gain 2 spaces on every save, & components no longer get the leaked indent as a whitespace child (updated the mixed-content test inCustomComponents.test.tsxto use real whitespace).I didn't lower
safeDeindent's 4-column gate, it breaks a bunch of position tests.🧪 QA tips
📸 Screenshot or Loom
Before:
Screen.Recording.2026-11-19.at.3.52.13.pm.mov
After:
Screen.Recording.2026-11-19.at.4.20.00.pm.mov