@shikijs/core 1.15.1 → 1.16.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/types.d.mts CHANGED
@@ -1,12 +1,654 @@
1
- import { Root } from 'hast';
2
- import { I as IGrammar, T as ThemeInput, g as SpecialTheme, L as LanguageInput, S as SpecialLanguage, h as ThemeRegistrationAny, m as ThemeRegistrationResolved, s as LanguageRegistration, C as CodeToHastOptions, r as ResolveBundleKey, a as CodeToTokensOptions, b as TokensResult, c as CodeToTokensBaseOptions, d as ThemedToken, e as CodeToTokensWithThemesOptions, f as ThemedTokenWithVariants, G as GrammarState } from './chunk-tokens.mjs';
3
- export { A as AnsiLanguage, $ as Awaitable, B as BundledHighlighterOptions, t as BundledLanguageInfo, Q as BundledThemeInfo, y as CodeOptionsMeta, v as CodeOptionsMultipleThemes, u as CodeOptionsSingleTheme, w as CodeOptionsThemes, x as CodeToHastOptionsCommon, o as CodeToHastRenderOptions, z as CodeToHastRenderOptionsCommon, a4 as DecorationItem, a3 as DecorationOptions, a6 as DecorationTransformType, D as DynamicImportLanguageRegistration, O as DynamicImportThemeRegistration, X as FontStyle, H as HighlighterCoreOptions, M as MaybeArray, a0 as MaybeGetter, a1 as MaybeModule, a7 as Offset, a8 as OffsetOrPosition, P as PlainTextLanguage, k as Position, E as RawGrammar, F as RawTheme, J as RawThemeSetting, R as RequireKeys, a5 as ResolvedDecorationItem, a9 as ResolvedPosition, q as ShikiTransformer, _ as ShikiTransformerContext, n as ShikiTransformerContextCommon, Z as ShikiTransformerContextMeta, p as ShikiTransformerContextSource, a2 as StringLiteralUnion, N as ThemeRegistration, K as ThemeRegistrationRaw, V as ThemedTokenExplanation, U as ThemedTokenScopeExplanation, W as TokenBase, j as TokenStyles, i as TokenizeWithThemeOptions, Y as TransformerOptions } from './chunk-tokens.mjs';
4
- export { L as LoadWasmOptions, a as WebAssemblyInstance, W as WebAssemblyInstantiator } from './chunk-engines.mjs';
1
+ import { Root, Element } from 'hast';
2
+ import { I as IGrammar, b as MaybeGetter, M as MaybeArray, c as IRawGrammar, d as IRawTheme, e as IRawThemeSetting, j as StateStack, a as RegexEngine, A as Awaitable, L as LoadWasmOptions, S as StringLiteralUnion } from './chunk-engines.mjs';
3
+ export { J as JavaScriptRegexEngineOptions, i as LoadWasmOptionsPlain, f as MaybeModule, O as OnigurumaLoadOptions, P as PatternScanner, g as RegexEngineString, R as RequireKeys, h as WebAssemblyInstance, W as WebAssemblyInstantiator } from './chunk-engines.mjs';
5
4
 
6
5
  interface Grammar extends IGrammar {
7
6
  name: string;
8
7
  }
9
8
 
