-
Notifications
You must be signed in to change notification settings - Fork 16
fix(mdxish): fix rendering callout from magic blocks #1275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
fix(mdxish): fix rendering callout from magic blocks #1275
Conversation
kevinports
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Noticed a few small things to be addressed but giving approval so this isn't blocked.
| const md = '[block:callout]{"type":"info","title":"Note","body":"This is important"}[/block]'; | ||
|
|
||
| const ast = mdxish(md); | ||
| console.log(JSON.stringify(ast, null, 2)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| console.log(JSON.stringify(ast, null, 2)); |
| // Check if first child is a flow element that needs unwrapping (mdxJsxFlowElement, etc.) | ||
| const needsUnwrapping = (child: RootContent): boolean => { | ||
| return child.type === 'mdxJsxFlowElement'; | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could move out of the top visitor function so it is only created once.
| } | ||
| } | ||
| } else { | ||
| parent.children.splice(index, 1, ...children); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we are mutating parent.children do we need to return an index of the next node to visit here?
🧰 Changes
Fixes an issue where callout magic blocks (
[block:callout]...[/block]) were not rendering correctly in the mdxish pipeline. The placeholder tokens (__MAGIC_BLOCK_0__) are parsed asinlineCodenodes, which can end up inside paragraphs. When magic blocks create flow elements (likemdxJsxFlowElement), they need to be unwrapped from the paragraph to maintain valid AST structure.Changes
mdxJsxFlowElementnodes directly with name'Callout'instead of intermediaterdme-calloutnodescalloutTransformerbehaviormdxJsxFlowElementnodes from paragraphs inmagicBlockRestorer, since flow elements cannot be children of paragraphs in MDASTBefore
Screen.Recording.2025-12-17.at.22.12.27.mov
After
Screen.Recording.2025-12-17.at.23.32.40.mov
🧬 QA & Testing