2024-07-01 12:46:10 +02:00
|
|
|
import { SignalLike } from '$fresh/src/types.ts'
|
|
|
|
import { render, RenderOptions } from 'gfm'
|
|
|
|
|
|
|
|
export type MarkdownTheme = 'light' | 'dark' | 'auto'
|
|
|
|
export function Markdown(
|
2024-07-02 13:56:47 +02:00
|
|
|
{ children, theme, options }: {
|
|
|
|
children?: SignalLike<string> | string
|
|
|
|
theme?: SignalLike<MarkdownTheme> | MarkdownTheme
|
|
|
|
options?: RenderOptions
|
|
|
|
},
|
2024-07-01 12:46:10 +02:00
|
|
|
) {
|
2024-07-02 13:56:47 +02:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
class='markdown-body'
|
|
|
|
data-color-mode={typeof theme === 'string'
|
|
|
|
? theme
|
|
|
|
: theme?.value ?? 'auto'}
|
|
|
|
data-light-theme='light'
|
|
|
|
data-dark-theme='dark'
|
|
|
|
dangerouslySetInnerHTML={{
|
|
|
|
__html: render(
|
|
|
|
typeof children === 'string' ? children : children?.value ?? '',
|
|
|
|
options,
|
|
|
|
),
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
</div>
|
|
|
|
)
|
2024-07-01 12:46:10 +02:00
|
|
|
}
|