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
Copy file name to clipboardExpand all lines: docs/api.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,9 +5,9 @@
5
5
You can also get the intermediate `hast` to do custom rendering without serializing them into HTML with `codeToHast`. You can also further integrate the AST with the [unified](https://github.com/unifiedjs) ecosystem.
The [shorthands](#shorthands) we provided are executed asynchronously as we use WASM and load themes and languages on demand internally. In some cases, you may need to highlight code synchronously, so we provide the `getHighlighter` function to create a highlighter instance that can later be used synchronously.
83
+
The [shorthands](#shorthands) we provided are executed asynchronously as we use WASM and load themes and languages on demand internally. In some cases, you may need to highlight code synchronously, so we provide the `createHighlighter` function to create a highlighter instance that can later be used synchronously.
84
84
85
85
The usage is pretty much the same as with `codeToHtml`, where each theme and language file is a dynamically imported ES module. It would be better to list the languages and themes **explicitly** to have the best performance.
86
86
87
87
```ts twoslash theme:nord
88
-
import { getHighlighter } from'shiki'
88
+
import { createHighlighter } from'shiki'
89
89
90
-
// `getHighlighter` is async, it initializes the internal and
90
+
// `createHighlighter` is async, it initializes the internal and
Highlighter instance should be **long-lived singleton**. You might need to cache it somewhere and reuse it across your application. Avoid calling `getHighlighter` in hot functions or loops.
106
+
Highlighter instance should be **long-lived singleton**. You might need to cache it somewhere and reuse it across your application. Avoid calling `createHighlighter` in hot functions or loops.
107
107
108
108
If running on Node.js, we recommend using the [Shorthands](#shorthands) which manages the highlighter instance and dynamic theme/language loading for you.
109
109
:::
110
110
111
111
Additionally, if you want to load themes and languages after the highlighter is created, you can use the `loadTheme` and `loadLanguage` methods.
Copy file name to clipboardExpand all lines: docs/guide/migrate.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ Breaking changes applies to main package `shiki`, but are shimmed by the [compat
27
27
28
28
- Top-level named exports `setCDN`, `loadLanguage`, `loadTheme`, `setWasm` are dropped as they are not needed anymore.
29
29
-`BUNDLED_LANGUAGES`, `BUNDLED_THEMES` are moved to `shiki/langs` and `shiki/themes` and renamed to `bundledLanguages` and `bundledThemes` respectively.
30
-
-`theme` option for `getHighlighter` is dropped, use `themes` with an array instead.
30
+
-`theme` option for `createHighlighter` is dropped, use `themes` with an array instead.
31
31
- Highlighter does not maintain an internal default theme context. `theme` option is required for `codeToHtml` and `codeToTokens`.
32
32
-`codeToThemedTokens` is renamed to `codeToTokensBase`, a higher level `codeToTokens` is added.
33
33
-`codeToTokens` sets `includeExplanation` to `false` by default.
Copy file name to clipboardExpand all lines: docs/guide/theme-colors.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,9 +5,9 @@
5
5
Usually, TextMate themes expect the color values of each token to be a valid hex color value. This limitation is inherited from [`vscode-textmate`](https://github.com/microsoft/vscode-textmate). However, in Shiki v0.9.15 we introduced an automatic workaround by replacing non-hex color values with a placeholder and replacing them back on tokenization. This would allows you to use themes with arbitrary color values for rendering without worrying about the technical details:
6
6
7
7
```ts twoslash
8
-
import { getHighlighter } from'shiki'
8
+
import { createHighlighter } from'shiki'
9
9
10
-
const highlighter =awaitgetHighlighter({
10
+
const highlighter =awaitcreateHighlighter({
11
11
langs: ['javascript'],
12
12
themes: [
13
13
{
@@ -99,7 +99,7 @@ Shiki provides a factory function helper `createCssVariablesTheme` for creating
99
99
This theme is **not included by default** and must be registered explicitly:
0 commit comments