-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmdx-components.tsx
More file actions
29 lines (28 loc) · 788 Bytes
/
mdx-components.tsx
File metadata and controls
29 lines (28 loc) · 788 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import type { MDXComponents } from 'mdx/types'
import { ComponentPropsWithoutRef } from 'react'
import { highlight } from 'sugar-high'
export function useMDXComponents(components: MDXComponents): MDXComponents {
return {
...components,
Cover: ({
src,
alt,
caption,
}: {
src: string
alt: string
caption: string
}) => {
return (
<figure>
<img src={src} alt={alt} className="rounded-xl" />
<figcaption className="text-center">{caption}</figcaption>
</figure>
)
},
code: ({ children, ...props }: ComponentPropsWithoutRef<'code'>) => {
const codeHTML = highlight(children as string)
return <code dangerouslySetInnerHTML={{ __html: codeHTML }} {...props} />
},
}
}