返回 slidev
config-highlighter.md
根目录 / docs / custom / config-highlighter.md
1 # Configure Highlighter
2
3 Slidev uses [Shiki](https://github.com/shikijs/shiki) as the code highlighter. It's a TextMate Grammar powered syntax highlighter as accurate as VS Code. It generates colored tokens so no additinal CSS is required. Shiki also comes with [a bunch of built-in themes](https://shiki.style/themes). In Slidev, we also provided the [TwoSlash](#twoslash-integration) support.
4
5 ## Configure Shiki
6
7 <Environment type="both" />
8
9 Create `./setup/shiki.ts` file with the following content:
10
11 ```ts twoslash [setup/shiki.ts]
12 import { defineShikiSetup } from '@slidev/types'
13
14 export default defineShikiSetup(() => {
15 return {
16 themes: {
17 dark: 'min-dark',
18 light: 'min-light',
19 },
20 transformers: [
21 // ...
22 ],
23 }
24 })
25 ```
26
27 If you want to add custom theme or language (TextMate grammar/themes in JSON), you can import them in the setup file:
28
29 ```ts twoslash [setup/shiki.ts]
30 import { defineShikiSetup } from '@slidev/types'
31 // ---cut-start---
32 // @ts-expect-error missing types
33 // ---cut-end---
34 import customLanguage from './customLanguage.tmLanguage.json'
35 // ---cut-start---
36 // @ts-expect-error missing types
37 // ---cut-end---
38 import customTheme from './customTheme.tmTheme.json'
39
40 export default defineShikiSetup(() => {
41 return {
42 themes: {
43 dark: customTheme,
44 light: 'min-light',
45 },
46 langs: [
47 'js',
48 'typescript',
49 'cpp',
50 customLanguage,
51 // ...
52 ],
53 transformers: [
54 // ...
55 ],
56 }
57 })
58 ```
59
60 Check [Built-in languages](https://shiki.style/languages) and [Built-in themes](https://shiki.style/themes), and refer to [Shiki's docs](https://shiki.style) for more details.
61
62 :::info
63 For now, Shiki Magic Move does not support transformers.
64 :::
65
66 ## Configure Prism
67
68 :::warning
69 Prism support has been removed since v0.50. Please use Shiki instead.
70 :::
71
71 lines MARKDOWN