Skip to content

fix(mdxish): tone down empty line addition preprocessing after html blocks#1344

Merged
eaglethrost merged 9 commits intonextfrom
dimas/RM-15306-html-treated-as-code-blocks-fix
Feb 18, 2026
Merged

fix(mdxish): tone down empty line addition preprocessing after html blocks#1344
eaglethrost merged 9 commits intonextfrom
dimas/RM-15306-html-treated-as-code-blocks-fix

Conversation

@eaglethrost
Copy link
Contributor

PR App Fix RM-15306

🧰 Changes

Tightens up the preprocessing logic in mdxish to add blank lines after HTML construct lines introduced in #1336 to no longer do so if the next line is an HTML construct or not indented.

The previous logic was causing a regression where the new blank line caused an HTML line after an opening HTML tag, that was 4 tabs indented, to get rendered as a code block instead of an html element. In common mark, lines with at least 4 indents are treated as code blocks (see here), but if it's right under a line with an HTML construct (opened or closed), it won't get treated as a code block. Hence the additional blank line caused the customer HTML to break.

The adjusted conditions here removes adding blank lines where we don't want it to be added, and also where it's not really needed (if the next line is indented as it already doesn't get consumed by the previous line HTML flow)

🧬 QA & Testing

  1. In the markdown playground, test these markdown with mdxish flag on:
<div>
        <a class="glossary-letter" href="#a">A</a> |
        <a class="glossary-letter" href="#b">B</a> |
</div>

<div>
[block:callout]
{
  "type": "success",
  "body": "Hello"
}
[/block]
</div>
  1. The indented HTML tags wrapped in an HTML tree shouldn't get converted to code block, and any content right after a line with HTML construct should get rendered & not consumed (retain that behaviour)
  2. Test with more examples & compare it with legacy, basically there shouldn't be any difference
Screenshot 2026-02-16 at 2 53 25 pm

[/block]
</div>
`);
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
})
});

\`\`\``);
});
});
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
})
});


it('does not catastrophically backtrack on malformed tags with spaces', () => {
const input = `<a${' '.repeat(1000)}`;
it('does not add a blank line after an opening that that already has a blank line after it', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
it('does not add a blank line after an opening that that already has a blank line after it', () => {
it('does not add a blank line after an opening tag that already has a blank line after it', () => {

(STANDALONE_HTML_LINE_REGEX.test(lines[i]) || HTML_LINE_WITH_CONTENT_REGEX.test(lines[i])) &&
lines[i + 1].trim().length > 0
) {
if (i >= lines.length - 1 || lines[i + 1].trim().length === 0 || lines[i + 1].startsWith(' ')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (i >= lines.length - 1 || lines[i + 1].trim().length === 0 || lines[i + 1].startsWith(' ')) {
if (i >= lines.length - 1 || lines[i + 1].trim().length === 0 || lines[i + 1].startsWith(' ') || lines[i + 1].startsWith('\t')) {

can you add this as well, it looks like we are only considering when spaces start the next line but would be great to cover for \t cases as well

you can use this test case, the top one uses \t and the bottom uses spaces

<div>
	<a class="glossary-letter" href="#a">A</a> |
	<a class="glossary-letter" href="#b">B</a> |
</div>

---

<div>
        <a class="glossary-letter" href="#a">A</a> |
        <a class="glossary-letter" href="#b">B</a> |
</div>

currently is broken on \t
Image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Really good catch thanks!

Copy link
Contributor

@maximilianfalco maximilianfalco left a comment

Choose a reason for hiding this comment

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

lgtm!

Copy link
Contributor

@maximilianfalco maximilianfalco left a comment

Choose a reason for hiding this comment

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

derefering to kevin and rafe for final approval!

continue;
}

const isCurrentLineHtml = STANDALONE_HTML_LINE_REGEX.test(lines[i]) || HTML_LINE_WITH_CONTENT_REGEX.test(lines[i]);
Copy link
Contributor

Choose a reason for hiding this comment

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

small nit (not blocking): these could be DRY'ed up a bit with a small util isLineHtml that accepts the line and runs both the conditionals

(STANDALONE_HTML_LINE_REGEX.test(lines[i]) || HTML_LINE_WITH_CONTENT_REGEX.test(lines[i])) &&
lines[i + 1].trim().length > 0
) {
if (i >= lines.length - 1 || lines[i + 1].trim().length === 0 || lines[i + 1].startsWith(' ') || lines[i + 1].startsWith('\t')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: i find a comment helpful when there are lots of conditionals to resolve in an if statement!

@eaglethrost eaglethrost merged commit e4e7362 into next Feb 18, 2026
11 checks passed
@eaglethrost eaglethrost deleted the dimas/RM-15306-html-treated-as-code-blocks-fix branch February 18, 2026 13:16
rafegoldberg pushed a commit that referenced this pull request Feb 18, 2026
## Version 13.2.0
### ✨ New & Improved

* **demo:** add a markdown view in demo app when stripComments is on ([#1348](#1348)) ([a7a8726](a7a8726))
* extend regex to cover more cases ([#1338](#1338)) ([3e8efc8](3e8efc8))

### 🛠 Fixes & Updates

* **mdxish:** add missing toMarkdown extension for MDX expressions in stripComments ([#1347](#1347)) ([02ddfce](02ddfce))
* properly escape escaped chars when expression parsing fails ([#1325](#1325)) ([136f7af](136f7af))
* **mdxish:** tone down empty line addition preprocessing after html blocks ([#1344](#1344)) ([e4e7362](e4e7362)), closes [#1336](#1336)

<!--SKIP CI-->
@rafegoldberg
Copy link
Contributor

This PR was released!

🚀 Changes included in v13.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants