-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.config.mjs
40 lines (35 loc) · 1.03 KB
/
next.config.mjs
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
32
33
34
35
36
37
38
39
40
import createMDX from '@next/mdx'
import rehypeHighlight from 'rehype-highlight'
import { visit } from 'unist-util-visit'
/** @type {import('next').NextConfig} */
const nextConfig = {
pageExtensions: ['js', 'jsx', 'mdx', 'ts', 'tsx'],
}
const withMDX = createMDX({
options: {
rehypePlugins: [
() => (tree) => {
visit(tree, (node) => {
if (node?.type === 'element' && node?.tagName === 'pre') {
const [codeElement] = node.children
if (codeElement.tagName !== 'code') return
node.__rawString__ = codeElement.children[0]?.value
}
})
},
rehypeHighlight,
() => (tree) => {
visit(tree, (node) => {
if (node?.type === 'element' && node?.tagName === 'pre') {
const preElement = node.children.at(-1)
preElement.properties = {
...preElement.properties,
__rawString__: node.__rawString__,
}
}
})
},
],
},
})
export default withMDX(nextConfig)