feat: MDX rendering support in books island #29
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
The books island receives page content as pre-rendered HTML from hero_books backend via the
content_htmlfield in the JSON-RPC response. This works for standard markdown, but.mdxfiles contain JSX components (<Tabs>,<CodeBlock>, embedded iframes,<div style={{...}}>, etc.) that pulldown-cmark strips or misrenders.Originally tracked as hero_books #44 (closed — moved here since the rendering belongs in the WASM frontend).
Goal
When viewing an
.mdxpage, render JSX components correctly in the browser. Must work at any scale (books may have thousands of .mdx files).Approach
Two-part change:
1. hero_books backend — send raw content for .mdx files
The
bookservice.get_pageRPC response needs a way to signal that content is MDX and provide raw source:content_typefield ("html"or"mdx") to the responsecontent_rawfield with the original .mdx source whencontent_type == "mdx"content_htmlstill present as fallback2. archipelagos books island — client-side MDX rendering
In
views/mod.rsPageContentView:content_typefield in the response"html": use existingdangerous_inner_htmlpath (no change)"mdx": load mdx-js via JS interop to compile and render the MDX in-browserwasm-bindgen/js-systo call the JS MDX compilerComponent mapping
Common MDX components to support:
<Tabs>/<TabItem>— tabbed content panels<CodeBlock>— syntax-highlighted code with copy button<Callout>/<Admonition>— info/warning/error boxes<Details>— collapsible sectionsstyle={{...}}) — convert JSX object syntax to CSS stringPrerequisites
content_type+content_rawto get_page response)Related