fix: can not render code, close #640

This commit is contained in:
Stephen Zhou
2024-09-27 10:10:28 +08:00
parent 4751447ce2
commit ab8c9e5988
+10 -5
View File
@@ -137,14 +137,19 @@ export const parseHtml = (
if (typeof props.children !== "object") {
codeString = props.children.toString()
} else {
const propsChildren = props.children
const children = Array.isArray(propsChildren)
? propsChildren.find((i) => i.type === "code")
: propsChildren
if (
"type" in props.children &&
props.children.type === "code" &&
props.children.props.className?.includes("language-")
"type" in children &&
children.type === "code" &&
children.props.className?.includes("language-")
) {
language = props.children.props.className.replace("language-", "")
language = children.props.className.replace("language-", "")
}
const code = "props" in props.children && props.children.props.children
const code = "props" in children && children.props.children
if (!code) return null
try {