mirror of
https://github.com/jackyzha0/quartz.git
synced 2026-03-21 21:45:42 -05:00
fix: prevent HTML-escaping of inline style and script content in htmlToJsx
Add dangerouslySetInnerHTML overrides for <style> and <script> elements so that CSS/JS injected by tree transforms is not HTML-escaped during preact-render-to-string serialization.
This commit is contained in:
parent
6c78b5f6c1
commit
cb242ab386
@ -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) => (
|
||||
<div class="table-container">
|
||||
<table {...props} />
|
||||
</div>
|
||||
),
|
||||
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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user