Preview
const code = `type Languages = "javascript" | "typescript";`;
const highlighter = await highlight();
const html = highlighter.codeToHtml(code, {
lang: "javascript",
lang: "typescript",
theme: "one-light",
});Installation
- Install the following dependencies:
Shiki Transformers
pnpm i @shikijs/transformers -D- Customize the styles in your CSS file if needed:
shiki
Shiki Highlighter
#stylesThe main highlighter utility to render syntax highlighted code.
Usage
shikijs/rehype
- Set up
transformerNotationDiff:
Shiki Notation Highlight Transformer
import { transformerNotationDiff } from "@shikijs/transformers";
const rehypeShikiOptions: RehypeShikiCoreOptions = {
//...
transformers: [transformerNotationDiff()],
};
export { rehypeShikiOptions };- To add diff notation to your code blocks, use the
[!code ++]and[!code --]markers to indicate added and removed lines, respectively:
- Typescript/JavaScript:
```
const code = `type Languages = "javascript" | "typescript";`;
const highlighter = await highlight();
const html = highlighter.codeToHtml(code, {
lang: "javascript", // [!code --]
lang: "typescript", // [!code ++]
theme: "one-light",
});
```- React Code (TSX/JSX):
Use the {/* [!code ++] */} and {/* [!code --] */} comment syntax instead:
```tsx
export default function Page() {
return (
<h1>Hello</h1> {/* [!code --] */}
<h1>Hello World</h1> {/* [!code ++] */}
);
}
```The transformer automatically detects tsx and jsx languages and handles the { /* */ } comment syntax accordingly.