Download packages/web/src/components/share/content-code.tsx from SaylorTwift/opencode: direct link, hf CLI and curl.
- Browser
- Download file 851 Bytes
-
https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/web/src/components/share/content-code.tsx
- Command line
-
hf download hf://SaylorTwift/opencode/packages/web/src/components/share/content-code.tsx
-
curl -L -o content-code.tsx https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/web/src/components/share/content-code.tsx
851 Bytes
| import { codeToHtml, bundledLanguages } from "shiki" | |
| 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 || "", { | |
| 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> | |
| ) | |
| } | |