@shikijs/types 3.23.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +686 -684
- package/dist/index.mjs +9 -7
- package/package.json +6 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,281 +1,282 @@
|
|
|
1
|
-
import { Element, Root } from
|
|
2
|
-
import {
|
|
3
|
-
export { IRawGrammar as RawGrammar, IRawTheme as RawTheme, IRawThemeSetting as RawThemeSetting } from '@shikijs/vscode-textmate';
|
|
1
|
+
import { Element, Root } from "hast";
|
|
2
|
+
import { FontStyle, IGrammar, IRawGrammar as RawGrammar, IRawTheme as RawTheme, IRawThemeSetting, IRawThemeSetting as RawThemeSetting, OnigScanner, OnigString, StateStack } from "@shikijs/vscode-textmate";
|
|
4
3
|
|
|
4
|
+
//#region src/utils.d.ts
|
|
5
5
|
type Awaitable<T> = T | Promise<T>;
|
|
6
6
|
type MaybeGetter<T> = Awaitable<MaybeModule<T>> | (() => Awaitable<MaybeModule<T>>);
|
|
7
7
|
type MaybeModule<T> = T | {
|
|
8
|
-
|
|
8
|
+
default: T;
|
|
9
9
|
};
|
|
10
10
|
type MaybeArray<T> = T | T[];
|
|
11
11
|
type RequireKeys<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
|
12
|
-
interface Nothing {
|
|
13
|
-
}
|
|
12
|
+
interface Nothing {}
|
|
14
13
|
/**
|
|
15
14
|
* type StringLiteralUnion<'foo'> = 'foo' | string
|
|
16
15
|
* This has auto completion whereas `'foo' | string` doesn't
|
|
17
16
|
* Adapted from https://github.com/microsoft/TypeScript/issues/29729
|
|
18
17
|
*/
|
|
19
18
|
type StringLiteralUnion<T extends U, U = string> = T | (U & Nothing);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
interface RegexEngineString extends OnigString {
|
|
24
|
-
}
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/engines.d.ts
|
|
21
|
+
interface PatternScanner extends OnigScanner {}
|
|
22
|
+
interface RegexEngineString extends OnigString {}
|
|
25
23
|
/**
|
|
26
24
|
* Engine for RegExp matching and scanning.
|
|
27
25
|
*/
|
|
28
26
|
interface RegexEngine {
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
createScanner: (patterns: (string | RegExp)[]) => PatternScanner;
|
|
28
|
+
createString: (s: string) => RegexEngineString;
|
|
31
29
|
}
|
|
32
30
|
interface WebAssemblyInstantiator {
|
|
33
|
-
|
|
31
|
+
(importObject: Record<string, Record<string, WebAssembly.ImportValue>> | undefined): Promise<WebAssemblyInstance>;
|
|
34
32
|
}
|
|
35
33
|
type WebAssemblyInstance = WebAssembly.WebAssemblyInstantiatedSource | WebAssembly.Instance | WebAssembly.Instance['exports'];
|
|
36
34
|
type OnigurumaLoadOptions = {
|
|
37
|
-
|
|
35
|
+
instantiator: WebAssemblyInstantiator;
|
|
38
36
|
} | {
|
|
39
|
-
|
|
37
|
+
default: WebAssemblyInstantiator;
|
|
40
38
|
} | {
|
|
41
|
-
|
|
39
|
+
data: ArrayBufferView | ArrayBuffer | Response;
|
|
42
40
|
};
|
|
43
41
|
type LoadWasmOptionsPlain = OnigurumaLoadOptions | WebAssemblyInstantiator | ArrayBufferView | ArrayBuffer | Response;
|
|
44
42
|
type LoadWasmOptions = Awaitable<LoadWasmOptionsPlain> | (() => Awaitable<LoadWasmOptionsPlain>);
|
|
45
|
-
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/textmate.d.ts
|
|
46
45
|
interface Grammar extends IGrammar {
|
|
47
|
-
|
|
46
|
+
name: string;
|
|
48
47
|
}
|
|
49
|
-
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/langs.d.ts
|
|
50
50
|
type PlainTextLanguage = 'text' | 'plaintext' | 'txt' | 'plain';
|
|
51
51
|
type AnsiLanguage = 'ansi';
|
|
52
52
|
type SpecialLanguage = PlainTextLanguage | AnsiLanguage;
|
|
53
53
|
type LanguageInput = MaybeGetter<MaybeArray<LanguageRegistration>>;
|
|
54
54
|
type ResolveBundleKey<T extends string> = [T] extends [never] ? string : T;
|
|
55
|
-
interface LanguageRegistration extends
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
55
|
+
interface LanguageRegistration extends RawGrammar {
|
|
56
|
+
name: string;
|
|
57
|
+
scopeName: string;
|
|
58
|
+
displayName?: string;
|
|
59
|
+
aliases?: string[];
|
|
60
|
+
/**
|
|
61
|
+
* A list of languages the current language embeds.
|
|
62
|
+
* If manually specifying languages to load, make sure to load the embedded
|
|
63
|
+
* languages for each parent language.
|
|
64
|
+
*/
|
|
65
|
+
embeddedLangs?: string[];
|
|
66
|
+
embeddedLanguages?: string[];
|
|
67
|
+
/**
|
|
68
|
+
* A list of languages that embed the current language.
|
|
69
|
+
* Unlike `embeddedLangs`, the embedded languages will not be loaded automatically.
|
|
70
|
+
*/
|
|
71
|
+
embeddedLangsLazy?: string[];
|
|
72
|
+
balancedBracketSelectors?: string[];
|
|
73
|
+
unbalancedBracketSelectors?: string[];
|
|
74
|
+
foldingStopMarker?: string;
|
|
75
|
+
foldingStartMarker?: string;
|
|
76
|
+
/**
|
|
77
|
+
* Inject this language to other scopes.
|
|
78
|
+
* Same as `injectTo` in VSCode's `contributes.grammars`.
|
|
79
|
+
*
|
|
80
|
+
* @see https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide#injection-grammars
|
|
81
|
+
*/
|
|
82
|
+
injectTo?: string[];
|
|
83
83
|
}
|
|
84
84
|
interface BundledLanguageInfo {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
id: string;
|
|
86
|
+
name: string;
|
|
87
|
+
import: DynamicImportLanguageRegistration;
|
|
88
|
+
aliases?: string[];
|
|
89
89
|
}
|
|
90
90
|
type DynamicImportLanguageRegistration = () => Promise<{
|
|
91
|
-
|
|
91
|
+
default: LanguageRegistration[];
|
|
92
92
|
}>;
|
|
93
|
-
|
|
93
|
+
//#endregion
|
|
94
|
+
//#region src/decorations.d.ts
|
|
94
95
|
interface DecorationOptions {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
/**
|
|
97
|
+
* Custom decorations to wrap highlighted tokens with.
|
|
98
|
+
*/
|
|
99
|
+
decorations?: DecorationItem[];
|
|
99
100
|
}
|
|
100
101
|
interface DecorationItem {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
102
|
+
/**
|
|
103
|
+
* Start offset or position of the decoration.
|
|
104
|
+
*/
|
|
105
|
+
start: OffsetOrPosition;
|
|
106
|
+
/**
|
|
107
|
+
* End offset or position of the decoration.
|
|
108
|
+
*/
|
|
109
|
+
end: OffsetOrPosition;
|
|
110
|
+
/**
|
|
111
|
+
* Tag name of the element to create.
|
|
112
|
+
* @default 'span'
|
|
113
|
+
*/
|
|
114
|
+
tagName?: string;
|
|
115
|
+
/**
|
|
116
|
+
* Properties of the element to create.
|
|
117
|
+
*/
|
|
118
|
+
properties?: Element['properties'];
|
|
119
|
+
/**
|
|
120
|
+
* A custom function to transform the element after it has been created.
|
|
121
|
+
*/
|
|
122
|
+
transform?: (element: Element, type: DecorationTransformType) => Element | void;
|
|
123
|
+
/**
|
|
124
|
+
* By default when the decoration contains only one token, the decoration will be applied to the token.
|
|
125
|
+
*
|
|
126
|
+
* Set to `true` to always wrap the token with a new element
|
|
127
|
+
*
|
|
128
|
+
* @default false
|
|
129
|
+
*/
|
|
130
|
+
alwaysWrap?: boolean;
|
|
130
131
|
}
|
|
131
132
|
interface ResolvedDecorationItem extends Omit<DecorationItem, 'start' | 'end'> {
|
|
132
|
-
|
|
133
|
-
|
|
133
|
+
start: ResolvedPosition;
|
|
134
|
+
end: ResolvedPosition;
|
|
134
135
|
}
|
|
135
136
|
type DecorationTransformType = 'wrapper' | 'line' | 'token';
|
|
136
137
|
interface Position {
|
|
137
|
-
|
|
138
|
-
|
|
138
|
+
line: number;
|
|
139
|
+
character: number;
|
|
139
140
|
}
|
|
140
141
|
type Offset = number;
|
|
141
142
|
type OffsetOrPosition = Position | Offset;
|
|
142
143
|
interface ResolvedPosition extends Position {
|
|
143
|
-
|
|
144
|
+
offset: Offset;
|
|
144
145
|
}
|
|
145
|
-
|
|
146
|
+
//#endregion
|
|
147
|
+
//#region src/themes.d.ts
|
|
146
148
|
type SpecialTheme = 'none';
|
|
147
149
|
type ThemeInput = MaybeGetter<ThemeRegistrationAny>;
|
|
148
|
-
interface ThemeRegistrationRaw extends
|
|
149
|
-
}
|
|
150
|
-
interface
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
*/
|
|
220
|
-
semanticTokenColors?: Record<string, string>;
|
|
150
|
+
interface ThemeRegistrationRaw extends RawTheme, Partial<Omit<ThemeRegistration, 'name' | 'settings'>> {}
|
|
151
|
+
interface ThemeRegistration extends Partial<ThemeRegistrationResolved> {}
|
|
152
|
+
interface ThemeRegistrationResolved extends RawTheme {
|
|
153
|
+
/**
|
|
154
|
+
* Theme name
|
|
155
|
+
*/
|
|
156
|
+
name: string;
|
|
157
|
+
/**
|
|
158
|
+
* Display name
|
|
159
|
+
*
|
|
160
|
+
* @field shiki custom property
|
|
161
|
+
*/
|
|
162
|
+
displayName?: string;
|
|
163
|
+
/**
|
|
164
|
+
* Light/dark theme
|
|
165
|
+
*
|
|
166
|
+
* @field shiki custom property
|
|
167
|
+
*/
|
|
168
|
+
type: 'light' | 'dark';
|
|
169
|
+
/**
|
|
170
|
+
* Token rules
|
|
171
|
+
*/
|
|
172
|
+
settings: RawThemeSetting[];
|
|
173
|
+
/**
|
|
174
|
+
* Same as `settings`, will use as fallback if `settings` is not present.
|
|
175
|
+
*/
|
|
176
|
+
tokenColors?: RawThemeSetting[];
|
|
177
|
+
/**
|
|
178
|
+
* Default foreground color
|
|
179
|
+
*
|
|
180
|
+
* @field shiki custom property
|
|
181
|
+
*/
|
|
182
|
+
fg: string;
|
|
183
|
+
/**
|
|
184
|
+
* Background color
|
|
185
|
+
*
|
|
186
|
+
* @field shiki custom property
|
|
187
|
+
*/
|
|
188
|
+
bg: string;
|
|
189
|
+
/**
|
|
190
|
+
* A map of color names to new color values.
|
|
191
|
+
*
|
|
192
|
+
* The color key starts with '#' and should be lowercased.
|
|
193
|
+
*
|
|
194
|
+
* @field shiki custom property
|
|
195
|
+
*/
|
|
196
|
+
colorReplacements?: Record<string, string>;
|
|
197
|
+
/**
|
|
198
|
+
* Color map of VS Code options
|
|
199
|
+
*
|
|
200
|
+
* Will be used by shiki on `lang: 'ansi'` to find ANSI colors, and to find the default foreground/background colors.
|
|
201
|
+
*/
|
|
202
|
+
colors?: Record<string, string>;
|
|
203
|
+
/**
|
|
204
|
+
* JSON schema path
|
|
205
|
+
*
|
|
206
|
+
* @field not used by shiki
|
|
207
|
+
*/
|
|
208
|
+
$schema?: string;
|
|
209
|
+
/**
|
|
210
|
+
* Enable semantic highlighting
|
|
211
|
+
*
|
|
212
|
+
* @field not used by shiki
|
|
213
|
+
*/
|
|
214
|
+
semanticHighlighting?: boolean;
|
|
215
|
+
/**
|
|
216
|
+
* Tokens for semantic highlighting
|
|
217
|
+
*
|
|
218
|
+
* @field not used by shiki
|
|
219
|
+
*/
|
|
220
|
+
semanticTokenColors?: Record<string, string>;
|
|
221
221
|
}
|
|
222
222
|
type ThemeRegistrationAny = ThemeRegistrationRaw | ThemeRegistration | ThemeRegistrationResolved;
|
|
223
223
|
type DynamicImportThemeRegistration = () => Promise<{
|
|
224
|
-
|
|
224
|
+
default: ThemeRegistration;
|
|
225
225
|
}>;
|
|
226
226
|
interface BundledThemeInfo {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
227
|
+
id: string;
|
|
228
|
+
displayName: string;
|
|
229
|
+
type: 'light' | 'dark';
|
|
230
|
+
import: DynamicImportThemeRegistration;
|
|
231
231
|
}
|
|
232
|
-
|
|
232
|
+
//#endregion
|
|
233
|
+
//#region src/tokens.d.ts
|
|
233
234
|
/**
|
|
234
235
|
* GrammarState is a special reference object that holds the state of a grammar.
|
|
235
236
|
*
|
|
236
237
|
* It's used to highlight code snippets that are part of the target language.
|
|
237
238
|
*/
|
|
238
239
|
interface GrammarState {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
240
|
+
readonly lang: string;
|
|
241
|
+
readonly theme: string;
|
|
242
|
+
readonly themes: string[];
|
|
243
|
+
/**
|
|
244
|
+
* @internal
|
|
245
|
+
*/
|
|
246
|
+
getInternalStack: (theme?: string) => StateStack | undefined;
|
|
247
|
+
getScopes: (theme?: string) => string[] | undefined;
|
|
247
248
|
}
|
|
248
249
|
interface CodeToTokensBaseOptions<Languages extends string = string, Themes extends string = string> extends TokenizeWithThemeOptions {
|
|
249
|
-
|
|
250
|
-
|
|
250
|
+
lang?: Languages | SpecialLanguage;
|
|
251
|
+
theme?: Themes | ThemeRegistrationAny | SpecialTheme;
|
|
251
252
|
}
|
|
252
253
|
type CodeToTokensOptions<Languages extends string = string, Themes extends string = string> = Omit<CodeToTokensBaseOptions<Languages, Themes>, 'theme'> & CodeOptionsThemes<Themes>;
|
|
253
254
|
interface CodeToTokensWithThemesOptions<Languages = string, Themes = string> extends TokenizeWithThemeOptions {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
255
|
+
lang?: Languages | SpecialLanguage;
|
|
256
|
+
/**
|
|
257
|
+
* A map of color names to themes.
|
|
258
|
+
*
|
|
259
|
+
* `light` and `dark` are required, and arbitrary color names can be added.
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* ```ts
|
|
263
|
+
* themes: {
|
|
264
|
+
* light: 'vitesse-light',
|
|
265
|
+
* dark: 'vitesse-dark',
|
|
266
|
+
* soft: 'nord',
|
|
267
|
+
* // custom colors
|
|
268
|
+
* }
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
|
+
themes: Partial<Record<string, Themes | ThemeRegistrationAny | SpecialTheme>>;
|
|
271
272
|
}
|
|
272
273
|
interface ThemedTokenScopeExplanation {
|
|
273
|
-
|
|
274
|
-
|
|
274
|
+
scopeName: string;
|
|
275
|
+
themeMatches?: IRawThemeSetting[];
|
|
275
276
|
}
|
|
276
277
|
interface ThemedTokenExplanation {
|
|
277
|
-
|
|
278
|
-
|
|
278
|
+
content: string;
|
|
279
|
+
scopes: ThemedTokenScopeExplanation[];
|
|
279
280
|
}
|
|
280
281
|
/**
|
|
281
282
|
* A single token with color, and optionally with explanation.
|
|
@@ -331,414 +332,415 @@ interface ThemedTokenExplanation {
|
|
|
331
332
|
* }
|
|
332
333
|
* ```
|
|
333
334
|
*/
|
|
334
|
-
interface ThemedToken extends TokenStyles, TokenBase {
|
|
335
|
-
}
|
|
335
|
+
interface ThemedToken extends TokenStyles, TokenBase {}
|
|
336
336
|
interface TokenBase {
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
337
|
+
/**
|
|
338
|
+
* The content of the token
|
|
339
|
+
*/
|
|
340
|
+
content: string;
|
|
341
|
+
/**
|
|
342
|
+
* The start offset of the token, relative to the input code. 0-indexed.
|
|
343
|
+
*/
|
|
344
|
+
offset: number;
|
|
345
|
+
/**
|
|
346
|
+
* Explanation of
|
|
347
|
+
*
|
|
348
|
+
* - token text's matching scopes
|
|
349
|
+
* - reason that token text is given a color (one matching scope matches a rule (scope -> color) in the theme)
|
|
350
|
+
*/
|
|
351
|
+
explanation?: ThemedTokenExplanation[];
|
|
352
352
|
}
|
|
353
353
|
interface TokenStyles {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
354
|
+
/**
|
|
355
|
+
* 6 or 8 digit hex code representation of the token's color
|
|
356
|
+
*/
|
|
357
|
+
color?: string;
|
|
358
|
+
/**
|
|
359
|
+
* 6 or 8 digit hex code representation of the token's background color
|
|
360
|
+
*/
|
|
361
|
+
bgColor?: string;
|
|
362
|
+
/**
|
|
363
|
+
* Font style of token. Can be None/Italic/Bold/Underline
|
|
364
|
+
*/
|
|
365
|
+
fontStyle?: FontStyle;
|
|
366
|
+
/**
|
|
367
|
+
* Override with custom inline style for HTML renderer.
|
|
368
|
+
* When specified, `color` and `fontStyle` will be ignored.
|
|
369
|
+
* Prefer use object style for merging with other styles.
|
|
370
|
+
*/
|
|
371
|
+
htmlStyle?: Record<string, string>;
|
|
372
|
+
/**
|
|
373
|
+
* Extra HTML attributes for the token.
|
|
374
|
+
*/
|
|
375
|
+
htmlAttrs?: Record<string, string>;
|
|
376
376
|
}
|
|
377
377
|
interface ThemedTokenWithVariants extends TokenBase {
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
378
|
+
/**
|
|
379
|
+
* An object of color name to token styles
|
|
380
|
+
*/
|
|
381
|
+
variants: Record<string, TokenStyles>;
|
|
382
382
|
}
|
|
383
383
|
interface TokenizeWithThemeOptions {
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
384
|
+
/**
|
|
385
|
+
* Include explanation of why a token is given a color.
|
|
386
|
+
*
|
|
387
|
+
* You can optionally pass `scopeName` to only include explanation for scopes,
|
|
388
|
+
* which is more performant than full explanation.
|
|
389
|
+
*
|
|
390
|
+
* @default false
|
|
391
|
+
*/
|
|
392
|
+
includeExplanation?: boolean | 'scopeName';
|
|
393
|
+
/**
|
|
394
|
+
* A map of color names to new color values.
|
|
395
|
+
*
|
|
396
|
+
* The color key starts with '#' and should be lowercased.
|
|
397
|
+
*
|
|
398
|
+
* This will be merged with theme's `colorReplacements` if any.
|
|
399
|
+
*/
|
|
400
|
+
colorReplacements?: Record<string, string | Record<string, string>>;
|
|
401
|
+
/**
|
|
402
|
+
* Lines above this length will not be tokenized for performance reasons.
|
|
403
|
+
*
|
|
404
|
+
* @default 0 (no limit)
|
|
405
|
+
*/
|
|
406
|
+
tokenizeMaxLineLength?: number;
|
|
407
|
+
/**
|
|
408
|
+
* Time limit in milliseconds for tokenizing a single line.
|
|
409
|
+
*
|
|
410
|
+
* @default 500 (0.5s)
|
|
411
|
+
*/
|
|
412
|
+
tokenizeTimeLimit?: number;
|
|
413
|
+
/**
|
|
414
|
+
* Represent the state of the grammar, allowing to continue tokenizing from a intermediate grammar state.
|
|
415
|
+
*
|
|
416
|
+
* You can get the grammar state from `getLastGrammarState`.
|
|
417
|
+
*/
|
|
418
|
+
grammarState?: GrammarState;
|
|
419
|
+
/**
|
|
420
|
+
* The code context of the grammar.
|
|
421
|
+
* Consider it a prepended code to the input code, that only participate the grammar inference but not presented in the final output.
|
|
422
|
+
*
|
|
423
|
+
* This will be ignored if `grammarState` is provided.
|
|
424
|
+
*/
|
|
425
|
+
grammarContextCode?: string;
|
|
426
426
|
}
|
|
427
427
|
/**
|
|
428
428
|
* Result of `codeToTokens`, an object with 2D array of tokens and meta info like background and foreground color.
|
|
429
429
|
*/
|
|
430
430
|
interface TokensResult {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
}
|
|
457
|
-
|
|
431
|
+
/**
|
|
432
|
+
* 2D array of tokens, first dimension is lines, second dimension is tokens in a line.
|
|
433
|
+
*/
|
|
434
|
+
tokens: ThemedToken[][];
|
|
435
|
+
/**
|
|
436
|
+
* Foreground color of the code.
|
|
437
|
+
*/
|
|
438
|
+
fg?: string;
|
|
439
|
+
/**
|
|
440
|
+
* Background color of the code.
|
|
441
|
+
*/
|
|
442
|
+
bg?: string;
|
|
443
|
+
/**
|
|
444
|
+
* A string representation of themes applied to the token.
|
|
445
|
+
*/
|
|
446
|
+
themeName?: string;
|
|
447
|
+
/**
|
|
448
|
+
* Custom style string to be applied to the root `<pre>` element.
|
|
449
|
+
* When specified, `fg` and `bg` will be ignored.
|
|
450
|
+
*/
|
|
451
|
+
rootStyle?: string | false;
|
|
452
|
+
/**
|
|
453
|
+
* The last grammar state of the code snippet.
|
|
454
|
+
*/
|
|
455
|
+
grammarState?: GrammarState;
|
|
456
|
+
}
|
|
457
|
+
//#endregion
|
|
458
|
+
//#region src/transformers.d.ts
|
|
458
459
|
interface TransformerOptions {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
}
|
|
464
|
-
interface ShikiTransformerContextMeta {
|
|
460
|
+
/**
|
|
461
|
+
* Transformers for the Shiki pipeline.
|
|
462
|
+
*/
|
|
463
|
+
transformers?: ShikiTransformer[];
|
|
465
464
|
}
|
|
465
|
+
interface ShikiTransformerContextMeta {}
|
|
466
466
|
/**
|
|
467
467
|
* Common transformer context for all transformers hooks
|
|
468
468
|
*/
|
|
469
469
|
interface ShikiTransformerContextCommon {
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
470
|
+
meta: ShikiTransformerContextMeta;
|
|
471
|
+
options: CodeToHastOptions;
|
|
472
|
+
codeToHast: (code: string, options: CodeToHastOptions) => Root;
|
|
473
|
+
codeToTokens: (code: string, options: CodeToTokensOptions) => TokensResult;
|
|
474
474
|
}
|
|
475
475
|
interface ShikiTransformerContextSource extends ShikiTransformerContextCommon {
|
|
476
|
-
|
|
476
|
+
readonly source: string;
|
|
477
477
|
}
|
|
478
478
|
/**
|
|
479
479
|
* Transformer context for HAST related hooks
|
|
480
480
|
*/
|
|
481
481
|
interface ShikiTransformerContext extends ShikiTransformerContextSource {
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
482
|
+
readonly tokens: ThemedToken[][];
|
|
483
|
+
readonly root: Root;
|
|
484
|
+
readonly pre: Element;
|
|
485
|
+
readonly code: Element;
|
|
486
|
+
readonly lines: Element[];
|
|
487
|
+
readonly structure: CodeToHastOptions['structure'];
|
|
488
|
+
/**
|
|
489
|
+
* Utility to append class to a hast node
|
|
490
|
+
*
|
|
491
|
+
* If the `property.class` is a string, it will be splitted by space and converted to an array.
|
|
492
|
+
*/
|
|
493
|
+
addClassToHast: (hast: Element, className: string | string[]) => Element;
|
|
494
494
|
}
|
|
495
495
|
interface ShikiTransformer {
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
}
|
|
549
|
-
|
|
496
|
+
/**
|
|
497
|
+
* Name of the transformer
|
|
498
|
+
*/
|
|
499
|
+
name?: string;
|
|
500
|
+
/**
|
|
501
|
+
* Enforce plugin invocation tier similar to webpack loaders. Hooks ordering
|
|
502
|
+
* is still subject to the `order` property in the hook object.
|
|
503
|
+
*
|
|
504
|
+
* Plugin invocation order:
|
|
505
|
+
* - `enforce: 'pre'` plugins
|
|
506
|
+
* - normal plugins
|
|
507
|
+
* - `enforce: 'post'` plugins
|
|
508
|
+
* - shiki post plugins
|
|
509
|
+
*/
|
|
510
|
+
enforce?: 'pre' | 'post';
|
|
511
|
+
/**
|
|
512
|
+
* Transform the raw input code before passing to the highlighter.
|
|
513
|
+
*/
|
|
514
|
+
preprocess?: (this: ShikiTransformerContextCommon, code: string, options: CodeToHastOptions) => string | void;
|
|
515
|
+
/**
|
|
516
|
+
* Transform the full tokens list before converting to HAST.
|
|
517
|
+
* Return a new tokens list will replace the original one.
|
|
518
|
+
*/
|
|
519
|
+
tokens?: (this: ShikiTransformerContextSource, tokens: ThemedToken[][]) => ThemedToken[][] | void;
|
|
520
|
+
/**
|
|
521
|
+
* Transform the entire generated HAST tree. Return a new Node will replace the original one.
|
|
522
|
+
*/
|
|
523
|
+
root?: (this: ShikiTransformerContext, hast: Root) => Root | void;
|
|
524
|
+
/**
|
|
525
|
+
* Transform the `<pre>` element. Return a new Node will replace the original one.
|
|
526
|
+
*/
|
|
527
|
+
pre?: (this: ShikiTransformerContext, hast: Element) => Element | void;
|
|
528
|
+
/**
|
|
529
|
+
* Transform the `<code>` element. Return a new Node will replace the original one.
|
|
530
|
+
*/
|
|
531
|
+
code?: (this: ShikiTransformerContext, hast: Element) => Element | void;
|
|
532
|
+
/**
|
|
533
|
+
* Transform each line `<span class="line">` element.
|
|
534
|
+
*
|
|
535
|
+
* @param hast
|
|
536
|
+
* @param line 1-based line number
|
|
537
|
+
*/
|
|
538
|
+
line?: (this: ShikiTransformerContext, hast: Element, line: number) => Element | void;
|
|
539
|
+
/**
|
|
540
|
+
* Transform each token `<span>` element.
|
|
541
|
+
*/
|
|
542
|
+
span?: (this: ShikiTransformerContext, hast: Element, line: number, col: number, lineElement: Element, token: ThemedToken) => Element | void;
|
|
543
|
+
/**
|
|
544
|
+
* Transform the generated HTML string before returning.
|
|
545
|
+
* This hook will only be called with `codeToHtml`.
|
|
546
|
+
*/
|
|
547
|
+
postprocess?: (this: ShikiTransformerContextCommon, html: string, options: CodeToHastOptions) => string | void;
|
|
548
|
+
}
|
|
549
|
+
//#endregion
|
|
550
|
+
//#region src/options.d.ts
|
|
550
551
|
interface HighlighterCoreOptions<Sync extends boolean = false> {
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
552
|
+
/**
|
|
553
|
+
* Custom RegExp engine.
|
|
554
|
+
*/
|
|
555
|
+
engine: Sync extends true ? RegexEngine : Awaitable<RegexEngine>;
|
|
556
|
+
/**
|
|
557
|
+
* Theme names, or theme registration objects to be loaded upfront.
|
|
558
|
+
*/
|
|
559
|
+
themes?: Sync extends true ? MaybeArray<ThemeRegistrationAny>[] : ThemeInput[];
|
|
560
|
+
/**
|
|
561
|
+
* Language names, or language registration objects to be loaded upfront.
|
|
562
|
+
*/
|
|
563
|
+
langs?: Sync extends true ? MaybeArray<LanguageRegistration>[] : LanguageInput[];
|
|
564
|
+
/**
|
|
565
|
+
* Alias of languages
|
|
566
|
+
* @example { 'my-lang': 'javascript' }
|
|
567
|
+
*/
|
|
568
|
+
langAlias?: Record<string, string>;
|
|
569
|
+
/**
|
|
570
|
+
* Emit console warnings to alert users of potential issues.
|
|
571
|
+
* @default true
|
|
572
|
+
*/
|
|
573
|
+
warnings?: boolean;
|
|
573
574
|
}
|
|
574
575
|
interface BundledHighlighterOptions<L extends string, T extends string> extends Pick<HighlighterCoreOptions, 'warnings'> {
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
576
|
+
/**
|
|
577
|
+
* Custom RegExp engine.
|
|
578
|
+
*/
|
|
579
|
+
engine?: Awaitable<RegexEngine>;
|
|
580
|
+
/**
|
|
581
|
+
* Theme registation
|
|
582
|
+
*
|
|
583
|
+
* @default []
|
|
584
|
+
*/
|
|
585
|
+
themes: (ThemeInput | StringLiteralUnion<T> | SpecialTheme)[];
|
|
586
|
+
/**
|
|
587
|
+
* Language registation
|
|
588
|
+
*
|
|
589
|
+
* @default []
|
|
590
|
+
*/
|
|
591
|
+
langs: (LanguageInput | StringLiteralUnion<L> | SpecialLanguage)[];
|
|
592
|
+
/**
|
|
593
|
+
* Alias of languages
|
|
594
|
+
* @example { 'my-lang': 'javascript' }
|
|
595
|
+
*/
|
|
596
|
+
langAlias?: Record<string, StringLiteralUnion<L>>;
|
|
596
597
|
}
|
|
597
598
|
interface CodeOptionsSingleTheme<Themes extends string = string> {
|
|
598
|
-
|
|
599
|
+
theme: ThemeRegistrationAny | StringLiteralUnion<Themes>;
|
|
599
600
|
}
|
|
600
601
|
interface CodeOptionsMultipleThemes<Themes extends string = string> {
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
602
|
+
/**
|
|
603
|
+
* A map of color names to themes.
|
|
604
|
+
* This allows you to specify multiple themes for the generated code.
|
|
605
|
+
*
|
|
606
|
+
* ```ts
|
|
607
|
+
* highlighter.codeToHtml(code, {
|
|
608
|
+
* lang: 'js',
|
|
609
|
+
* themes: {
|
|
610
|
+
* light: 'vitesse-light',
|
|
611
|
+
* dark: 'vitesse-dark',
|
|
612
|
+
* }
|
|
613
|
+
* })
|
|
614
|
+
* ```
|
|
615
|
+
*
|
|
616
|
+
* Will generate:
|
|
617
|
+
*
|
|
618
|
+
* ```html
|
|
619
|
+
* <span style="color:#111;--shiki-dark:#fff;">code</span>
|
|
620
|
+
* ```
|
|
621
|
+
*
|
|
622
|
+
* @see https://shiki.style/guide/dual-themes
|
|
623
|
+
*/
|
|
624
|
+
themes: Partial<Record<string, ThemeRegistrationAny | StringLiteralUnion<Themes>>>;
|
|
625
|
+
/**
|
|
626
|
+
* The default theme applied to the code (via inline `color` style).
|
|
627
|
+
* The rest of the themes are applied via CSS variables, and toggled by CSS overrides.
|
|
628
|
+
*
|
|
629
|
+
* For example, if `defaultColor` is `light`, then `light` theme is applied to the code,
|
|
630
|
+
* and the `dark` theme and other custom themes are applied via CSS variables:
|
|
631
|
+
*
|
|
632
|
+
* ```html
|
|
633
|
+
* <span style="color:#{light};--shiki-dark:#{dark};--shiki-custom:#{custom};">code</span>
|
|
634
|
+
* ```
|
|
635
|
+
*
|
|
636
|
+
* When set to `false`, no default styles will be applied, and totally up to users to apply the styles:
|
|
637
|
+
*
|
|
638
|
+
* ```html
|
|
639
|
+
* <span style="--shiki-light:#{light};--shiki-dark:#{dark};--shiki-custom:#{custom};">code</span>
|
|
640
|
+
* ```
|
|
641
|
+
*
|
|
642
|
+
* When set to `light-dark()`, the default color will be rendered as `light-dark(#{light}, #{dark})`.
|
|
643
|
+
*
|
|
644
|
+
* ```html
|
|
645
|
+
* <span style="color:light-dark(#{light}, #{dark});--shiki-dark:#{dark};--shiki-custom:#{custom};">code</span>
|
|
646
|
+
* ```
|
|
647
|
+
*
|
|
648
|
+
* @default 'light'
|
|
649
|
+
*/
|
|
650
|
+
defaultColor?: StringLiteralUnion<'light' | 'dark'> | 'light-dark()' | false;
|
|
651
|
+
/**
|
|
652
|
+
* The strategy to render multiple colors.
|
|
653
|
+
*
|
|
654
|
+
* - `css-vars`: Render the colors via CSS variables.
|
|
655
|
+
* - `none`: Do not render the colors, only use the default color.
|
|
656
|
+
*
|
|
657
|
+
* @default 'css-vars'
|
|
658
|
+
*/
|
|
659
|
+
colorsRendering?: 'css-vars' | 'none';
|
|
660
|
+
/**
|
|
661
|
+
* Prefix of CSS variables used to store the color of the other theme.
|
|
662
|
+
*
|
|
663
|
+
* @default '--shiki-'
|
|
664
|
+
*/
|
|
665
|
+
cssVariablePrefix?: string;
|
|
665
666
|
}
|
|
666
667
|
type CodeOptionsThemes<Themes extends string = string> = CodeOptionsSingleTheme<Themes> | CodeOptionsMultipleThemes<Themes>;
|
|
667
668
|
type CodeToHastOptions<Languages extends string = string, Themes extends string = string> = CodeToHastOptionsCommon<Languages> & CodeOptionsThemes<Themes> & CodeOptionsMeta;
|
|
668
669
|
interface CodeToHastOptionsCommon<Languages extends string = string> extends TransformerOptions, DecorationOptions, Pick<TokenizeWithThemeOptions, 'colorReplacements' | 'tokenizeMaxLineLength' | 'tokenizeTimeLimit' | 'grammarState' | 'grammarContextCode' | 'includeExplanation'> {
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
670
|
+
/**
|
|
671
|
+
* Data to be added to the root `<pre>` element.
|
|
672
|
+
*/
|
|
673
|
+
data?: Record<string, unknown>;
|
|
674
|
+
/**
|
|
675
|
+
* The grammar name for the code.
|
|
676
|
+
*/
|
|
677
|
+
lang: StringLiteralUnion<Languages | SpecialLanguage>;
|
|
678
|
+
/**
|
|
679
|
+
* Custom style string to be applied to the root `<pre>` element.
|
|
680
|
+
*
|
|
681
|
+
* When set to `false`, no style will be applied.
|
|
682
|
+
*/
|
|
683
|
+
rootStyle?: string | false;
|
|
684
|
+
/**
|
|
685
|
+
* Merge whitespace tokens to saving extra `<span>`.
|
|
686
|
+
*
|
|
687
|
+
* When set to true, it will merge whitespace tokens with the next token.
|
|
688
|
+
* When set to false, it keep the output as-is.
|
|
689
|
+
* When set to `never`, it will force to separate leading and trailing spaces from tokens.
|
|
690
|
+
*
|
|
691
|
+
* @default true
|
|
692
|
+
*/
|
|
693
|
+
mergeWhitespaces?: boolean | 'never';
|
|
694
|
+
/**
|
|
695
|
+
* Merge consecutive tokens with the same style to reduce the number of DOM nodes.
|
|
696
|
+
* This can improve rendering performance but may affect the structure of the output.
|
|
697
|
+
*
|
|
698
|
+
* @default false
|
|
699
|
+
*/
|
|
700
|
+
mergeSameStyleTokens?: boolean;
|
|
701
|
+
/**
|
|
702
|
+
* The structure of the generated HAST and HTML.
|
|
703
|
+
*
|
|
704
|
+
* - `classic`: The classic structure with `<pre>` and `<code>` elements, each line wrapped with a `<span class="line">` element.
|
|
705
|
+
* - `inline`: All tokens are rendered as `<span>`, line breaks are rendered as `<br>`. No `<pre>` or `<code>` elements. Default forground and background colors are not applied.
|
|
706
|
+
*
|
|
707
|
+
* @default 'classic'
|
|
708
|
+
*/
|
|
709
|
+
structure?: 'classic' | 'inline';
|
|
710
|
+
/**
|
|
711
|
+
* Tab index of the root `<pre>` element.
|
|
712
|
+
*
|
|
713
|
+
* Set to `false` to disable tab index.
|
|
714
|
+
*
|
|
715
|
+
* @default 0
|
|
716
|
+
*/
|
|
717
|
+
tabindex?: number | string | false;
|
|
717
718
|
}
|
|
718
719
|
interface CodeOptionsMeta {
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
720
|
+
/**
|
|
721
|
+
* Meta data passed to Shiki, usually used by plugin integrations to pass the code block header.
|
|
722
|
+
*
|
|
723
|
+
* Key values in meta will be serialized to the attributes of the root `<pre>` element.
|
|
724
|
+
*
|
|
725
|
+
* Keys starting with `_` will be ignored.
|
|
726
|
+
*
|
|
727
|
+
* A special key `__raw` key will be used to pass the raw code block header (if the integration supports it).
|
|
728
|
+
*/
|
|
729
|
+
meta?: {
|
|
730
|
+
/**
|
|
731
|
+
* Raw string of the code block header.
|
|
732
|
+
*/
|
|
733
|
+
__raw?: string;
|
|
734
|
+
[key: string]: any;
|
|
735
|
+
};
|
|
735
736
|
}
|
|
736
737
|
interface CodeToHastRenderOptionsCommon extends TransformerOptions, Omit<TokensResult, 'tokens'> {
|
|
737
|
-
|
|
738
|
-
|
|
738
|
+
lang?: string;
|
|
739
|
+
langId?: string;
|
|
739
740
|
}
|
|
740
741
|
type CodeToHastRenderOptions = CodeToHastRenderOptionsCommon & CodeToHastOptions;
|
|
741
|
-
|
|
742
|
+
//#endregion
|
|
743
|
+
//#region src/highlighter.d.ts
|
|
742
744
|
/**
|
|
743
745
|
* Type of object that can be bound to a grammar state
|
|
744
746
|
*/
|
|
@@ -746,116 +748,116 @@ type GrammarStateMapKey = Root | ThemedToken[][];
|
|
|
746
748
|
/**
|
|
747
749
|
* Internal context of Shiki, core textmate logic
|
|
748
750
|
*/
|
|
749
|
-
interface
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
751
|
+
interface ShikiPrimitive<BundledLangKeys extends string = never, BundledThemeKeys extends string = never> {
|
|
752
|
+
/**
|
|
753
|
+
* Load a theme to the highlighter, so later it can be used synchronously.
|
|
754
|
+
*/
|
|
755
|
+
loadTheme: (...themes: (ThemeInput | BundledThemeKeys | SpecialTheme)[]) => Promise<void>;
|
|
756
|
+
/**
|
|
757
|
+
* Load a theme registration synchronously.
|
|
758
|
+
*/
|
|
759
|
+
loadThemeSync: (...themes: MaybeArray<ThemeRegistrationAny>[]) => void;
|
|
760
|
+
/**
|
|
761
|
+
* Load a language to the highlighter, so later it can be used synchronously.
|
|
762
|
+
*/
|
|
763
|
+
loadLanguage: (...langs: (LanguageInput | BundledLangKeys | SpecialLanguage)[]) => Promise<void>;
|
|
764
|
+
/**
|
|
765
|
+
* Load a language registration synchronously.
|
|
766
|
+
*/
|
|
767
|
+
loadLanguageSync: (...langs: MaybeArray<LanguageRegistration>[]) => void;
|
|
768
|
+
/**
|
|
769
|
+
* Get the registered theme object
|
|
770
|
+
*/
|
|
771
|
+
getTheme: (name: string | ThemeRegistrationAny) => ThemeRegistrationResolved;
|
|
772
|
+
/**
|
|
773
|
+
* Get the registered language object
|
|
774
|
+
*/
|
|
775
|
+
getLanguage: (name: string | LanguageRegistration) => Grammar;
|
|
776
|
+
/**
|
|
777
|
+
* Set the current theme and get the resolved theme object and color map.
|
|
778
|
+
* @internal
|
|
779
|
+
*/
|
|
780
|
+
setTheme: (themeName: string | ThemeRegistrationAny) => {
|
|
781
|
+
theme: ThemeRegistrationResolved;
|
|
782
|
+
colorMap: string[];
|
|
783
|
+
};
|
|
784
|
+
/**
|
|
785
|
+
* Resolve a language alias
|
|
786
|
+
*/
|
|
787
|
+
resolveLangAlias: (lang: string) => string;
|
|
788
|
+
/**
|
|
789
|
+
* Get the names of loaded languages
|
|
790
|
+
*
|
|
791
|
+
* Special-handled languages like `text`, `plain` and `ansi` are not included.
|
|
792
|
+
*/
|
|
793
|
+
getLoadedLanguages: () => string[];
|
|
794
|
+
/**
|
|
795
|
+
* Get the names of loaded themes
|
|
796
|
+
*
|
|
797
|
+
* Special-handled themes like `none` are not included.
|
|
798
|
+
*/
|
|
799
|
+
getLoadedThemes: () => string[];
|
|
800
|
+
/**
|
|
801
|
+
* Dispose the internal registry and release resources
|
|
802
|
+
*/
|
|
803
|
+
dispose: () => void;
|
|
804
|
+
/**
|
|
805
|
+
* Dispose the internal registry and release resources
|
|
806
|
+
*/
|
|
807
|
+
[Symbol.dispose]: () => void;
|
|
806
808
|
}
|
|
807
809
|
/**
|
|
808
810
|
* Generic instance interface of Shiki
|
|
809
811
|
*/
|
|
810
|
-
interface HighlighterGeneric<BundledLangKeys extends string, BundledThemeKeys extends string> extends
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
812
|
+
interface HighlighterGeneric<BundledLangKeys extends string, BundledThemeKeys extends string> extends ShikiPrimitive<BundledLangKeys, BundledThemeKeys> {
|
|
813
|
+
/**
|
|
814
|
+
* Get highlighted code in HTML string
|
|
815
|
+
*/
|
|
816
|
+
codeToHtml: (code: string, options: CodeToHastOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>) => string;
|
|
817
|
+
/**
|
|
818
|
+
* Get highlighted code in HAST.
|
|
819
|
+
* @see https://github.com/syntax-tree/hast
|
|
820
|
+
*/
|
|
821
|
+
codeToHast: (code: string, options: CodeToHastOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>) => Root;
|
|
822
|
+
/**
|
|
823
|
+
* Get highlighted code in tokens. Uses `codeToTokensWithThemes` or `codeToTokensBase` based on the options.
|
|
824
|
+
*/
|
|
825
|
+
codeToTokens: (code: string, options: CodeToTokensOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>) => TokensResult;
|
|
826
|
+
/**
|
|
827
|
+
* Get highlighted code in tokens with a single theme.
|
|
828
|
+
* @returns A 2D array of tokens, first dimension is lines, second dimension is tokens in a line.
|
|
829
|
+
*/
|
|
830
|
+
codeToTokensBase: (code: string, options: CodeToTokensBaseOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>) => ThemedToken[][];
|
|
831
|
+
/**
|
|
832
|
+
* Get highlighted code in tokens with multiple themes.
|
|
833
|
+
*
|
|
834
|
+
* Different from `codeToTokensBase`, each token will have a `variants` property consisting of an object of color name to token styles.
|
|
835
|
+
*
|
|
836
|
+
* @returns A 2D array of tokens, first dimension is lines, second dimension is tokens in a line.
|
|
837
|
+
*/
|
|
838
|
+
codeToTokensWithThemes: (code: string, options: CodeToTokensWithThemesOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>) => ThemedTokenWithVariants[][];
|
|
839
|
+
/**
|
|
840
|
+
* Get the last grammar state of a code snippet.
|
|
841
|
+
* You can pass the grammar state to `codeToTokens` as `grammarState` to continue tokenizing from an intermediate state.
|
|
842
|
+
*/
|
|
843
|
+
getLastGrammarState: {
|
|
844
|
+
(element: GrammarStateMapKey, options?: never): GrammarState | undefined;
|
|
845
|
+
(code: string, options: CodeToTokensBaseOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>): GrammarState;
|
|
846
|
+
};
|
|
847
|
+
/**
|
|
848
|
+
* Get internal context object
|
|
849
|
+
* @internal
|
|
850
|
+
* @deprecated
|
|
851
|
+
*/
|
|
852
|
+
getInternalContext: () => ShikiPrimitive;
|
|
853
|
+
/**
|
|
854
|
+
* Get bundled languages object
|
|
855
|
+
*/
|
|
856
|
+
getBundledLanguages: () => Record<BundledLangKeys, LanguageInput>;
|
|
857
|
+
/**
|
|
858
|
+
* Get bundled themes object
|
|
859
|
+
*/
|
|
860
|
+
getBundledThemes: () => Record<BundledThemeKeys, ThemeInput>;
|
|
859
861
|
}
|
|
860
862
|
/**
|
|
861
863
|
* The fine-grained core Shiki highlighter instance.
|
|
@@ -865,21 +867,21 @@ type HighlighterCore = HighlighterGeneric<never, never>;
|
|
|
865
867
|
* Options for creating a bundled highlighter.
|
|
866
868
|
*/
|
|
867
869
|
interface CreateBundledHighlighterOptions<BundledLangs extends string, BundledThemes extends string> {
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
870
|
+
langs: Record<BundledLangs, LanguageInput>;
|
|
871
|
+
themes: Record<BundledThemes, ThemeInput>;
|
|
872
|
+
engine: () => Awaitable<RegexEngine>;
|
|
871
873
|
}
|
|
872
874
|
/**
|
|
873
875
|
* @deprecated Use `CreateBundledHighlighterOptions` instead.
|
|
874
876
|
*/
|
|
875
|
-
interface CreatedBundledHighlighterOptions<BundledLangs extends string, BundledThemes extends string> extends CreateBundledHighlighterOptions<BundledLangs, BundledThemes> {
|
|
876
|
-
|
|
877
|
-
|
|
877
|
+
interface CreatedBundledHighlighterOptions<BundledLangs extends string, BundledThemes extends string> extends CreateBundledHighlighterOptions<BundledLangs, BundledThemes> {}
|
|
878
|
+
//#endregion
|
|
879
|
+
//#region src/bundle-factory.d.ts
|
|
878
880
|
type CreateHighlighterFactory<L extends string, T extends string> = (options: BundledHighlighterOptions<L, T>) => Promise<HighlighterGeneric<L, T>>;
|
|
879
|
-
|
|
881
|
+
//#endregion
|
|
882
|
+
//#region src/error.d.ts
|
|
880
883
|
declare class ShikiError extends Error {
|
|
881
|
-
|
|
884
|
+
constructor(message: string);
|
|
882
885
|
}
|
|
883
|
-
|
|
884
|
-
export { ShikiError };
|
|
885
|
-
export type { AnsiLanguage, Awaitable, BundledHighlighterOptions, BundledLanguageInfo, BundledThemeInfo, CodeOptionsMeta, CodeOptionsMultipleThemes, CodeOptionsSingleTheme, CodeOptionsThemes, CodeToHastOptions, CodeToHastOptionsCommon, CodeToHastRenderOptions, CodeToHastRenderOptionsCommon, CodeToTokensBaseOptions, CodeToTokensOptions, CodeToTokensWithThemesOptions, CreateBundledHighlighterOptions, CreateHighlighterFactory, CreatedBundledHighlighterOptions, DecorationItem, DecorationOptions, DecorationTransformType, DynamicImportLanguageRegistration, DynamicImportThemeRegistration, Grammar, GrammarState, GrammarStateMapKey, HighlighterCore, HighlighterCoreOptions, HighlighterGeneric, LanguageInput, LanguageRegistration, LoadWasmOptions, LoadWasmOptionsPlain, MaybeArray, MaybeGetter, MaybeModule, Offset, OffsetOrPosition, OnigurumaLoadOptions, PatternScanner, PlainTextLanguage, Position, RegexEngine, RegexEngineString, RequireKeys, ResolveBundleKey, ResolvedDecorationItem, ResolvedPosition, ShikiInternal, ShikiTransformer, ShikiTransformerContext, ShikiTransformerContextCommon, ShikiTransformerContextMeta, ShikiTransformerContextSource, SpecialLanguage, SpecialTheme, StringLiteralUnion, ThemeInput, ThemeRegistration, ThemeRegistrationAny, ThemeRegistrationRaw, ThemeRegistrationResolved, ThemedToken, ThemedTokenExplanation, ThemedTokenScopeExplanation, ThemedTokenWithVariants, TokenBase, TokenStyles, TokenizeWithThemeOptions, TokensResult, TransformerOptions, WebAssemblyInstance, WebAssemblyInstantiator };
|
|
886
|
+
//#endregion
|
|
887
|
+
export { AnsiLanguage, Awaitable, BundledHighlighterOptions, BundledLanguageInfo, BundledThemeInfo, CodeOptionsMeta, CodeOptionsMultipleThemes, CodeOptionsSingleTheme, CodeOptionsThemes, CodeToHastOptions, CodeToHastOptionsCommon, CodeToHastRenderOptions, CodeToHastRenderOptionsCommon, CodeToTokensBaseOptions, CodeToTokensOptions, CodeToTokensWithThemesOptions, CreateBundledHighlighterOptions, CreateHighlighterFactory, CreatedBundledHighlighterOptions, DecorationItem, DecorationOptions, DecorationTransformType, DynamicImportLanguageRegistration, DynamicImportThemeRegistration, Grammar, GrammarState, GrammarStateMapKey, HighlighterCore, HighlighterCoreOptions, HighlighterGeneric, LanguageInput, LanguageRegistration, LoadWasmOptions, LoadWasmOptionsPlain, MaybeArray, MaybeGetter, MaybeModule, Offset, OffsetOrPosition, OnigurumaLoadOptions, PatternScanner, PlainTextLanguage, Position, type RawGrammar, type RawTheme, type RawThemeSetting, RegexEngine, RegexEngineString, RequireKeys, ResolveBundleKey, ResolvedDecorationItem, ResolvedPosition, ShikiError, ShikiPrimitive, ShikiTransformer, ShikiTransformerContext, ShikiTransformerContextCommon, ShikiTransformerContextMeta, ShikiTransformerContextSource, SpecialLanguage, SpecialTheme, StringLiteralUnion, ThemeInput, ThemeRegistration, ThemeRegistrationAny, ThemeRegistrationRaw, ThemeRegistrationResolved, ThemedToken, ThemedTokenExplanation, ThemedTokenScopeExplanation, ThemedTokenWithVariants, TokenBase, TokenStyles, TokenizeWithThemeOptions, TokensResult, TransformerOptions, WebAssemblyInstance, WebAssemblyInstantiator };
|