-
Notifications
You must be signed in to change notification settings - Fork 0
/
mdx-components.tsx
31 lines (29 loc) · 1.14 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
30
31
// 改成使用自定义的MDXRemote
// import { type MDXComponents } from 'mdx/types'
// import { renderToString } from 'react-dom/server'
// // This file is required to use MDX in `app :root` directory.
// function generateId(children: React.ReactNode) {
// function Title({ children }: { children: React.ReactNode }) {
// return children
// }
// const text = renderToString(<Title>{children}</Title>)
// return text.replace(/<code>|<\/code>/g, '')
// }
// function getCodeLanguage(children: any) {
// const [_, language] = children?.props.className.split('language-')
// return language as string
// }
// export function useMDXComponents(components: MDXComponents): MDXComponents {
// return {
// // Allows customizing built-in components, e.g. to add styling.
// h1: ({ children }) => <h1 id={generateId(children)}>{children}</h1>,
// h3: ({ children }) => <h3 id={generateId(children)}>{children}</h3>,
// pre: ({ children }) => (
// <pre className='relative'>
// <div className='absolute right-5'>{getCodeLanguage(children)}</div>
// {children}
// </pre>
// ),
// ...components,
// }
// }