| 8 | } |
| 9 | |
| 10 | export function Markdown( |
| 11 | props: ComponentProps<"div"> & { |
| 12 | text: string |
| 13 | class?: string |
| 14 | classList?: Record<string, boolean> |
| 15 | }, |
| 16 | ) { |
| 17 | const [local, others] = splitProps(props, ["text", "class", "classList"]) |
| 18 | const marked = useMarked() |
| 19 | const [html] = createResource( |
| 20 | () => strip(local.text), |
| 21 | async (markdown) => { |
| 22 | return marked.parse(markdown) |
| 23 | }, |
| 24 | ) |
| 25 | return ( |
| 26 | <div |
| 27 | data-component="markdown" |
| 28 | classList={{ |
| 29 | ...(local.classList ?? {}), |
| 30 | [local.class ?? ""]: !!local.class, |
| 31 | }} |
| 32 | innerHTML={html()} |
| 33 | {...others} |
| 34 | /> |
| 35 | ) |
| 36 | } |