9
+ type PlainTextLanguage = 'text' | 'plaintext' | 'txt';
10
+ type AnsiLanguage = 'ansi';
11
+ type SpecialLanguage = PlainTextLanguage | AnsiLanguage;
12
+ type LanguageInput = MaybeGetter<MaybeArray<LanguageRegistration>>;
13
+ type ResolveBundleKey<T extends string> = [T] extends [never] ? string : T;
14
+ interface LanguageRegistration extends IRawGrammar {
15
+ name: string;
16
+ scopeName: string;
17
+ displayName?: string;
18
+ aliases?: string[];
19
+ /**
20
+ * A list of languages the current language embeds.
21
+ * If manually specifying languages to load, make sure to load the embedded
22
+ * languages for each parent language.
23
+ */
24
+ embeddedLangs?: string[];
25
+ /**
26
+ * A list of languages that embed the current language.
27
+ * Unlike `embeddedLangs`, the embedded languages will not be loaded automatically.
28
+ */
29
+ embeddedLangsLazy?: string[];
30
+ balancedBracketSelectors?: string[];
31
+ unbalancedBracketSelectors?: string[];
32
+ foldingStopMarker?: string;
33
+ foldingStartMarker?: string;
34
+ /**
35
+ * Inject this language to other scopes.
36
+ * Same as `injectTo` in VSCode's `contributes.grammars`.
37
+ *
38
+ * @see https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide#injection-grammars
39
+ */
40
+ injectTo?: string[];
41
+ }
42
+ interface BundledLanguageInfo {
43
+ id: string;
44
+ name: string;
45
+ import: DynamicImportLanguageRegistration;
46
+ aliases?: string[];
47
+ }
48
+ type DynamicImportLanguageRegistration = () => Promise<{
49
+ default: LanguageRegistration[];
50
+ }>;
51
+
52
+ type SpecialTheme = 'none';
53
+ type ThemeInput = MaybeGetter<ThemeRegistrationAny>;
54
+ interface ThemeRegistrationRaw extends IRawTheme, Partial<Omit<ThemeRegistration, 'name' | 'settings'>> {
55
+ }
56
+ interface ThemeRegistration extends Partial<ThemeRegistrationResolved> {
57
+ }
58
+ interface ThemeRegistrationResolved extends IRawTheme {
59
+ /**
60
+ * Theme name
61
+ */
62
+ name: string;
63
+ /**
64
+ * Display name
65
+ *
66
+ * @field shiki custom property
67
+ */
68
+ displayName?: string;
69
+ /**
70
+ * Light/dark theme
71
+ *
72
+ * @field shiki custom property
73
+ */
74
+ type: 'light' | 'dark';
75
+ /**
76
+ * Token rules
77
+ */
78
+ settings: IRawThemeSetting[];
79
+ /**
80
+ * Same as `settings`, will use as fallback if `settings` is not present.
81
+ */
82
+ tokenColors?: IRawThemeSetting[];
83
+ /**
84
+ * Default foreground color
85
+ *
86
+ * @field shiki custom property
87
+ */
88
+ fg: string;
89
+ /**
90
+ * Background color
91
+ *
92
+ * @field shiki custom property
93
+ */
94
+ bg: string;
95
+ /**
96
+ * A map of color names to new color values.
97
+ *
98
+ * The color key starts with '#' and should be lowercased.
99
+ *
100
+ * @field shiki custom property
101
+ */
102
+ colorReplacements?: Record<string, string>;
103
+ /**
104
+ * Color map of VS Code options
105
+ *
106
+ * Will be used by shiki on `lang: 'ansi'` to find ANSI colors, and to find the default foreground/background colors.
107
+ */
108
+ colors?: Record<string, string>;
109
+ /**
110
+ * JSON schema path
111
+ *
112
+ * @field not used by shiki
113
+ */
114
+ $schema?: string;
115
+ /**
116
+ * Enable semantic highlighting
117
+ *
118
+ * @field not used by shiki
119
+ */
120
+ semanticHighlighting?: boolean;
121
+ /**
122
+ * Tokens for semantic highlighting
123
+ *
124
+ * @field not used by shiki
125
+ */
126
+ semanticTokenColors?: Record<string, string>;
127
+ }
128
+ type ThemeRegistrationAny = ThemeRegistrationRaw | ThemeRegistration | ThemeRegistrationResolved;
129
+ type DynamicImportThemeRegistration = () => Promise<{
130
+ default: ThemeRegistration;
131
+ }>;
132
+ interface BundledThemeInfo {
133
+ id: string;
134
+ displayName: string;
135
+ type: 'light' | 'dark';
136
+ import: DynamicImportThemeRegistration;
137
+ }
138
+
139
+ /**
140
+ * GrammarState is a special reference object that holds the state of a grammar.
141
+ *
142
+ * It's used to highlight code snippets that are part of the target language.
143
+ */
144
+ declare class GrammarState {
145
+ private readonly _stack;
146
+ readonly lang: string;
147
+ readonly theme: string;
148
+ /**
149
+ * Static method to create a initial grammar state.
150
+ */
151
+ static initial(lang: string, theme: string): GrammarState;
152
+ constructor(_stack: StateStack, lang: string, theme: string);
153
+ get scopes(): string[];
154
+ toJSON(): {
155
+ lang: string;
156
+ theme: string;
157
+ scopes: string[];
158
+ };
159
+ }
160
+
161
+ interface TransformerOptions {
162
+ /**
163
+ * Transformers for the Shiki pipeline.
164
+ */
165
+ transformers?: ShikiTransformer[];
166
+ }
167
+ interface ShikiTransformerContextMeta {
168
+ }
169
+ /**
170
+ * Common transformer context for all transformers hooks
171
+ */
172
+ interface ShikiTransformerContextCommon {
173
+ meta: ShikiTransformerContextMeta;
174
+ options: CodeToHastOptions;
175
+ codeToHast: (code: string, options: CodeToHastOptions) => Root;
176
+ codeToTokens: (code: string, options: CodeToTokensOptions) => TokensResult;
177
+ }
178
+ interface ShikiTransformerContextSource extends ShikiTransformerContextCommon {
179
+ readonly source: string;
180
+ }
181
+ /**
182
+ * Transformer context for HAST related hooks
183
+ */
184
+ interface ShikiTransformerContext extends ShikiTransformerContextSource {
185
+ readonly tokens: ThemedToken[][];
186
+ readonly root: Root;
187
+ readonly pre: Element;
188
+ readonly code: Element;
189
+ readonly lines: Element[];
190
+ readonly structure: CodeToHastOptions['structure'];
191
+ /**
192
+ * Utility to append class to a hast node
193
+ *
194
+ * If the `property.class` is a string, it will be splitted by space and converted to an array.
195
+ */
196
+ addClassToHast: (hast: Element, className: string | string[]) => Element;
197
+ }
198
+ interface ShikiTransformer {
199
+ /**
200
+ * Name of the transformer
201
+ */
202
+ name?: string;
203
+ /**
204
+ * Transform the raw input code before passing to the highlighter.
205
+ */
206
+ preprocess?: (this: ShikiTransformerContextCommon, code: string, options: CodeToHastOptions) => string | void;
207
+ /**
208
+ * Transform the full tokens list before converting to HAST.
209
+ * Return a new tokens list will replace the original one.
210
+ */
211
+ tokens?: (this: ShikiTransformerContextSource, tokens: ThemedToken[][]) => ThemedToken[][] | void;
212
+ /**
213
+ * Transform the entire generated HAST tree. Return a new Node will replace the original one.
214
+ */
215
+ root?: (this: ShikiTransformerContext, hast: Root) => Root | void;
216
+ /**
217
+ * Transform the `<pre>` element. Return a new Node will replace the original one.
218
+ */
219
+ pre?: (this: ShikiTransformerContext, hast: Element) => Element | void;
220
+ /**
221
+ * Transform the `<code>` element. Return a new Node will replace the original one.
222
+ */
223
+ code?: (this: ShikiTransformerContext, hast: Element) => Element | void;
224
+ /**
225
+ * Transform each line `<span class="line">` element.
226
+ *
227
+ * @param hast
228
+ * @param line 1-based line number
229
+ */
230
+ line?: (this: ShikiTransformerContext, hast: Element, line: number) => Element | void;
231
+ /**
232
+ * Transform each token `<span>` element.
233
+ */
234
+ span?: (this: ShikiTransformerContext, hast: Element, line: number, col: number, lineElement: Element) => Element | void;
235
+ /**
236
+ * Transform the generated HTML string before returning.
237
+ * This hook will only be called with `codeToHtml`.
238
+ */
239
+ postprocess?: (this: ShikiTransformerContextCommon, html: string, options: CodeToHastOptions) => string | void;
240
+ }
241
+
242
+ interface DecorationOptions {
243
+ /**
244
+ * Custom decorations to wrap highlighted tokens with.
245
+ */
246
+ decorations?: DecorationItem[];
247
+ }
248
+ interface DecorationItem {
249
+ /**
250
+ * Start offset or position of the decoration.
251
+ */
252
+ start: OffsetOrPosition;
253
+ /**
254
+ * End offset or position of the decoration.
255
+ */
256
+ end: OffsetOrPosition;
257
+ /**
258
+ * Tag name of the element to create.
259
+ * @default 'span'
260
+ */
261
+ tagName?: string;
262
+ /**
263
+ * Properties of the element to create.
264
+ */
265
+ properties?: Element['properties'];
266
+ /**
267
+ * A custom function to transform the element after it has been created.
268
+ */
269
+ transform?: (element: Element, type: DecorationTransformType) => Element | void;
270
+ /**
271
+ * By default when the decoration contains only one token, the decoration will be applied to the token.
272
+ *
273
+ * Set to `true` to always wrap the token with a new element
274
+ *
275
+ * @default false
276
+ */
277
+ alwaysWrap?: boolean;
278
+ }
279
+ interface ResolvedDecorationItem extends Omit<DecorationItem, 'start' | 'end'> {
280
+ start: ResolvedPosition;
281
+ end: ResolvedPosition;
282
+ }
283
+ type DecorationTransformType = 'wrapper' | 'line' | 'token';
284
+ interface Position {
285
+ line: number;
286
+ character: number;
287
+ }
288
+ type Offset = number;
289
+ type OffsetOrPosition = Position | Offset;
290
+ interface ResolvedPosition extends Position {
291
+ offset: Offset;
292
+ }
293
+
294
+ interface HighlighterCoreOptions<Sync extends boolean = false> {
295
+ /**
296
+ * Custom RegExp engine.
297
+ */
298
+ engine?: Sync extends true ? RegexEngine : Awaitable<RegexEngine>;
299
+ /**
300
+ * Theme names, or theme registration objects to be loaded upfront.
301
+ */
302
+ themes?: Sync extends true ? MaybeArray<ThemeRegistrationAny>[] : ThemeInput[];
303
+ /**
304
+ * Language names, or language registration objects to be loaded upfront.
305
+ */
306
+ langs?: Sync extends true ? MaybeArray<LanguageRegistration>[] : LanguageInput[];
307
+ /**
308
+ * Alias of languages
309
+ * @example { 'my-lang': 'javascript' }
310
+ */
311
+ langAlias?: Record<string, string>;
312
+ /**
313
+ * Emit console warnings to alert users of potential issues.
314
+ * @default true
315
+ */
316
+ warnings?: boolean;
317
+ /**
318
+ * Load wasm file from a custom path or using a custom function.
319
+ */
320
+ loadWasm?: Sync extends true ? never : LoadWasmOptions;
321
+ }
322
+ interface BundledHighlighterOptions<L extends string, T extends string> extends Pick<HighlighterCoreOptions, 'warnings' | 'engine'> {
323
+ /**
324
+ * Theme registation
325
+ *
326
+ * @default []
327
+ */
328
+ themes: (ThemeInput | StringLiteralUnion<T> | SpecialTheme)[];
329
+ /**
330
+ * Language registation
331
+ *
332
+ * @default []
333
+ */
334
+ langs: (LanguageInput | StringLiteralUnion<L> | SpecialLanguage)[];
335
+ /**
336
+ * Alias of languages
337
+ * @example { 'my-lang': 'javascript' }
338
+ */
339
+ langAlias?: Record<string, StringLiteralUnion<L>>;
340
+ }
341
+ interface CodeOptionsSingleTheme<Themes extends string = string> {
342
+ theme: ThemeRegistrationAny | StringLiteralUnion<Themes>;
343
+ }
344
+ interface CodeOptionsMultipleThemes<Themes extends string = string> {
345
+ /**
346
+ * A map of color names to themes.
347
+ * This allows you to specify multiple themes for the generated code.
348
+ *
349
+ * ```ts
350
+ * highlighter.codeToHtml(code, {
351
+ * lang: 'js',
352
+ * themes: {
353
+ * light: 'vitesse-light',
354
+ * dark: 'vitesse-dark',
355
+ * }
356
+ * })
357
+ * ```
358
+ *
359
+ * Will generate:
360
+ *
361
+ * ```html
362
+ * <span style="color:#111;--shiki-dark:#fff;">code</span>
363
+ * ```
364
+ *
365
+ * @see https://github.com/shikijs/shiki#lightdark-dual-themes
366
+ */
367
+ themes: Partial<Record<string, ThemeRegistrationAny | StringLiteralUnion<Themes>>>;
368
+ /**
369
+ * The default theme applied to the code (via inline `color` style).
370
+ * The rest of the themes are applied via CSS variables, and toggled by CSS overrides.
371
+ *
372
+ * For example, if `defaultColor` is `light`, then `light` theme is applied to the code,
373
+ * and the `dark` theme and other custom themes are applied via CSS variables:
374
+ *
375
+ * ```html
376
+ * <span style="color:#{light};--shiki-dark:#{dark};--shiki-custom:#{custom};">code</span>
377
+ * ```
378
+ *
379
+ * When set to `false`, no default styles will be applied, and totally up to users to apply the styles:
380
+ *
381
+ * ```html
382
+ * <span style="--shiki-light:#{light};--shiki-dark:#{dark};--shiki-custom:#{custom};">code</span>
383
+ * ```
384
+ *
385
+ *
386
+ * @default 'light'
387
+ */
388
+ defaultColor?: StringLiteralUnion<'light' | 'dark'> | false;
389
+ /**
390
+ * Prefix of CSS variables used to store the color of the other theme.
391
+ *
392
+ * @default '--shiki-'
393
+ */
394
+ cssVariablePrefix?: string;
395
+ }
396
+ type CodeOptionsThemes<Themes extends string = string> = CodeOptionsSingleTheme<Themes> | CodeOptionsMultipleThemes<Themes>;
397
+ type CodeToHastOptions<Languages extends string = string, Themes extends string = string> = CodeToHastOptionsCommon<Languages> & CodeOptionsThemes<Themes> & CodeOptionsMeta;
398
+ interface CodeToHastOptionsCommon<Languages extends string = string> extends TransformerOptions, DecorationOptions, Pick<TokenizeWithThemeOptions, 'colorReplacements' | 'tokenizeMaxLineLength' | 'tokenizeTimeLimit' | 'grammarState' | 'grammarContextCode'> {
399
+ lang: StringLiteralUnion<Languages | SpecialLanguage>;
400
+ /**
401
+ * Merge whitespace tokens to saving extra `<span>`.
402
+ *
403
+ * When set to true, it will merge whitespace tokens with the next token.
404
+ * When set to false, it keep the output as-is.
405
+ * When set to `never`, it will force to separate leading and trailing spaces from tokens.
406
+ *
407
+ * @default true
408
+ */
409
+ mergeWhitespaces?: boolean | 'never';
410
+ /**
411
+ * The structure of the generated HAST and HTML.
412
+ *
413
+ * - `classic`: The classic structure with `<pre>` and `<code>` elements, each line wrapped with a `<span class="line">` element.
414
+ * - `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.
415
+ *
416
+ * @default 'classic'
417
+ */
418
+ structure?: 'classic' | 'inline';
419
+ }
420
+ interface CodeOptionsMeta {
421
+ /**
422
+ * Meta data passed to Shiki, usually used by plugin integrations to pass the code block header.
423
+ *
424
+ * Key values in meta will be serialized to the attributes of the root `<pre>` element.
425
+ *
426
+ * Keys starting with `_` will be ignored.
427
+ *
428
+ * A special key `__raw` key will be used to pass the raw code block header (if the integration supports it).
429
+ */
430
+ meta?: {
431
+ /**
432
+ * Raw string of the code block header.
433
+ */
434
+ __raw?: string;
435
+ [key: string]: any;
436
+ };
437
+ }
438
+ interface CodeToHastRenderOptionsCommon extends TransformerOptions, Omit<TokensResult, 'tokens'> {
439
+ lang?: string;
440
+ langId?: string;
441
+ }
442
+ type CodeToHastRenderOptions = CodeToHastRenderOptionsCommon & CodeToHastOptions;
443
+
444
+ interface CodeToTokensBaseOptions<Languages extends string = string, Themes extends string = string> extends TokenizeWithThemeOptions {
445
+ lang?: Languages | SpecialLanguage;
446
+ theme?: Themes | ThemeRegistrationAny | SpecialTheme;
447
+ }
448
+ type CodeToTokensOptions<Languages extends string = string, Themes extends string = string> = Omit<CodeToTokensBaseOptions<Languages, Themes>, 'theme'> & CodeOptionsThemes<Themes>;
449
+ interface CodeToTokensWithThemesOptions<Languages = string, Themes = string> {
450
+ lang?: Languages | SpecialLanguage;
451
+ /**
452
+ * A map of color names to themes.
453
+ *
454
+ * `light` and `dark` are required, and arbitrary color names can be added.
455
+ *
456
+ * @example
457
+ * ```ts
458
+ * themes: {
459
+ * light: 'vitesse-light',
460
+ * dark: 'vitesse-dark',
461
+ * soft: 'nord',
462
+ * // custom colors
463
+ * }
464
+ * ```
465
+ */
466
+ themes: Partial<Record<string, Themes | ThemeRegistrationAny | SpecialTheme>>;
467
+ }
468
+ interface ThemedTokenScopeExplanation {
469
+ scopeName: string;
470
+ themeMatches?: IRawThemeSetting[];
471
+ }
472
+ interface ThemedTokenExplanation {
473
+ content: string;
474
+ scopes: ThemedTokenScopeExplanation[];
475
+ }
476
+ /**
477
+ * A single token with color, and optionally with explanation.
478
+ *
479
+ * For example:
480
+ *
481
+ * ```json
482
+ * {
483
+ * "content": "shiki",
484
+ * "color": "#D8DEE9",
485
+ * "explanation": [
486
+ * {
487
+ * "content": "shiki",
488
+ * "scopes": [
489
+ * {
490
+ * "scopeName": "source.js",
491
+ * "themeMatches": []
492
+ * },
493
+ * {
494
+ * "scopeName": "meta.objectliteral.js",
495
+ * "themeMatches": []
496
+ * },
497
+ * {
498
+ * "scopeName": "meta.object.member.js",
499
+ * "themeMatches": []
500
+ * },
501
+ * {
502
+ * "scopeName": "meta.array.literal.js",
503
+ * "themeMatches": []
504
+ * },
505
+ * {
506
+ * "scopeName": "variable.other.object.js",
507
+ * "themeMatches": [
508
+ * {
509
+ * "name": "Variable",
510
+ * "scope": "variable.other",
511
+ * "settings": {
512
+ * "foreground": "#D8DEE9"
513
+ * }
514
+ * },
515
+ * {
516
+ * "name": "[JavaScript] Variable Other Object",
517
+ * "scope": "source.js variable.other.object",
518
+ * "settings": {
519
+ * "foreground": "#D8DEE9"
520
+ * }
521
+ * }
522
+ * ]
523
+ * }
524
+ * ]
525
+ * }
526
+ * ]
527
+ * }
528
+ * ```
529
+ */
530
+ interface ThemedToken extends TokenStyles, TokenBase {
531
+ }
532
+ interface TokenBase {
533
+ /**
534
+ * The content of the token
535
+ */
536
+ content: string;
537
+ /**
538
+ * The start offset of the token, relative to the input code. 0-indexed.
539
+ */
540
+ offset: number;
541
+ /**
542
+ * Explanation of
543
+ *
544
+ * - token text's matching scopes
545
+ * - reason that token text is given a color (one matching scope matches a rule (scope -> color) in the theme)
546
+ */
547
+ explanation?: ThemedTokenExplanation[];
548
+ }
549
+ interface TokenStyles {
550
+ /**
551
+ * 6 or 8 digit hex code representation of the token's color
552
+ */
553
+ color?: string;
554
+ /**
555
+ * 6 or 8 digit hex code representation of the token's background color
556
+ */
557
+ bgColor?: string;
558
+ /**
559
+ * Font style of token. Can be None/Italic/Bold/Underline
560
+ */
561
+ fontStyle?: FontStyle;
562
+ /**
563
+ * Override with custom inline style for HTML renderer.
564
+ * When specified, `color` and `fontStyle` will be ignored.
565
+ */
566
+ htmlStyle?: string;
567
+ }
568
+ interface ThemedTokenWithVariants extends TokenBase {
569
+ /**
570
+ * An object of color name to token styles
571
+ */
572
+ variants: Record<string, TokenStyles>;
573
+ }
574
+ interface TokenizeWithThemeOptions {
575
+ /**
576
+ * Include explanation of why a token is given a color.
577
+ *
578
+ * You can optionally pass `scopeName` to only include explanation for scopes,
579
+ * which is more performant than full explanation.
580
+ *
581
+ * @default false
582
+ */
583
+ includeExplanation?: boolean | 'scopeName';
584
+ /**
585
+ * A map of color names to new color values.
586
+ *
587
+ * The color key starts with '#' and should be lowercased.
588
+ *
589
+ * This will be merged with theme's `colorReplacements` if any.
590
+ */
591
+ colorReplacements?: Record<string, string | Record<string, string>>;
592
+ /**
593
+ * Lines above this length will not be tokenized for performance reasons.
594
+ *
595
+ * @default 0 (no limit)
596
+ */
597
+ tokenizeMaxLineLength?: number;
598
+ /**
599
+ * Time limit in milliseconds for tokenizing a single line.
600
+ *
601
+ * @default 500 (0.5s)
602
+ */
603
+ tokenizeTimeLimit?: number;
604
+ /**
605
+ * Represent the state of the grammar, allowing to continue tokenizing from a intermediate grammar state.
606
+ *
607
+ * You can get the grammar state from `getLastGrammarState`.
608
+ */
609
+ grammarState?: GrammarState;
610
+ /**
611
+ * The code context of the grammar.
612
+ * Consider it a prepended code to the input code, that only participate the grammar inference but not presented in the final output.
613
+ *
614
+ * This will be ignored if `grammarState` is provided.
615
+ */
616
+ grammarContextCode?: string;
617
+ }
618
+ /**
619
+ * Result of `codeToTokens`, an object with 2D array of tokens and meta info like background and foreground color.
620
+ */
621
+ interface TokensResult {
622
+ /**
623
+ * 2D array of tokens, first dimension is lines, second dimension is tokens in a line.
624
+ */
625
+ tokens: ThemedToken[][];
626
+ /**
627
+ * Foreground color of the code.
628
+ */
629
+ fg?: string;
630
+ /**
631
+ * Background color of the code.
632
+ */
633
+ bg?: string;
634
+ /**
635
+ * A string representation of themes applied to the token.
636
+ */
637
+ themeName?: string;
638
+ /**
639
+ * Custom style string to be applied to the root `<pre>` element.
640
+ * When specified, `fg` and `bg` will be ignored.
641
+ */
642
+ rootStyle?: string;
643
+ }
644
+ declare enum FontStyle {
645
+ NotSet = -1,
646
+ None = 0,
647
+ Italic = 1,
648
+ Bold = 2,
649
+ Underline = 4
650
+ }
651
+
10
652
  /**
11
653
  * Internal context of Shiki, core textmate logic
12
654
  */
