mirror of
https://github.com/anomalyco/opencode.git
synced 2026-04-29 04:59:51 +00:00
wip: desktop work
This commit is contained in:
parent
2a0b67d84f
commit
dc6e54503c
20 changed files with 581 additions and 373 deletions
36
packages/ui/src/components/markdown.tsx
Normal file
36
packages/ui/src/components/markdown.tsx
Normal file
|
|
@ -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}
|
||||
/>
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue