10

I want to highlight a part of a code block that is written in markdown using triple backticks (```). Here is an image of what I want. code block with highlighting-imgur

I want to replicate how we highlight a sentence in a book with a highlighter/marker . I have used the <pre></pre> and <mark></mark> but these tags dont work inside code block as seen below;

```
<pre>
<b>some bold text</b>
<pre/>
```
Alekh Kumar
  • 101
  • 1
  • 3

1 Answers1

3

I use rehype-prism-plus and a mdx library next-mdx-remote together.

rehype-prism-plus is a rehype plugin to highlight code blocks in HTML with Prism (via refractor) with additional line highlighting and line numbers functionalities.

With next-mdx-remote the setting is very simple:

import { serialize } from "next-mdx-remote/serialize";
import rehypePrism from "rehype-prism-plus"

const mdxSource = await serialize(markdownContent, {
    mdxOptions: {
      remarkPlugins: [],
      rehypePlugins: [rehypePrism], //  here it is
    },
  });
iamCY
  • 31
  • 3