Skip to content

fix: fix callout magic blocks when rendered directly below a list item#1331

Merged
maximilianfalco merged 3 commits intonextfrom
falco/rm-15192-magic-block-callout-under-a-list-breaks-rendering
Feb 12, 2026
Merged

fix: fix callout magic blocks when rendered directly below a list item#1331
maximilianfalco merged 3 commits intonextfrom
falco/rm-15192-magic-block-callout-under-a-list-breaks-rendering

Conversation

@maximilianfalco
Copy link
Copy Markdown
Contributor

@maximilianfalco maximilianfalco commented Feb 10, 2026

PR App Fix RM-15192

🧰 Changes

When a [block:callout] follows a list item without a blank line, markdown parses it as continuation content of that list item. The callout ends up inside a <p> inside the <li>.

We already had paragraph-lifting logic in magicBlockTransformer to handle this. it lifts them out of the paragraph and splices them into the paragraph's parent.

The problem was that the second pass found the paragraph's parent by searching tree.children which is only the root's direct children. When the <p> was nested inside an <li>, it wasn't a direct child of the root, so the search returned -1 and the code fell back to stuffing everything back into the paragraph. The callout stayed trapped in a <p> tag, which is what caused the rendering bug.

The fix switches from visit to visitParents to capture the full ancestor chain during traversal. This gives us the paragraph's actual container directly (e.g., the <li>) without needing to search the tree afterward. The second pass now splices into the correct container at any depth, not just the root.

Before After
Screenshot 2026-02-11 at 01 40 50 Screenshot 2026-02-11 at 01 40 22

🧬 QA & Testing

if (!children.length) {
// Remove the node if transformation returns nothing
parent.children.splice(index, 1);
return [SKIP, index];
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.

Why do we not return anymore here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the old code used visit which supports [SKIP, index] returns to avoid re-visiting the current index after a splice. visitParents doesn't support that [Action, Index] tuple and instead only Action or void so the bare return is the correct API usage here.

it should be safe because visitParents walks by tree structure rather than by index, so splicing out the node won't cause the next node to be skipped or revisited.

good call though! ill put a comment explaining this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added some comments in 09cf0e0

@eaglethrost
Copy link
Copy Markdown
Contributor

eaglethrost commented Feb 11, 2026

Looks good! Did quite a lot testing with the magic blocks and seems to be no regression.

@maximilianfalco maximilianfalco marked this pull request as ready for review February 11, 2026 12:57
Copy link
Copy Markdown
Contributor

@rafegoldberg rafegoldberg left a comment

Choose a reason for hiding this comment

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

Isn't this the same issue as #1336? Why do they require two entirely different solutions? If so, it feels real redundant to fix the same underlying issue twice in two different ways but…feel free to merge this if it works.

@eaglethrost
Copy link
Copy Markdown
Contributor

Isn't this the same issue as #1336? Why do they require two entirely different solutions? If so, it feels real redundant to fix the same underlying issue twice in two different ways but…feel free to merge this if it works.

It looks similar indeed, but this a more specific issue regarding callout magic blocks under a list item specifically. Merging in that other PR still won’t fix this issue.

@maximilianfalco maximilianfalco merged commit de2b82a into next Feb 12, 2026
11 checks passed
@maximilianfalco maximilianfalco deleted the falco/rm-15192-magic-block-callout-under-a-list-breaks-rendering branch February 12, 2026 23:52
rafegoldberg pushed a commit that referenced this pull request Feb 13, 2026
## Version 13.1.2
### 🛠 Fixes & Updates

* **magic blocks:** ensure newline characters processed as hard breaks ([#1329](#1329)) ([bb37d62](bb37d62))
* fix callout magic blocks when rendered directly below a list item ([#1331](#1331)) ([de2b82a](de2b82a))
* fix rendering content in table magic blocks ([#1318](#1318)) ([0ea1cfc](0ea1cfc))
* preserve recipe top level attributes in mdast ([#1324](#1324)) ([98f466b](98f466b))
* **stripComments:** properly pass in the micromark extensions ([#1335](#1335)) ([7ec9d46](7ec9d46))
* **mdxish:** properly terminate html blocks ([#1336](#1336)) ([d221861](d221861))

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

This PR was released!

🚀 Changes included in v13.1.2

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.

4 participants