opencode/packages/web/src/components/share/content-code.tsx

31 lines
851 B
TypeScript
Raw Normal View History

2025-07-16 05:47:18 +08:00
import { codeToHtml, bundledLanguages } from "shiki"
2025-07-09 06:14:36 +08:00
import { createResource, Suspense } from "solid-js"
import style from "./content-code.module.css"
interface Props {
code: string
lang?: string
flush?: boolean
}
export function ContentCode(props: Props) {
const [html] = createResource(
() => [props.code, props.lang],
async ([code, lang]) => {
// TODO: For testing delays
// await new Promise((resolve) => setTimeout(resolve, 3000))
return (await codeToHtml(code || "", {
2025-07-16 05:47:18 +08:00
lang: lang && lang in bundledLanguages ? lang : "text",
themes: {
light: "github-light",
dark: "github-dark",
},
})) as string
},
)
return (
<Suspense>
<div innerHTML={html()} class={style.root} data-flush={props.flush === true ? true : undefined} />
</Suspense>
)
}