@@ -15,10 +657,18 @@ interface ShikiInternal<BundledLangKeys extends string = never, BundledThemeKeys
15
657
  * Load a theme to the highlighter, so later it can be used synchronously.
16
658
  */
17
659
  loadTheme: (...themes: (ThemeInput | BundledThemeKeys | SpecialTheme)[]) => Promise<void>;
660
+ /**
661
+ * Load a theme registration synchronously.
662
+ */
663
+ loadThemeSync: (...themes: MaybeArray<ThemeRegistrationAny>[]) => void;
18
664
  /**
19
665
  * Load a language to the highlighter, so later it can be used synchronously.
20
666
  */
21
667
  loadLanguage: (...langs: (LanguageInput | BundledLangKeys | SpecialLanguage)[]) => Promise<void>;
668
+ /**
669
+ * Load a language registration synchronously.
670
+ */
671
+ loadLanguageSync: (...langs: MaybeArray<LanguageRegistration>[]) => void;
22
672
  /**
23
673
  * Get the registered theme object
24
674
  */
@@ -102,5 +752,13 @@ interface HighlighterGeneric<BundledLangKeys extends string, BundledThemeKeys ex
102
752
  * The fine-grained core Shiki highlighter instance.
103
753
  */
104
754
  type HighlighterCore = HighlighterGeneric<never, never>;
