| 1 | // hastJsx — main-thread HAST→JSX rendering for worker-parsed markdown. Uses |
| 2 | // hast-util-to-jsx-runtime with the exact option set react-markdown passes |
| 3 | // (Fragment/jsx/jsxs from react, ignoreInvalidStyle, passKeys, passNode), so |
| 4 | // blocks parsed off-thread render byte-identically to react-markdown's output. |
| 5 | // Only lazy markdown chunks may import this module: it sits in the heavy |
| 6 | // vendor-markdown graph and must stay out of the app shell. |
| 7 | |
| 8 | import { toJsxRuntime } from "hast-util-to-jsx-runtime"; |
| 9 | import type { Components as JsxComponents } from "hast-util-to-jsx-runtime"; |
| 10 | import { Fragment, jsx, jsxs } from "react/jsx-runtime"; |
| 11 | import type { ReactNode } from "react"; |
| 12 | import type { Components } from "react-markdown"; |
| 13 | import type { MarkdownBlock } from "./markdownPipeline"; |
| 14 | |
| 15 | export function hastBlockToJsx(block: MarkdownBlock, components: Components): ReactNode { |
| 16 | return toJsxRuntime( |
| 17 | { type: "root", children: block.children }, |
| 18 | { |
| 19 | Fragment, |
| 20 | components: components as JsxComponents, |
| 21 | ignoreInvalidStyle: true, |
| 22 | jsx, |
| 23 | jsxs, |
| 24 | passKeys: true, |
| 25 | passNode: true, |
| 26 | }, |
| 27 | ); |
| 28 | } |
| 29 |