Skip to content

Commit 6b11812

Browse files
fix: add syntax highlighting to blog posts
Configure rehype-pretty-code plugin for MDXRemote to enable code block syntax highlighting in blog post
1 parent dc99780 commit 6b11812

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/app/blog/[slug]/page.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { MDXRemote } from "next-mdx-remote/rsc";
22
import { notFound } from "next/navigation";
3+
import rehypePrettyCode from "rehype-pretty-code";
34
import { getPostBySlug } from "../utils/blogUtils";
45
import BlogPostContent from "../components/BlogPostContent";
56
import Playground from "../components/Playground"; // Import the Playground component
@@ -38,6 +39,11 @@ export async function generateMetadata({ params }: PostPageProps) {
3839
};
3940
}
4041

42+
const prettyCodeOptions = {
43+
theme: "github-dark",
44+
keepBackground: false,
45+
};
46+
4147
export default function PostPage({ params }: PostPageProps) {
4248
const post = getPostBySlug(params.slug);
4349

@@ -46,7 +52,15 @@ export default function PostPage({ params }: PostPageProps) {
4652
}
4753

4854
const content = (
49-
<MDXRemote source={post.content} components={{ Playground }} />
55+
<MDXRemote
56+
source={post.content}
57+
components={{ Playground }}
58+
options={{
59+
mdxOptions: {
60+
rehypePlugins: [[rehypePrettyCode, prettyCodeOptions]],
61+
},
62+
}}
63+
/>
5064
);
5165

5266
return <BlogPostContent post={post} content={content} />;

0 commit comments

Comments
 (0)