755
+ /**
756
+ * Options for creating a bundled highlighter.
757
+ */
758
+ interface CreatedBundledHighlighterOptions<BundledLangs extends string, BundledThemes extends string> {
759
+ langs: Record<BundledLangs, LanguageInput>;
760
+ themes: Record<BundledThemes, ThemeInput>;
761
+ engine: () => Awaitable<RegexEngine>;
762
+ }
105
763
 
106
- export { CodeToHastOptions, CodeToTokensBaseOptions, CodeToTokensOptions, CodeToTokensWithThemesOptions, type Grammar, GrammarState, type HighlighterCore, type HighlighterGeneric, LanguageInput, LanguageRegistration, ResolveBundleKey, type ShikiInternal, SpecialLanguage, SpecialTheme, ThemeInput, ThemeRegistrationAny, ThemeRegistrationResolved, ThemedToken, ThemedTokenWithVariants, TokensResult };
764
+ export { type AnsiLanguage, Awaitable, type BundledHighlighterOptions, type BundledLanguageInfo, type BundledThemeInfo, type CodeOptionsMeta, type CodeOptionsMultipleThemes, type CodeOptionsSingleTheme, type CodeOptionsThemes, type CodeToHastOptions, type CodeToHastOptionsCommon, type CodeToHastRenderOptions, type CodeToHastRenderOptionsCommon, type CodeToTokensBaseOptions, type CodeToTokensOptions, type CodeToTokensWithThemesOptions, type CreatedBundledHighlighterOptions, type DecorationItem, type DecorationOptions, type DecorationTransformType, type DynamicImportLanguageRegistration, type DynamicImportThemeRegistration, FontStyle, type Grammar, GrammarState, type HighlighterCore, type HighlighterCoreOptions, type HighlighterGeneric, type LanguageInput, type LanguageRegistration, LoadWasmOptions, MaybeArray, MaybeGetter, type Offset, type OffsetOrPosition, type PlainTextLanguage, type Position, IRawGrammar as RawGrammar, IRawTheme as RawTheme, IRawThemeSetting as RawThemeSetting, RegexEngine, type ResolveBundleKey, type ResolvedDecorationItem, type ResolvedPosition, type ShikiInternal, type ShikiTransformer, type ShikiTransformerContext, type ShikiTransformerContextCommon, type ShikiTransformerContextMeta, type ShikiTransformerContextSource, type SpecialLanguage, type SpecialTheme, StringLiteralUnion, type ThemeInput, type ThemeRegistration, type ThemeRegistrationAny, type ThemeRegistrationRaw, type ThemeRegistrationResolved, type ThemedToken, type ThemedTokenExplanation, type ThemedTokenScopeExplanation, type ThemedTokenWithVariants, type TokenBase, type TokenStyles, type TokenizeWithThemeOptions, type TokensResult, type TransformerOptions };