diff --git a/quartz/util/jsx.tsx b/quartz/util/jsx.tsx index b52542348..d403f18db 100644 --- a/quartz/util/jsx.tsx +++ b/quartz/util/jsx.tsx @@ -1,15 +1,26 @@ import { Components, Jsx, toJsxRuntime } from "hast-util-to-jsx-runtime" import { Node, Root } from "hast" import { Fragment, jsx, jsxs } from "preact/jsx-runtime" +import { h } from "preact" import { trace } from "./trace" import { type FilePath } from "./path" +function childrenToString(children: unknown): string { + if (typeof children === "string") return children + if (Array.isArray(children)) return children.map(childrenToString).join("") + return String(children ?? "") +} + const customComponents: Components = { table: (props) => (
), + style: ({ children, ...rest }) => + h("style", { ...rest, dangerouslySetInnerHTML: { __html: childrenToString(children) } }), + script: ({ children, ...rest }) => + h("script", { ...rest, dangerouslySetInnerHTML: { __html: childrenToString(children) } }), } export function htmlToJsx(fp: FilePath, tree: Node) {