generated from canopy-iiif/canopy-iiif
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mdx-components.tsx
29 lines (27 loc) · 1.12 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 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 "@/services/build/slug";
import Blockquote from "./components/Shared/Markdown/Blockquote";
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,
};
}