fix: fix callout magic blocks when rendered directly below a list item#1331
Conversation
| if (!children.length) { | ||
| // Remove the node if transformation returns nothing | ||
| parent.children.splice(index, 1); | ||
| return [SKIP, index]; |
There was a problem hiding this comment.
Why do we not return anymore here?
There was a problem hiding this comment.
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
processor/transform/mdxish/magic-blocks/magic-block-transformer.ts
Outdated
Show resolved
Hide resolved
|
Looks good! Did quite a lot testing with the magic blocks and seems to be no regression. |
There was a problem hiding this comment.
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. |
## 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-->
This PR was released!🚀 Changes included in v13.1.2 |

🧰 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
magicBlockTransformerto 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.childrenwhich 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-1and 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
visittovisitParentsto 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.🧬 QA & Testing