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 (optional)
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 --]`):
Rehype pretty code can also highlight inline code.
@@ -935,7 +1016,7 @@ If we used the correct tokens to create our aliases map, the colors in the list
935
1016

936
1017
937
1018
> [!TIP]
938
-
> There are even more features like **shiki transformers**, **visitor hooks** and **custom highlighters** (which we will not see in this tutorial), but you can find more info about them in the [rehype pretty code](https://rehype-pretty.pages.dev/) and [shiki](https://shiki.style/) docs websites
1019
+
> There are even more features like **visitor hooks** and **custom highlighters** (which we will not see in this tutorial), but you can find more info about them in the [rehype pretty code](https://rehype-pretty.pages.dev/) and [shiki](https://shiki.style/) docs websites
939
1020
940
1021
Congratulations 🎉 you finished learning about how to highlight code using a remark plugin and learned how to use most of its features (including using VSCode themes)
0 commit comments