From f3da73553c45f17e04b1e77cb13eb0fca714d1bd Mon Sep 17 00:00:00 2001
From: Dax Raad <d@ironbay.co>
Date: Fri, 30 May 2025 20:47:56 -0400
Subject: sync

---
 packages/web/src/components/CodeBlock.tsx | 47 +++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
 create mode 100644 packages/web/src/components/CodeBlock.tsx

(limited to 'packages/web/src/components/CodeBlock.tsx')

diff --git a/packages/web/src/components/CodeBlock.tsx b/packages/web/src/components/CodeBlock.tsx
new file mode 100644
index 000000000..17559ece1
--- /dev/null
+++ b/packages/web/src/components/CodeBlock.tsx
@@ -0,0 +1,47 @@
+import {
+  type JSX,
+  onCleanup,
+  splitProps,
+  createEffect,
+  createResource,
+} from "solid-js"
+import { codeToHtml } from "shiki"
+import { transformerNotationDiff } from '@shikijs/transformers'
+
+interface CodeBlockProps extends JSX.HTMLAttributes<HTMLDivElement> {
+  code: string
+  lang?: string
+}
+function CodeBlock(props: CodeBlockProps) {
+  const [local, rest] = splitProps(props, ["code", "lang"])
+  let containerRef!: HTMLDivElement
+
+  const [html] = createResource(async () => {
+    return (await codeToHtml(local.code, {
+      lang: local.lang || "text",
+      themes: {
+        light: 'github-light',
+        dark: 'github-dark',
+      },
+      transformers: [
+        transformerNotationDiff(),
+      ],
+    })) as string
+  })
+
+  onCleanup(() => {
+    if (containerRef) containerRef.innerHTML = ""
+  })
+
+  createEffect(() => {
+    if (html() && containerRef) {
+      containerRef.innerHTML = html() as string
+    }
+  })
+
+  return (
+    <div ref={containerRef} {...rest}></div>
+  )
+}
+
+export default CodeBlock
-- 
cgit v1.2.3

