Next.js Discord

Discord Forum

In MDX, how do I add syntax highlighting to code blocks?

Unanswered
Gharial posted this in #help-forum
Open in Discord
GharialOP
Im trying to add syntax highlighting but it doesn't seem to be working. I think there may be an extra step that Im missing? I configured the next.config and thats about it:
import type { NextConfig } from "next";
import createMDX from "@next/mdx";
import rehypePrettyCode from "rehype-pretty-code";

const nextConfig: NextConfig = {
  /* config options here */
  pageExtensions: ["js", "jsx", "md", "mdx", "ts", "tsx"],
};

/** @type {import('rehype-pretty-code').Options} */
const options = {
  // See Options section below.
  theme: "one-dark-pro",
};

const withMDX = createMDX({
  extension: /\.mdx?$/,
  options: {
    remarkPlugins: [],
    rehypePlugins: [[rehypePrettyCode, options]],
  },
});

export default withMDX(nextConfig);

0 Replies