Skip to content

Commit

Permalink
feat: add style support for markdown component
Browse files Browse the repository at this point in the history
  • Loading branch information
y-nk committed Dec 18, 2023
1 parent d3443c3 commit 3132c31
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions astro-components/src/components/Markdown.astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,33 @@ import { parseMarkdown, ParserOptions } from '../utils/markdown'
export type Props = {
['class']?: string
['class:list']?: AstroBuiltinAttributes
['class:list']?: AstroBuiltinAttributes['class:list']
style?: any
as?: string
content: string
options?: ParserOptions
}
const {
['class']: className,
['class:list']: classList,
['class']: className = '',
['class:list']: classList = {},
style = {},
as: Tag,
content,
options,
} = Astro.props
const html = await parseMarkdown(content, options)
if (import.meta.env.DEV && !Tag && (className || classList || style)) {
console.warn('[astro-components] using Markdown component without `as` will ignore `className`, `classList` nor `style` attributes.')
}
---

{
Tag
? <Tag class:list={[className, classList]} set:html={html} />
? <Tag class:list={[className, classList]} style={style} set:html={html} />
: <Fragment set:html={html} />
}

0 comments on commit 3132c31

Please sign in to comment.