Skip to content

fix(mdxish): strip body indent from html in component bodies - #1694

Draft
eaglethrost wants to merge 3 commits into
nextfrom
falco/rm-19815-mdxisheditor-html-inside-a-callout-shows-its
Draft

eaglethrost wants to merge 3 commits into
nextfrom
falco/rm-19815-mdxisheditor-html-inside-a-callout-shows-its

Conversation

@eaglethrost

@eaglethrost eaglethrost commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor
🎫 Resolve RM-19815

🎯 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 became trimBlankEdges.

  • mdx-blocks.ts: bodies under 4 columns skip safeDeindent, & 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.
  • Side effects: <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 in CustomComponents.test.tsx to use real whitespace).

I didn't lower safeDeindent's 4-column gate, it breaks a bunch of position tests.

🧪 QA tips

  • In the MdxishEditor, switch to raw mode, paste the markdown below, switch back to rich mode & check neither html line shows leading spaces
  • Save & reload, the indent stays at 2 spaces
<Callout icon="📘" theme="info">
  <!-- note --> Some text
</Callout>

<Callout icon="📘" theme="info">
  Hello

  <div>x</div>
</Callout>

📸 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

@greptile-apps

greptile-apps Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[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 HTMLBlock payloads.

Findings

  1. P2 HTMLBlock content gains spaces ▶

Reviews (1) · Last reviewed commit: "Merge branch 'next' of https://github.co..." · Reviewed by Greptile

Comment on lines +113 to +116
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');

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.

P2 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.

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.

1 participant