Custom Components

Code Block - Diff Notation

Enabling diff notation in code blocks


Diff Notation

Diff notation is a way to show the changes between two versions of a file, like git diff if you familiar.

Code Example

Show diff notation using the // [!code ++] for added line and // [!code --] for removed line identifier. The identifier is place at top of the line.

mdx
```ts showLineNumbers
function MyComponent() {
  return (
    <div>
      //[!code --:3]
      <h1>Hello World</h1>
      <p>Unchanged Line</p>
 
      //[!code ++]
      <h1>Hello Next.js</h1>
 
      <p>Highlighted Line</p>
      <p>Focused Line</p>
    </div>
  );
}
```

It will show like this

ts
function MyComponent() {
  return (
    <div>
      <h1>Hello World</h1>
      <p>Unchanged Line</p>
 
      <h1>Hello Next.js</h1>
 
      <p>Highlighted Line</p>
      <p>Focused Line</p>
    </div>
  );
}