forked from martimpassos/sebastiao-lacerda-canopy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mdx-components.tsx
29 lines (27 loc) · 1.13 KB
/
mdx-components.tsx
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 Blockquote from "@components/Shared/Markdown/Blockquote";
import Code from "@components/Shared/Code/Code";
import { CodeInline } from "@components/Shared/Code/Code.styled";
import Heading from "@components/Shared/Heading/Heading";
import type { MDXComponents } from "mdx/types";
import { ReactElement } from "react";
import { getSlug } from "@lib/build/slug";
export function useMDXComponents(components: MDXComponents): MDXComponents {
return {
h1: ({ children }) => <Heading as="h1">{children}</Heading>,
h2: ({ children }) => (
<Heading as="h2" id={getSlug(children)}>
{children}
</Heading>
),
h3: ({ children }) => <Heading as="h3">{children}</Heading>,
code: ({ children }) => <CodeInline>{children}</CodeInline>,
blockquote: ({ children }) => <Blockquote>{children}</Blockquote>,
// @ts-ignore
pre: ({ children }: { children: ReactElement }) => {
const string = children.props.children;
const language = children.props.className?.replace("language-", "");
return <Code language={language}>{string.trim()}</Code>;
},
...components,
};
}