fix: fix rendering content in table magic blocks#1318
Conversation
- also created the appropriate transformer - deleted the old `mdxish-magic-blocks` transformer
- this was necessary since the old logic introduced whitespaces that are no longer here
…o/mdxish-magic-blocks-in-lists
…o/mdxish-magic-blocks-in-lists
- fixed issue where callouts without title werent rendering properly - fixed issue where callouts without body werent rendering properly - fixed issue where caption of images would be rendered as plain text instead of being parsed
- added tests as well
…o/mdxish-magic-blocks-in-lists
- malformed syntax is returned as raw text instead of erroring
|
@rafegoldberg I did a bit of refactor on this, its a bit more convoluted and complex but it should be more robust in general. it might degrade performance a tiny bit 🤞 but it shouldnt really matter since we rarely see these complex magic block tables anyways... ive placed all the refactor here 249d6bd. these are the steps now
its a bit confusing yea... took my head a bit too to get around it but it looks to be the most robust way... we still needed to re-stringify it so that we maintain the original I asked claude to help visualize a test case and it did it pretty well here: Detailed Flow |
…o/fix-rendering-content-in-table-magic-blocks
|
Code looks good to me. Yeah it's not ideal we have to create another mini md processor just for magic blocks, but I think works for now. We didn't design the table magic block to convert to the MDX because technically they're a different and might have different stylings and behaviour. But in the future I do think it's worth doing so to reduce code duplications like this and clean it up further |
rafegoldberg
left a comment
There was a problem hiding this comment.
Appreciate the details @maximilianfalco. I'm (very) cautiously approving this, though I'd love to address the following comments ASAP.
processor/transform/mdxish/magic-blocks/magic-block-transformer.ts
Outdated
Show resolved
Hide resolved
| /** Markdown parser */ | ||
| const contentParser = unified().use(remarkParse).use(remarkGfm).use(normalizeEmphasisAST); | ||
|
|
||
| /** Markdown to HTML processor (mdast → hast → HTML string) */ | ||
| const markdownToHtml = unified().use(remarkParse).use(remarkGfm).use(remarkRehype).use(rehypeStringify); | ||
|
|
||
| /** HTML parser (HTML string → hast) */ | ||
| const htmlParser = unified().use(rehypeParse, { fragment: true }); | ||
|
|
||
| /** HTML stringifier (hast → HTML string) */ | ||
| const htmlStringifier = unified().use(rehypeStringify); |
There was a problem hiding this comment.
I have two concerns about this pattern of instantiating multiple subprocessors:
-
Firstly, performance especially on large tables with lots of cells and complex content. Can we add a test for such a scenario, or at least manually run a benchmark to see how well this approach is working?
-
And secondly, it doesn't seem like these subprocessors will support any of our custom syntax (like variables or glossary terms) within cells. Is that an accurate assumption?
There was a problem hiding this comment.
performance seems to be stable and alright, I added a perf test in da09016 and they seem to be working just fine. the perf deg isnt significant
There was a problem hiding this comment.
Confirmed variables & glossary are rendered in magic blocks including tables
Screen.Recording.2026-02-12.at.2.35.12.pm.mov
There was a problem hiding this comment.
ive added support for the new glossary syntax here as well 7ad3fea
processor/transform/mdxish/magic-blocks/magic-block-transformer.ts
Outdated
Show resolved
Hide resolved
processor/transform/mdxish/magic-blocks/magic-block-transformer.ts
Outdated
Show resolved
Hide resolved
| let counter = 0; | ||
| const safened = escapeInvalidTags(html).replace(HTML_TAG_RE, match => { | ||
| if (!/^<\/?[A-Z]/.test(match)) return match; | ||
| const id = `<!--PC${(counter += 1)}-->`; |
There was a problem hiding this comment.
need to do some replace and restore here because rehype-parse would mangle away the <Glossary> tags
…o/fix-rendering-content-in-table-magic-blocks
processor/transform/mdxish/magic-blocks/magic-block-transformer.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Appreciate the followup @maximilianfalco. Let's clean up that regex per our thread and get these conflicts resolved. But otherwise this seems to be rendering as expected. 👌
…ontent-in-table-magic-blocks # Conflicts: # __tests__/lib/mdxish/magic-blocks.test.ts # processor/transform/mdxish/magic-blocks/magic-block-transformer.ts
## 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
Add preprocessing in
parseTableCellofmagic-block-transformerto:\< → <) and col characters (|)🧬 QA & Testing