【发布时间】:2022-06-18 11:02:30
【问题描述】:
我正在尝试在基于 Nextjs 的页面中使用 next-mdx-remote 突出显示我的代码语法。我从graphcms 获取我的降价格式并将其呈现如下:
import { serialize } from "next-mdx-remote/serialize"
import { MDXRemote } from "next-mdx-remote"
import rehypeHighlight from "rehype-highlight"
export async function getStaticProps({ params }: any) {
const data = await getPostDetail(params?.slug)
const source = data?.content?.markdown
const mdxSource = await serialize(source, {
mdxOptions: { rehypePlugins: [rehypeHighlight] },
})
return {
props: {
posts: data,
mdxSource: mdxSource,
},
}
}
function Post({mdxSource}){
return(
<MDXRemote {...mdxSource} />
)
}
不幸的是,代码块被渲染成普通的文本字段并且没有做任何事情。
我不确定我在这里遗漏了什么,官方documentation 也没有澄清这一点
【问题讨论】: