summaryrefslogtreecommitdiffhomepage
path: root/packages/ui/src/components/markdown.tsx
diff options
context:
space:
mode:
authorAdam <[email protected]>2025-10-30 13:49:29 -0500
committerAdam <[email protected]>2025-10-30 13:49:29 -0500
commitdc6e54503cb400ea2533740c9a92d09c8a50d077 (patch)
tree7abad7c0275fe646395a2f4f44d90e5f4a48dbe0 /packages/ui/src/components/markdown.tsx
parent2a0b67d84f048207d20d952cafa10c430451dc70 (diff)
downloadopencode-dc6e54503cb400ea2533740c9a92d09c8a50d077.tar.gz
opencode-dc6e54503cb400ea2533740c9a92d09c8a50d077.zip
wip: desktop work
Diffstat (limited to 'packages/ui/src/components/markdown.tsx')
-rw-r--r--packages/ui/src/components/markdown.tsx36
1 files changed, 36 insertions, 0 deletions
diff --git a/packages/ui/src/components/markdown.tsx b/packages/ui/src/components/markdown.tsx
new file mode 100644
index 000000000..071132e80
--- /dev/null
+++ b/packages/ui/src/components/markdown.tsx
@@ -0,0 +1,36 @@
+import { useMarked } from "../context/marked"
+import { ComponentProps, createResource, splitProps } from "solid-js"
+
+function strip(text: string): string {
+ const wrappedRe = /^\s*<([A-Za-z]\w*)>\s*([\s\S]*?)\s*<\/\1>\s*$/
+ const match = text.match(wrappedRe)
+ return match ? match[2] : text
+}
+
+export function Markdown(
+ props: ComponentProps<"div"> & {
+ text: string
+ class?: string
+ classList?: Record<string, boolean>
+ },
+) {
+ const [local, others] = splitProps(props, ["text", "class", "classList"])
+ const marked = useMarked()
+ const [html] = createResource(
+ () => strip(local.text),
+ async (markdown) => {
+ return marked.parse(markdown)
+ },
+ )
+ return (
+ <div
+ data-component="markdown"
+ classList={{
+ ...(local.classList ?? {}),
+ [local.class ?? ""]: !!local.class,
+ }}
+ innerHTML={html()}
+ {...others}
+ />
+ )
+}