Skip to content

Commit faf3bd2

Browse files
authored
feat!: rename getHighlighter to createHighlighter (#702)
1 parent 2468337 commit faf3bd2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+305
-169
lines changed

docs/.vitepress/store/playground.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const usePlayground = defineStore('playground', () => {
3939
}
4040

4141
;(async () => {
42-
const { getHighlighter } = await import('shiki')
42+
const { createHighlighter } = await import('shiki')
4343
const { bundledLanguagesInfo: bundleFull } = await import('shiki/bundle/full')
4444
const { bundledLanguagesInfo: bundleWeb } = await import('shiki/bundle/web')
4545
const { bundledThemesInfo } = await import('shiki/themes')
@@ -64,7 +64,7 @@ export const usePlayground = defineStore('playground', () => {
6464
bundledLangsWeb.value = bundleWeb
6565

6666
if (typeof window !== 'undefined') {
67-
const highlighter = await getHighlighter({
67+
const highlighter = await createHighlighter({
6868
themes: [theme.value],
6969
langs: ['typescript', 'javascript', lang.value as any],
7070
})

docs/api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
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.
66

77
```ts twoslash
8-
import { getHighlighter } from 'shiki'
8+
import { createHighlighter } from 'shiki'
99

10-
const highlighter = await getHighlighter({
10+
const highlighter = await createHighlighter({
1111
themes: ['nord', 'min-light'],
1212
langs: ['javascript'],
1313
})

docs/guide/bundles.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ import {
2727
BundledLanguage,
2828
BundledTheme,
2929
codeToHtml,
30-
getHighlighter
30+
createHighlighter
3131
} from 'shiki/bundle/web' // [!code highlight]
3232
33-
const highlighter = await getHighlighter({
33+
const highlighter = await createHighlighter({
3434
langs: ['html', 'css', 'js'],
3535
themes: ['github-dark', 'github-light'],
3636
})

docs/guide/install.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,16 @@ const hast = await codeToHast('.text-red { color: red; }', {
8080

8181
### Highlighter Usage
8282

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 `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.
8484

8585
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.
8686

8787
```ts twoslash theme:nord
88-
import { getHighlighter } from 'shiki'
88+
import { createHighlighter } from 'shiki'
8989

90-
// `getHighlighter` is async, it initializes the internal and
90+
// `createHighlighter` is async, it initializes the internal and
9191
// loads the themes and languages specified.
92-
const highlighter = await getHighlighter({
92+
const highlighter = await createHighlighter({
9393
themes: ['nord'],
9494
langs: ['javascript'],
9595
})
@@ -103,16 +103,16 @@ const code = highlighter.codeToHtml('const a = 1', {
103103
```
104104

105105
:::info Important Note
106-
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.
107107

108108
If running on Node.js, we recommend using the [Shorthands](#shorthands) which manages the highlighter instance and dynamic theme/language loading for you.
109109
:::
110110

111111
Additionally, if you want to load themes and languages after the highlighter is created, you can use the `loadTheme` and `loadLanguage` methods.
112112

113113
```ts twoslash
114-
import { getHighlighter } from 'shiki'
115-
const highlighter = await getHighlighter({ themes: [], langs: [] })
114+
import { createHighlighter } from 'shiki'
115+
const highlighter = await createHighlighter({ themes: [], langs: [] })
116116
// ---cut---
117117
// load themes and languages after creation
118118
await highlighter.loadTheme('vitesse-light')
@@ -122,9 +122,9 @@ await highlighter.loadLanguage('css')
122122
Since Shiki v1.0, it requires all themes and languages to be loaded explicitly.
123123

124124
```ts theme:slack-dark twoslash
125-
import { getHighlighter } from 'shiki'
125+
import { createHighlighter } from 'shiki'
126126

127-
const highlighter = await getHighlighter({
127+
const highlighter = await createHighlighter({
128128
themes: ['slack-dark'],
129129
langs: ['css']
130130
})
@@ -143,9 +143,9 @@ await highlighter.loadLanguage('javascript') // load the language
143143
If you want to load all themes and languages (not recommended), you can iterate over all keys from `bundledLanguages` and `bundledThemes`.
144144

145145
```ts twoslash theme:poimandres
146-
import { bundledLanguages, bundledThemes, getHighlighter } from 'shiki'
146+
import { bundledLanguages, bundledThemes, createHighlighter } from 'shiki'
147147

148-
const highlighter = await getHighlighter({
148+
const highlighter = await createHighlighter({
149149
themes: Object.keys(bundledThemes),
150150
langs: Object.keys(bundledLanguages),
151151
})
@@ -163,15 +163,15 @@ When importing `shiki`, all the themes and languages are bundled as async chunks
163163
```ts twoslash theme:material-theme-ocean
164164
// @noErrors
165165
// `shiki/core` entry does not include any themes or languages or the wasm binary.
166-
import { getHighlighterCore } from 'shiki/core'
166+
import { createHighlighterCore } from 'shiki/core'
167167

168168
// `shiki/wasm` contains the wasm binary inlined as base64 string.
169169
import getWasm from 'shiki/wasm'
170170

171171
// directly import the theme and language modules, only the ones you imported will be bundled.
172172
import nord from 'shiki/themes/nord.mjs'
173173

174-
const highlighter = await getHighlighterCore({
174+
const highlighter = await createHighlighterCore({
175175
themes: [
176176
// instead of strings, you need to pass the imported module
177177
nord,
@@ -213,10 +213,10 @@ For example, the following ESM code:
213213

214214
```ts twoslash
215215
// ESM
216-
import { getHighlighter } from 'shiki'
216+
import { createHighlighter } from 'shiki'
217217

218218
async function main() {
219-
const highlighter = await getHighlighter({
219+
const highlighter = await createHighlighter({
220220
themes: ['vitesse-dark'],
221221
langs: ['javascript'],
222222
})
@@ -233,9 +233,9 @@ Can be written in CJS as:
233233
```ts twoslash
234234
// CJS
235235
async function main() {
236-
const { getHighlighter } = await import('shiki')
236+
const { createHighlighter } = await import('shiki')
237237

238-
const highlighter = await getHighlighter({
238+
const highlighter = await createHighlighter({
239239
themes: ['vitesse-dark'],
240240
langs: ['javascript'],
241241
})
@@ -282,7 +282,7 @@ Meanwhile, it's also recommended to use the [Fine-grained Bundle](#fine-grained-
282282

283283
```ts twoslash theme:nord
284284
// @noErrors
285-
import { getHighlighterCore, loadWasm } from 'shiki/core'
285+
import { createHighlighterCore, loadWasm } from 'shiki/core'
286286
import nord from 'shiki/themes/nord.mjs'
287287
import js from 'shiki/langs/javascript.mjs'
288288

@@ -291,7 +291,7 @@ await loadWasm(import('shiki/onig.wasm'))
291291

292292
export default {
293293
async fetch() {
294-
const highlighter = await getHighlighterCore({
294+
const highlighter = await createHighlighterCore({
295295
themes: [nord],
296296
langs: [js],
297297
})

docs/guide/load-lang.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ You can load custom languages by passing a TextMate grammar object into the `lan
66

77
```ts twoslash
88
// @noErrors
9-
import { getHighlighter } from 'shiki'
9+
import { createHighlighter } from 'shiki'
1010

1111
const myLang = JSON.parse(fs.readFileSync('my-lang.json', 'utf8'))
1212

13-
const highlighter = await getHighlighter({
13+
const highlighter = await createHighlighter({
1414
langs: [myLang],
1515
themes: ['vitesse-light']
1616
})
@@ -25,11 +25,11 @@ You can also load languages after the highlighter has been created.
2525

2626
```ts twoslash
2727
// @noErrors
28-
import { getHighlighter } from 'shiki'
28+
import { createHighlighter } from 'shiki'
2929

3030
const myLang = JSON.parse(fs.readFileSync('my-lang.json', 'utf8'))
3131

32-
const highlighter = await getHighlighter({
32+
const highlighter = await createHighlighter({
3333
langs: [],
3434
themes: ['vitesse-light'],
3535
})
@@ -49,7 +49,7 @@ Since v1.0, `shiki` now is environment agnostic, we don't have access to the fil
4949
For example, the following would not work:
5050

5151
```ts
52-
const highlighter = await getHighlighter({
52+
const highlighter = await createHighlighter({
5353
langs: [
5454
{
5555
name: 'vue-vine',
@@ -75,7 +75,7 @@ Instead, load that file yourself (via `fs`, `import()`, `fetch()`, etc.):
7575
```ts
7676
const vineGrammar = JSON.parse(fs.readFileSync(join(__dirname, './vine-ts.tmLanguage.json'), 'utf8'))
7777

78-
const highlighter = await getHighlighter({
78+
const highlighter = await createHighlighter({
7979
langs: [
8080
{
8181
name: 'vue-vine',
@@ -100,9 +100,9 @@ const highlighter = await getHighlighter({
100100
You can register custom language aliases with the `langAlias` option. For example:
101101

102102
```ts twoslash
103-
import { getHighlighter } from 'shiki'
103+
import { createHighlighter } from 'shiki'
104104

105-
const highlighter = await getHighlighter({
105+
const highlighter = await createHighlighter({
106106
langs: ['javascript'],
107107
langAlias: { // [!code hl:3]
108108
mylang: 'javascript',

docs/guide/load-theme.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ See [All Builtin Themes](/themes) first.
55
You can load custom themes by passing a `Theme` object into the `themes` array.
66

77
```ts twoslash
8-
import { getHighlighter } from 'shiki'
8+
import { createHighlighter } from 'shiki'
99

1010
const myTheme = {
1111
name: 'my-theme',
@@ -20,7 +20,7 @@ const myTheme = {
2020
]
2121
}
2222

23-
const highlighter = await getHighlighter({
23+
const highlighter = await createHighlighter({
2424
themes: [myTheme],
2525
langs: [],
2626
})
@@ -36,12 +36,12 @@ You can also load themes after the highlighter has been created.
3636

3737
```ts twoslash
3838
// @noErrors
39-
import { getHighlighter } from 'shiki'
39+
import { createHighlighter } from 'shiki'
4040

4141
// Load the theme object from a file, a network request, or anywhere
4242
const myTheme = JSON.parse(fs.readFileSync('my-theme.json', 'utf8'))
4343

44-
const highlighter = await getHighlighter({
44+
const highlighter = await createHighlighter({
4545
langs: ['javascript'],
4646
themes: [],
4747
})

docs/guide/migrate.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Breaking changes applies to main package `shiki`, but are shimmed by the [compat
2727

2828
- Top-level named exports `setCDN`, `loadLanguage`, `loadTheme`, `setWasm` are dropped as they are not needed anymore.
2929
- `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.
3131
- Highlighter does not maintain an internal default theme context. `theme` option is required for `codeToHtml` and `codeToTokens`.
3232
- `codeToThemedTokens` is renamed to `codeToTokensBase`, a higher level `codeToTokens` is added.
3333
- `codeToTokens` sets `includeExplanation` to `false` by default.

docs/guide/theme-colors.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
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:
66

77
```ts twoslash
8-
import { getHighlighter } from 'shiki'
8+
import { createHighlighter } from 'shiki'
99

10-
const highlighter = await getHighlighter({
10+
const highlighter = await createHighlighter({
1111
langs: ['javascript'],
1212
themes: [
1313
{
@@ -99,7 +99,7 @@ Shiki provides a factory function helper `createCssVariablesTheme` for creating
9999
This theme is **not included by default** and must be registered explicitly:
100100

101101
```ts twoslash
102-
import { createCssVariablesTheme, getHighlighter } from 'shiki'
102+
import { createCssVariablesTheme, createHighlighter } from 'shiki'
103103

104104
// Create a custom CSS variables theme, the following are the default values
105105
const myTheme = createCssVariablesTheme({ // [!code hl:6]
@@ -109,7 +109,7 @@ const myTheme = createCssVariablesTheme({ // [!code hl:6]
109109
fontStyle: true
110110
})
111111

112-
const highlighter = await getHighlighter({
112+
const highlighter = await createHighlighter({
113113
langs: ['javascript'],
114114
themes: [myTheme] // register the theme // [!code hl]
115115
})

docs/packages/markdown-it.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ By default, the full bundle of `shiki` will be imported. If you are using a [fin
3434
// @noErrors: true
3535
import MarkdownIt from 'markdown-it'
3636
import { fromHighlighter } from '@shikijs/markdown-it/core'
37-
import { getHighlighterCore } from 'shiki/core'
37+
import { createHighlighterCore } from 'shiki/core'
3838

39-
const highlighter = await getHighlighterCore({
39+
const highlighter = await createHighlighterCore({
4040
themes: [
4141
import('shiki/themes/vitesse-light.mjs')
4242
],

docs/packages/monaco.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ npm i -D @shikijs/monaco
1515
```
1616

1717
```ts
18-
import { getHighlighter } from 'shiki'
18+
import { createHighlighter } from 'shiki'
1919
import { shikiToMonaco } from '@shikijs/monaco'
2020
import * as monaco from 'monaco-editor-core'
2121

2222
// Create the highlighter, it can be reused
23-
const highlighter = await getHighlighter({
23+
const highlighter = await createHighlighter({
2424
themes: [
2525
'vitesse-dark',
2626
'vitesse-light',

0 commit comments

Comments
 (0)