You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With this language you can use the **+** and **-** signs to tell the code highlighter to display the rows starting with a plus sign as if they had been added and the rows starting with a minus sign as if they had been removed
703
703
704
+
## Diff using a shiki transformer
705
+
706
+
You can also use shiki transformers in your rehype-pretty-code setup, as we just saw in the previous chapter, to create diffs one way is to use a language flag, the second way is to use the [shiki diff notation transformer](https://shiki.style/guide/transformers)
707
+
708
+
First we install the shiki transformers package:
709
+
710
+
```shell
711
+
npm i @shikijs/transformers --save-exact
712
+
```
713
+
714
+
Next we add a diff notation transformer to our Next.js configuration:
Line 8: we import the shiki "diff notation" transformer
745
+
746
+
Lines 22 to 24: add out shiki transformer to the rehype-pretty-code **transformers option**
747
+
748
+
> [!NOTE]
749
+
> we did set the "transformer matching algorithm" option () to v3 (as recommended in the transformers chapter of the [shiki v2 migration guide](https://shiki.style/blog/v2#transformers-matching-algorithm)) to get rid of the shiki deprecation notice:
750
+
>
751
+
> > [SHIKI DEPRECATE]: The default `matchAlgorithm: "v1"` is deprecated and will be removed in the future. Please explicitly set `matchAlgorithm: "v3"` in the transformer options.
752
+
753
+
Next we edit our global.css to add styling for added and removed rows:
754
+
755
+
```css title="/app/global.css"
756
+
[data-line].remove {
757
+
background-color: #852424;
758
+
border-left-color: #ff0000;
759
+
}
760
+
761
+
[data-line].add {
762
+
background-color: #248531;
763
+
border-left-color: #18c218;
764
+
}
765
+
```
766
+
767
+
How the [transformer diff notation](https://shiki.style/packages/transformers#transformernotationdiff) works, is that at the end of every line you use a comment to tell the transformer if code got added (`// [!code ++]`) or removed (`// [!code --]`):
0 commit comments