@shikijs/core 1.0.0-beta.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.
@@ -0,0 +1,1226 @@
1
+ import { L as LoadWasmOptions } from './chunk-index.mjs';
2
+
3
+ // ## Interfaces
4
+
5
+ /**
6
+ * Info associated with nodes by the ecosystem.
7
+ *
8
+ * This space is guaranteed to never be specified by unist or specifications
9
+ * implementing unist.
10
+ * But you can use it in utilities and plugins to store data.
11
+ *
12
+ * This type can be augmented to register custom data.
13
+ * For example:
14
+ *
15
+ * ```ts
16
+ * declare module 'unist' {
17
+ * interface Data {
18
+ * // `someNode.data.myId` is typed as `number | undefined`
19
+ * myId?: number | undefined
20
+ * }
21
+ * }
22
+ * ```
23
+ */
24
+ interface Data$1 {}
25
+
26
+ /**
27
+ * One place in a source file.
28
+ */
29
+ interface Point {
30
+ /**
31
+ * Line in a source file (1-indexed integer).
32
+ */
33
+ line: number;
34
+
35
+ /**
36
+ * Column in a source file (1-indexed integer).
37
+ */
38
+ column: number;
39
+ /**
40
+ * Character in a source file (0-indexed integer).
41
+ */
42
+ offset?: number | undefined;
43
+ }
44
+
45
+ /**
46
+ * Position of a node in a source document.
47
+ *
48
+ * A position is a range between two points.
49
+ */
50
+ interface Position {
51
+ /**
52
+ * Place of the first character of the parsed source region.
53
+ */
54
+ start: Point;
55
+
56
+ /**
57
+ * Place of the first character after the parsed source region.
58
+ */
59
+ end: Point;
60
+ }
61
+
62
+ /**
63
+ * Abstract unist node.
64
+ *
65
+ * The syntactic unit in unist syntax trees are called nodes.
66
+ *
67
+ * This interface is supposed to be extended.
68
+ * If you can use {@link Literal} or {@link Parent}, you should.
69
+ * But for example in markdown, a `thematicBreak` (`***`), is neither literal
70
+ * nor parent, but still a node.
71
+ */
72
+ interface Node$1 {
73
+ /**
74
+ * Node type.
75
+ */
76
+ type: string;
77
+
78
+ /**
79
+ * Info from the ecosystem.
80
+ */
81
+ data?: Data$1 | undefined;
82
+
83
+ /**
84
+ * Position of a node in a source document.
85
+ *
86
+ * Nodes that are generated (not in the original source document) must not
87
+ * have a position.
88
+ */
89
+ position?: Position | undefined;
90
+ }
91
+
92
+ // ## Interfaces
93
+
94
+ /**
95
+ * Info associated with hast nodes by the ecosystem.
96
+ *
97
+ * This space is guaranteed to never be specified by unist or hast.
98
+ * But you can use it in utilities and plugins to store data.
99
+ *
100
+ * This type can be augmented to register custom data.
101
+ * For example:
102
+ *
103
+ * ```ts
104
+ * declare module 'hast' {
105
+ * interface Data {
106
+ * // `someNode.data.myId` is typed as `number | undefined`
107
+ * myId?: number | undefined
108
+ * }
109
+ * }
110
+ * ```
111
+ */
112
+ interface Data extends Data$1 {}
113
+
114
+ /**
115
+ * Info associated with an element.
116
+ */
117
+ interface Properties {
118
+ [PropertyName: string]: boolean | number | string | null | undefined | Array<string | number>;
119
+ }
120
+
121
+ // ## Content maps
122
+
123
+ /**
124
+ * Union of registered hast nodes that can occur in {@link Element}.
125
+ *
126
+ * To register mote custom hast nodes, add them to {@link ElementContentMap}.
127
+ * They will be automatically added here.
128
+ */
129
+ type ElementContent = ElementContentMap[keyof ElementContentMap];
130
+
131
+ /**
132
+ * Registry of all hast nodes that can occur as children of {@link Element}.
133
+ *
134
+ * For a union of all {@link Element} children, see {@link ElementContent}.
135
+ */
136
+ interface ElementContentMap {
137
+ comment: Comment;
138
+ element: Element;
139
+ text: Text;
140
+ }
141
+
142
+ /**
143
+ * Union of registered hast nodes that can occur in {@link Root}.
144
+ *
145
+ * To register custom hast nodes, add them to {@link RootContentMap}.
146
+ * They will be automatically added here.
147
+ */
148
+ type RootContent = RootContentMap[keyof RootContentMap];
149
+
150
+ /**
151
+ * Registry of all hast nodes that can occur as children of {@link Root}.
152
+ *
153
+ * > 👉 **Note**: {@link Root} does not need to be an entire document.
154
+ * > it can also be a fragment.
155
+ *
156
+ * For a union of all {@link Root} children, see {@link RootContent}.
157
+ */
158
+ interface RootContentMap {
159
+ comment: Comment;
160
+ doctype: Doctype;
161
+ element: Element;
162
+ text: Text;
163
+ }
164
+
165
+ /**
166
+ * Union of registered hast nodes.
167
+ *
168
+ * To register custom hast nodes, add them to {@link RootContentMap} and other
169
+ * places where relevant.
170
+ * They will be automatically added here.
171
+ */
172
+ type Nodes = Root | RootContent;
173
+
174
+ // ## Abstract nodes
175
+
176
+ /**
177
+ * Abstract hast node.
178
+ *
179
+ * This interface is supposed to be extended.
180
+ * If you can use {@link Literal} or {@link Parent}, you should.
181
+ * But for example in HTML, a `Doctype` is neither literal nor parent, but
182
+ * still a node.
183
+ *
184
+ * To register custom hast nodes, add them to {@link RootContentMap} and other
185
+ * places where relevant (such as {@link ElementContentMap}).
186
+ *
187
+ * For a union of all registered hast nodes, see {@link Nodes}.
188
+ */
189
+ interface Node extends Node$1 {
190
+ /**
191
+ * Info from the ecosystem.
192
+ */
193
+ data?: Data | undefined;
194
+ }
195
+
196
+ /**
197
+ * Abstract hast node that contains the smallest possible value.
198
+ *
199
+ * This interface is supposed to be extended if you make custom hast nodes.
200
+ *
201
+ * For a union of all registered hast literals, see {@link Literals}.
202
+ */
203
+ interface Literal extends Node {
204
+ /**
205
+ * Plain-text value.
206
+ */
207
+ value: string;
208
+ }
209
+
210
+ /**
211
+ * Abstract hast node that contains other hast nodes (*children*).
212
+ *
213
+ * This interface is supposed to be extended if you make custom hast nodes.
214
+ *
215
+ * For a union of all registered hast parents, see {@link Parents}.
216
+ */
217
+ interface Parent extends Node {
218
+ /**
219
+ * List of children.
220
+ */
221
+ children: RootContent[];
222
+ }
223
+
224
+ // ## Concrete nodes
225
+
226
+ /**
227
+ * HTML comment.
228
+ */
229
+ interface Comment extends Literal {
230
+ /**
231
+ * Node type of HTML comments in hast.
232
+ */
233
+ type: "comment";
234
+ /**
235
+ * Data associated with the comment.
236
+ */
237
+ data?: CommentData | undefined;
238
+ }
239
+
240
+ /**
241
+ * Info associated with hast comments by the ecosystem.
242
+ */
243
+ interface CommentData extends Data {}
244
+
245
+ /**
246
+ * HTML document type.
247
+ */
248
+ interface Doctype extends Node$1 {
249
+ /**
250
+ * Node type of HTML document types in hast.
251
+ */
252
+ type: "doctype";
253
+ /**
254
+ * Data associated with the doctype.
255
+ */
256
+ data?: DoctypeData | undefined;
257
+ }
258
+
259
+ /**
260
+ * Info associated with hast doctypes by the ecosystem.
261
+ */
262
+ interface DoctypeData extends Data {}
263
+
264
+ /**
265
+ * HTML element.
266
+ */
267
+ interface Element extends Parent {
268
+ /**
269
+ * Node type of elements.
270
+ */
271
+ type: "element";
272
+ /**
273
+ * Tag name (such as `'body'`) of the element.
274
+ */
275
+ tagName: string;
276
+ /**
277
+ * Info associated with the element.
278
+ */
279
+ properties: Properties;
280
+ /**
281
+ * Children of element.
282
+ */
283
+ children: ElementContent[];
284
+ /**
285
+ * When the `tagName` field is `'template'`, a `content` field can be
286
+ * present.
287
+ */
288
+ content?: Root | undefined;
289
+ /**
290
+ * Data associated with the element.
291
+ */
292
+ data?: ElementData | undefined;
293
+ }
294
+
295
+ /**
296
+ * Info associated with hast elements by the ecosystem.
297
+ */
298
+ interface ElementData extends Data {}
299
+
300
+ /**
301
+ * Document fragment or a whole document.
302
+ *
303
+ * Should be used as the root of a tree and must not be used as a child.
304
+ *
305
+ * Can also be used as the value for the content field on a `'template'` element.
306
+ */
307
+ interface Root extends Parent {
308
+ /**
309
+ * Node type of hast root.
310
+ */
311
+ type: "root";
312
+ /**
313
+ * Children of root.
314
+ */
315
+ children: RootContent[];
316
+ /**
317
+ * Data associated with the hast root.
318
+ */
319
+ data?: RootData | undefined;
320
+ }
321
+
322
+ /**
323
+ * Info associated with hast root nodes by the ecosystem.
324
+ */
325
+ interface RootData extends Data {}
326
+
327
+ /**
328
+ * HTML character data (plain text).
329
+ */
330
+ interface Text extends Literal {
331
+ /**
332
+ * Node type of HTML character data (plain text) in hast.
333
+ */
334
+ type: "text";
335
+ /**
336
+ * Data associated with the text.
337
+ */
338
+ data?: TextData | undefined;
339
+ }
340
+
341
+ /**
342
+ * Info associated with hast texts by the ecosystem.
343
+ */
344
+ interface TextData extends Data {}
345
+
346
+ /**
347
+ * A union of given const enum values.
348
+ */
349
+ type OrMask<T extends number> = number;
350
+
351
+ interface IOnigLib {
352
+ createOnigScanner(sources: string[]): OnigScanner;
353
+ createOnigString(str: string): OnigString;
354
+ }
355
+ interface IOnigCaptureIndex {
356
+ start: number;
357
+ end: number;
358
+ length: number;
359
+ }
360
+ interface IOnigMatch {
361
+ index: number;
362
+ captureIndices: IOnigCaptureIndex[];
363
+ }
364
+ declare const enum FindOption {
365
+ None = 0,
366
+ /**
367
+ * equivalent of ONIG_OPTION_NOT_BEGIN_STRING: (str) isn't considered as begin of string (* fail \A)
368
+ */
369
+ NotBeginString = 1,
370
+ /**
371
+ * equivalent of ONIG_OPTION_NOT_END_STRING: (end) isn't considered as end of string (* fail \z, \Z)
372
+ */
373
+ NotEndString = 2,
374
+ /**
375
+ * equivalent of ONIG_OPTION_NOT_BEGIN_POSITION: (start) isn't considered as start position of search (* fail \G)
376
+ */
377
+ NotBeginPosition = 4,
378
+ /**
379
+ * used for debugging purposes.
380
+ */
381
+ DebugCall = 8
382
+ }
383
+ interface OnigScanner {
384
+ findNextMatchSync(string: string | OnigString, startPosition: number, options: OrMask<FindOption>): IOnigMatch | null;
385
+ dispose?(): void;
386
+ }
387
+ interface OnigString {
388
+ readonly content: string;
389
+ dispose?(): void;
390
+ }
391
+
392
+ declare const ruleIdSymbol: unique symbol;
393
+ type RuleId = {
394
+ __brand: typeof ruleIdSymbol;
395
+ };
396
+
397
+ /**
398
+ * Identifiers with a binary dot operator.
399
+ * Examples: `baz` or `foo.bar`
400
+ */
401
+ type ScopeName = string;
402
+ /**
403
+ * An expression language of ScopePathStr with a binary comma (to indicate alternatives) operator.
404
+ * Examples: `foo.bar boo.baz,quick quack`
405
+ */
406
+ type ScopePattern = string;
407
+ /**
408
+ * A TextMate theme.
409
+ */
410
+ interface IRawTheme {
411
+ readonly name?: string;
412
+ readonly settings: IRawThemeSetting[];
413
+ }
414
+ /**
415
+ * A single theme setting.
416
+ */
417
+ interface IRawThemeSetting {
418
+ readonly name?: string;
419
+ readonly scope?: ScopePattern | ScopePattern[];
420
+ readonly settings: {
421
+ readonly fontStyle?: string;
422
+ readonly foreground?: string;
423
+ readonly background?: string;
424
+ };
425
+ }
426
+
427
+ interface IRawGrammar extends ILocatable {
428
+ repository: IRawRepository;
429
+ readonly scopeName: ScopeName;
430
+ readonly patterns: IRawRule[];
431
+ readonly injections?: {
432
+ [expression: string]: IRawRule;
433
+ };
434
+ readonly injectionSelector?: string;
435
+ readonly fileTypes?: string[];
436
+ readonly name?: string;
437
+ readonly firstLineMatch?: string;
438
+ }
439
+ /**
440
+ * Allowed values:
441
+ * * Scope Name, e.g. `source.ts`
442
+ * * Top level scope reference, e.g. `source.ts#entity.name.class`
443
+ * * Relative scope reference, e.g. `#entity.name.class`
444
+ * * self, e.g. `$self`
445
+ * * base, e.g. `$base`
446
+ */
447
+ type IncludeString = string;
448
+ type RegExpString = string;
449
+ interface IRawRepositoryMap {
450
+ [name: string]: IRawRule;
451
+ $self: IRawRule;
452
+ $base: IRawRule;
453
+ }
454
+ type IRawRepository = IRawRepositoryMap & ILocatable;
455
+ interface IRawRule extends ILocatable {
456
+ id?: RuleId;
457
+ readonly include?: IncludeString;
458
+ readonly name?: ScopeName;
459
+ readonly contentName?: ScopeName;
460
+ readonly match?: RegExpString;
461
+ readonly captures?: IRawCaptures;
462
+ readonly begin?: RegExpString;
463
+ readonly beginCaptures?: IRawCaptures;
464
+ readonly end?: RegExpString;
465
+ readonly endCaptures?: IRawCaptures;
466
+ readonly while?: RegExpString;
467
+ readonly whileCaptures?: IRawCaptures;
468
+ readonly patterns?: IRawRule[];
469
+ readonly repository?: IRawRepository;
470
+ readonly applyEndPatternLast?: boolean;
471
+ }
472
+ type IRawCaptures = IRawCapturesMap & ILocatable;
473
+ interface IRawCapturesMap {
474
+ [captureId: string]: IRawRule;
475
+ }
476
+ interface ILocation {
477
+ readonly filename: string;
478
+ readonly line: number;
479
+ readonly char: number;
480
+ }
481
+ interface ILocatable {
482
+ readonly $vscodeTextmateLocation?: ILocation;
483
+ }
484
+
485
+ declare const enum StandardTokenType {
486
+ Other = 0,
487
+ Comment = 1,
488
+ String = 2,
489
+ RegEx = 3
490
+ }
491
+
492
+ /**
493
+ * A registry helper that can locate grammar file paths given scope names.
494
+ */
495
+ interface RegistryOptions {
496
+ onigLib: Promise<IOnigLib>;
497
+ theme?: IRawTheme;
498
+ colorMap?: string[];
499
+ loadGrammar(scopeName: ScopeName): Promise<IRawGrammar | undefined | null>;
500
+ getInjections?(scopeName: ScopeName): ScopeName[] | undefined;
501
+ }
502
+ /**
503
+ * A map from scope name to a language id. Please do not use language id 0.
504
+ */
505
+ interface IEmbeddedLanguagesMap {
506
+ [scopeName: string]: number;
507
+ }
508
+ /**
509
+ * A map from selectors to token types.
510
+ */
511
+ interface ITokenTypeMap {
512
+ [selector: string]: StandardTokenType;
513
+ }
514
+ interface IGrammarConfiguration {
515
+ embeddedLanguages?: IEmbeddedLanguagesMap;
516
+ tokenTypes?: ITokenTypeMap;
517
+ balancedBracketSelectors?: string[];
518
+ unbalancedBracketSelectors?: string[];
519
+ }
520
+ /**
521
+ * The registry that will hold all grammars.
522
+ */
523
+ declare class Registry {
524
+ private readonly _options;
525
+ private readonly _syncRegistry;
526
+ private readonly _ensureGrammarCache;
527
+ constructor(options: RegistryOptions);
528
+ dispose(): void;
529
+ /**
530
+ * Change the theme. Once called, no previous `ruleStack` should be used anymore.
531
+ */
532
+ setTheme(theme: IRawTheme, colorMap?: string[]): void;
533
+ /**
534
+ * Returns a lookup array for color ids.
535
+ */
536
+ getColorMap(): string[];
537
+ /**
538
+ * Load the grammar for `scopeName` and all referenced included grammars asynchronously.
539
+ * Please do not use language id 0.
540
+ */
541
+ loadGrammarWithEmbeddedLanguages(initialScopeName: ScopeName, initialLanguage: number, embeddedLanguages: IEmbeddedLanguagesMap): Promise<IGrammar | null>;
542
+ /**
543
+ * Load the grammar for `scopeName` and all referenced included grammars asynchronously.
544
+ * Please do not use language id 0.
545
+ */
546
+ loadGrammarWithConfiguration(initialScopeName: ScopeName, initialLanguage: number, configuration: IGrammarConfiguration): Promise<IGrammar | null>;
547
+ /**
548
+ * Load the grammar for `scopeName` and all referenced included grammars asynchronously.
549
+ */
550
+ loadGrammar(initialScopeName: ScopeName): Promise<IGrammar | null>;
551
+ private _loadGrammar;
552
+ private _loadSingleGrammar;
553
+ private _doLoadSingleGrammar;
554
+ /**
555
+ * Adds a rawGrammar.
556
+ */
557
+ addGrammar(rawGrammar: IRawGrammar, injections?: string[], initialLanguage?: number, embeddedLanguages?: IEmbeddedLanguagesMap | null): Promise<IGrammar>;
558
+ /**
559
+ * Get the grammar for `scopeName`. The grammar must first be created via `loadGrammar` or `addGrammar`.
560
+ */
561
+ private _grammarForScopeName;
562
+ }
563
+ /**
564
+ * A grammar
565
+ */
566
+ interface IGrammar {
567
+ /**
568
+ * Tokenize `lineText` using previous line state `prevState`.
569
+ */
570
+ tokenizeLine(lineText: string, prevState: StateStack | null, timeLimit?: number): ITokenizeLineResult;
571
+ /**
572
+ * Tokenize `lineText` using previous line state `prevState`.
573
+ * The result contains the tokens in binary format, resolved with the following information:
574
+ * - language
575
+ * - token type (regex, string, comment, other)
576
+ * - font style
577
+ * - foreground color
578
+ * - background color
579
+ * e.g. for getting the languageId: `(metadata & MetadataConsts.LANGUAGEID_MASK) >>> MetadataConsts.LANGUAGEID_OFFSET`
580
+ */
581
+ tokenizeLine2(lineText: string, prevState: StateStack | null, timeLimit?: number): ITokenizeLineResult2;
582
+ }
583
+ interface ITokenizeLineResult {
584
+ readonly tokens: IToken[];
585
+ /**
586
+ * The `prevState` to be passed on to the next line tokenization.
587
+ */
588
+ readonly ruleStack: StateStack;
589
+ /**
590
+ * Did tokenization stop early due to reaching the time limit.
591
+ */
592
+ readonly stoppedEarly: boolean;
593
+ }
594
+ interface ITokenizeLineResult2 {
595
+ /**
596
+ * The tokens in binary format. Each token occupies two array indices. For token i:
597
+ * - at offset 2*i => startIndex
598
+ * - at offset 2*i + 1 => metadata
599
+ *
600
+ */
601
+ readonly tokens: Uint32Array;
602
+ /**
603
+ * The `prevState` to be passed on to the next line tokenization.
604
+ */
605
+ readonly ruleStack: StateStack;
606
+ /**
607
+ * Did tokenization stop early due to reaching the time limit.
608
+ */
609
+ readonly stoppedEarly: boolean;
610
+ }
611
+ interface IToken {
612
+ startIndex: number;
613
+ readonly endIndex: number;
614
+ readonly scopes: string[];
615
+ }
616
+ /**
617
+ * **IMPORTANT** - Immutable!
618
+ */
619
+ interface StateStack {
620
+ _stackElementBrand: void;
621
+ readonly depth: number;
622
+ clone(): StateStack;
623
+ equals(other: StateStack): boolean;
624
+ }
625
+ declare const INITIAL: StateStack;
626
+
627
+ declare enum FontStyle {
628
+ NotSet = -1,
629
+ None = 0,
630
+ Italic = 1,
631
+ Bold = 2,
632
+ Underline = 4
633
+ }
634
+ type PlainTextLanguage = 'text' | 'plaintext' | 'txt';
635
+ type AnsiLanguage = 'ansi';
636
+ type SpecialLanguage = PlainTextLanguage | AnsiLanguage;
637
+ type SpecialTheme = 'none';
638
+ type Awaitable<T> = T | Promise<T>;
639
+ type MaybeGetter<T> = Awaitable<MaybeModule<T>> | (() => Awaitable<MaybeModule<T>>);
640
+ type MaybeModule<T> = T | {
641
+ default: T;
642
+ };
643
+ type MaybeArray<T> = T | T[];
644
+ type RequireKeys<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
645
+ type ThemeInput = MaybeGetter<ThemeRegistrationAny>;
646
+ type LanguageInput = MaybeGetter<MaybeArray<LanguageRegistration>>;
647
+ interface Nothing {
648
+ }
649
+ /**
650
+ * type StringLiteralUnion<'foo'> = 'foo' | string
651
+ * This has auto completion whereas `'foo' | string` doesn't
652
+ * Adapted from https://github.com/microsoft/TypeScript/issues/29729
653
+ */
654
+ type StringLiteralUnion<T extends U, U = string> = T | (U & Nothing);
655
+ type ResolveBundleKey<T extends string> = [T] extends [never] ? string : T;
656
+ interface ShikiInternal {
657
+ setTheme(name: string | ThemeRegistrationAny): {
658
+ theme: ThemeRegistrationResolved;
659
+ colorMap: string[];
660
+ };
661
+ getTheme(name: string | ThemeRegistrationAny): ThemeRegistrationResolved;
662
+ getLangGrammar(name: string): IGrammar;
663
+ getLoadedThemes(): string[];
664
+ getLoadedLanguages(): string[];
665
+ loadLanguage(...langs: LanguageInput[]): Promise<void>;
666
+ loadTheme(...themes: ThemeInput[]): Promise<void>;
667
+ getAlias(): Record<string, string>;
668
+ updateAlias(alias: Record<string, string>): void;
669
+ }
670
+ /**
671
+ * Generic instance interface of Shiki
672
+ */
673
+ interface HighlighterGeneric<BundledLangKeys extends string, BundledThemeKeys extends string> {
674
+ /**
675
+ * Get highlighted code in HTML string
676
+ */
677
+ codeToHtml(code: string, options: CodeToHastOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>): string;
678
+ /**
679
+ * Get highlighted code in HAST.
680
+ * @see https://github.com/syntax-tree/hast
681
+ */
682
+ codeToHast(code: string, options: CodeToHastOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>): Root;
683
+ /**
684
+ * Get highlighted code in tokens.
685
+ * @returns A 2D array of tokens, first dimension is lines, second dimension is tokens in a line.
686
+ */
687
+ codeToThemedTokens(code: string, options: CodeToThemedTokensOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>): ThemedToken[][];
688
+ /**
689
+ * Get highlighted code in tokens with multiple themes.
690
+ *
691
+ * Different from `codeToThemedTokens`, each token will have a `variants` property consisting of an object of color name to token styles.
692
+ *
693
+ * @returns A 2D array of tokens, first dimension is lines, second dimension is tokens in a line.
694
+ */
695
+ codeToTokensWithThemes(code: string, options: CodeToTokensWithThemesOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>): ThemedTokenWithVariants[][];
696
+ /**
697
+ * Load a theme to the highlighter, so later it can be used synchronously.
698
+ */
699
+ loadTheme(...themes: (ThemeInput | BundledThemeKeys | SpecialTheme)[]): Promise<void>;
700
+ /**
701
+ * Load a language to the highlighter, so later it can be used synchronously.
702
+ */
703
+ loadLanguage(...langs: (LanguageInput | BundledLangKeys | SpecialLanguage)[]): Promise<void>;
704
+ /**
705
+ * Get the registered theme object
706
+ */
707
+ getTheme(name: string | ThemeRegistrationAny): ThemeRegistrationResolved;
708
+ /**
709
+ * Get the registered language object
710
+ */
711
+ getLangGrammar(name: string | LanguageRegistration): IGrammar;
712
+ /**
713
+ * Set the current theme and get the resolved theme object and color map.
714
+ * @internal
715
+ */
716
+ setTheme: ShikiInternal['setTheme'];
717
+ /**
718
+ * Get the names of loaded languages
719
+ *
720
+ * Special-handled languages like `text`, `plain` and `ansi` are not included.
721
+ */
722
+ getLoadedLanguages(): string[];
723
+ /**
724
+ * Get the names of loaded themes
725
+ *
726
+ * Special-handled themes like `none` are not included.
727
+ */
728
+ getLoadedThemes(): string[];
729
+ /**
730
+ * Get internal context object
731
+ * @internal
732
+ * @deprecated
733
+ */
734
+ getInternalContext(): ShikiInternal;
735
+ }
736
+ interface HighlighterCoreOptions {
737
+ /**
738
+ * Theme names, or theme registration objects to be loaded upfront.
739
+ */
740
+ themes?: ThemeInput[];
741
+ /**
742
+ * Language names, or language registration objects to be loaded upfront.
743
+ */
744
+ langs?: LanguageInput[];
745
+ /**
746
+ * Alias of languages
747
+ * @example { 'my-lang': 'javascript' }
748
+ */
749
+ langAlias?: Record<string, string>;
750
+ /**
751
+ * Load wasm file from a custom path or using a custom function.
752
+ */
753
+ loadWasm?: LoadWasmOptions;
754
+ }
755
+ interface BundledHighlighterOptions<L extends string, T extends string> {
756
+ /**
757
+ * Theme registation
758
+ *
759
+ * @default []
760
+ */
761
+ themes?: (ThemeInput | StringLiteralUnion<T>)[];
762
+ /**
763
+ * Language registation
764
+ *
765
+ * @default Object.keys(bundledThemes)
766
+ */
767
+ langs?: (LanguageInput | StringLiteralUnion<L> | SpecialLanguage)[];
768
+ /**
769
+ * Alias of languages
770
+ * @example { 'my-lang': 'javascript' }
771
+ */
772
+ langAlias?: Record<string, StringLiteralUnion<L>>;
773
+ }
774
+ interface LanguageRegistration extends IRawGrammar {
775
+ name: string;
776
+ scopeName: string;
777
+ displayName?: string;
778
+ aliases?: string[];
779
+ /**
780
+ * A list of languages the current language embeds.
781
+ * If manually specifying languages to load, make sure to load the embedded
782
+ * languages for each parent language.
783
+ */
784
+ embeddedLangs?: string[];
785
+ /**
786
+ * A list of languages that embed the current language.
787
+ * Unlike `embeddedLangs`, the embedded languages will not be loaded automatically.
788
+ */
789
+ embeddedLangsLazy?: string[];
790
+ balancedBracketSelectors?: string[];
791
+ unbalancedBracketSelectors?: string[];
792
+ foldingStopMarker?: string;
793
+ foldingStartMarker?: string;
794
+ /**
795
+ * Inject this language to other scopes.
796
+ * Same as `injectTo` in VSCode's `contributes.grammars`.
797
+ *
798
+ * @see https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide#injection-grammars
799
+ */
800
+ injectTo?: string[];
801
+ }
802
+ interface CodeToThemedTokensOptions<Languages = string, Themes = string> extends TokenizeWithThemeOptions {
803
+ lang?: Languages | SpecialLanguage;
804
+ theme?: Themes | ThemeRegistrationAny | SpecialTheme;
805
+ }
806
+ interface CodeToHastOptionsCommon<Languages extends string = string> extends TransformerOptions, Pick<TokenizeWithThemeOptions, 'colorReplacements'> {
807
+ lang: StringLiteralUnion<Languages | SpecialLanguage>;
808
+ /**
809
+ * Merge whitespace tokens to saving extra `<span>`.
810
+ *
811
+ * When set to true, it will merge whitespace tokens with the next token.
812
+ * When set to false, it keep the output as-is.
813
+ * When set to `never`, it will force to separate leading and trailing spaces from tokens.
814
+ *
815
+ * @default true
816
+ */
817
+ mergeWhitespaces?: boolean | 'never';
818
+ }
819
+ interface CodeToTokensWithThemesOptions<Languages = string, Themes = string> {
820
+ lang?: Languages | SpecialLanguage;
821
+ /**
822
+ * A map of color names to themes.
823
+ *
824
+ * `light` and `dark` are required, and arbitrary color names can be added.
825
+ *
826
+ * @example
827
+ * ```ts
828
+ * themes: {
829
+ * light: 'vitesse-light',
830
+ * dark: 'vitesse-dark',
831
+ * soft: 'nord',
832
+ * // custom colors
833
+ * }
834
+ * ```
835
+ */
836
+ themes: Partial<Record<string, Themes | ThemeRegistrationAny | SpecialTheme>>;
837
+ }
838
+ interface CodeOptionsSingleTheme<Themes extends string = string> {
839
+ theme: ThemeRegistrationAny | StringLiteralUnion<Themes>;
840
+ }
841
+ interface CodeOptionsMultipleThemes<Themes extends string = string> {
842
+ /**
843
+ * A map of color names to themes.
844
+ * This allows you to specify multiple themes for the generated code.
845
+ *
846
+ * ```ts
847
+ * highlighter.codeToHtml(code, {
848
+ * lang: 'js',
849
+ * themes: {
850
+ * light: 'vitesse-light',
851
+ * dark: 'vitesse-dark',
852
+ * }
853
+ * })
854
+ * ```
855
+ *
856
+ * Will generate:
857
+ *
858
+ * ```html
859
+ * <span style="color:#111;--shiki-dark:#fff;">code</span>
860
+ * ```
861
+ *
862
+ * @see https://github.com/shikijs/shiki#lightdark-dual-themes
863
+ */
864
+ themes: Partial<Record<string, ThemeRegistrationAny | StringLiteralUnion<Themes>>>;
865
+ /**
866
+ * The default theme applied to the code (via inline `color` style).
867
+ * The rest of the themes are applied via CSS variables, and toggled by CSS overrides.
868
+ *
869
+ * For example, if `defaultColor` is `light`, then `light` theme is applied to the code,
870
+ * and the `dark` theme and other custom themes are applied via CSS variables:
871
+ *
872
+ * ```html
873
+ * <span style="color:#{light};--shiki-dark:#{dark};--shiki-custom:#{custom};">code</span>
874
+ * ```
875
+ *
876
+ * When set to `false`, no default styles will be applied, and totally up to users to apply the styles:
877
+ *
878
+ * ```html
879
+ * <span style="--shiki-light:#{light};--shiki-dark:#{dark};--shiki-custom:#{custom};">code</span>
880
+ * ```
881
+ *
882
+ *
883
+ * @default 'light'
884
+ */
885
+ defaultColor?: StringLiteralUnion<'light' | 'dark'> | false;
886
+ /**
887
+ * Prefix of CSS variables used to store the color of the other theme.
888
+ *
889
+ * @default '--shiki-'
890
+ */
891
+ cssVariablePrefix?: string;
892
+ }
893
+ type CodeOptionsThemes<Themes extends string = string> = CodeOptionsSingleTheme<Themes> | CodeOptionsMultipleThemes<Themes>;
894
+ interface CodeOptionsMeta {
895
+ /**
896
+ * Meta data passed to Shiki, usually used by plugin integrations to pass the code block header.
897
+ *
898
+ * Key values in meta will be serialized to the attributes of the root `<pre>` element.
899
+ *
900
+ * Keys starting with `_` will be ignored.
901
+ *
902
+ * A special key `__raw` key will be used to pass the raw code block header (if the integration supports it).
903
+ */
904
+ meta?: {
905
+ /**
906
+ * Raw string of the code block header.
907
+ */
908
+ __raw?: string;
909
+ [key: string]: any;
910
+ };
911
+ }
912
+ interface TransformerOptions {
913
+ /**
914
+ * Transformers for the Shiki pipeline.
915
+ */
916
+ transformers?: ShikiTransformer[];
917
+ }
918
+ type CodeToHastOptions<Languages extends string = string, Themes extends string = string> = CodeToHastOptionsCommon<Languages> & CodeOptionsThemes<Themes> & CodeOptionsMeta;
919
+ interface ThemeRegistrationRaw extends IRawTheme, Partial<Omit<ThemeRegistration, 'name' | 'settings'>> {
920
+ }
921
+ interface ThemeRegistration extends Partial<ThemeRegistrationResolved> {
922
+ }
923
+ interface ThemeRegistrationResolved extends IRawTheme {
924
+ /**
925
+ * Theme name
926
+ */
927
+ name: string;
928
+ /**
929
+ * Display name
930
+ *
931
+ * @field shiki custom property
932
+ */
933
+ displayName?: string;
934
+ /**
935
+ * Light/dark theme
936
+ *
937
+ * @field shiki custom property
938
+ */
939
+ type: 'light' | 'dark';
940
+ /**
941
+ * Token rules
942
+ */
943
+ settings: IRawThemeSetting[];
944
+ /**
945
+ * Same as `settings`, will use as fallback if `settings` is not present.
946
+ */
947
+ tokenColors?: IRawThemeSetting[];
948
+ /**
949
+ * Default foreground color
950
+ *
951
+ * @field shiki custom property
952
+ */
953
+ fg: string;
954
+ /**
955
+ * Background color
956
+ *
957
+ * @field shiki custom property
958
+ */
959
+ bg: string;
960
+ /**
961
+ * A map of color names to new color values.
962
+ *
963
+ * The color key starts with '#' and should be lowercased.
964
+ *
965
+ * @field shiki custom property
966
+ */
967
+ colorReplacements?: Record<string, string>;
968
+ /**
969
+ * Color map of VS Code options
970
+ *
971
+ * Will be used by shiki on `lang: 'ansi'` to find ANSI colors, and to find the default foreground/background colors.
972
+ */
973
+ colors?: Record<string, string>;
974
+ /**
975
+ * JSON schema path
976
+ *
977
+ * @field not used by shiki
978
+ */
979
+ $schema?: string;
980
+ /**
981
+ * Enable semantic highlighting
982
+ *
983
+ * @field not used by shiki
984
+ */
985
+ semanticHighlighting?: boolean;
986
+ /**
987
+ * Tokens for semantic highlighting
988
+ *
989
+ * @field not used by shiki
990
+ */
991
+ semanticTokenColors?: Record<string, string>;
992
+ }
993
+ type ThemeRegistrationAny = ThemeRegistrationRaw | ThemeRegistration | ThemeRegistrationResolved;
994
+ interface ShikiTransformerContextMeta {
995
+ }
996
+ /**
997
+ * Common transformer context for all transformers hooks
998
+ */
999
+ interface ShikiTransformerContextCommon {
1000
+ meta: ShikiTransformerContextMeta;
1001
+ options: CodeToHastOptions;
1002
+ codeToHast: (code: string, options: CodeToHastOptions) => Root;
1003
+ }
1004
+ /**
1005
+ * Transformer context for HAST related hooks
1006
+ */
1007
+ interface ShikiTransformerContext extends ShikiTransformerContextCommon {
1008
+ readonly tokens: ThemedToken[][];
1009
+ readonly root: Root;
1010
+ readonly pre: Element;
1011
+ readonly code: Element;
1012
+ readonly lines: Element[];
1013
+ }
1014
+ interface ShikiTransformer {
1015
+ /**
1016
+ * Name of the transformer
1017
+ */
1018
+ name?: string;
1019
+ /**
1020
+ * Transform the raw input code before passing to the highlighter.
1021
+ */
1022
+ preprocess?(this: ShikiTransformerContextCommon, code: string, options: CodeToHastOptions): string | void;
1023
+ /**
1024
+ * Transform the full tokens list before converting to HAST.
1025
+ * Return a new tokens list will replace the original one.
1026
+ */
1027
+ tokens?(this: ShikiTransformerContextCommon, tokens: ThemedToken[][]): ThemedToken[][] | void;
1028
+ /**
1029
+ * Transform the entire generated HAST tree. Return a new Node will replace the original one.
1030
+ */
1031
+ root?(this: ShikiTransformerContext, hast: Root): Root | void;
1032
+ /**
1033
+ * Transform the `<pre>` element. Return a new Node will replace the original one.
1034
+ */
1035
+ pre?(this: ShikiTransformerContext, hast: Element): Element | void;
1036
+ /**
1037
+ * Transform the `<code>` element. Return a new Node will replace the original one.
1038
+ */
1039
+ code?(this: ShikiTransformerContext, hast: Element): Element | void;
1040
+ /**
1041
+ * Transform each line `<span class="line">` element.
1042
+ *
1043
+ * @param hast
1044
+ * @param line 1-based line number
1045
+ */
1046
+ line?(this: ShikiTransformerContext, hast: Element, line: number): Element | void;
1047
+ /**
1048
+ * Transform each token `<span>` element.
1049
+ */
1050
+ span?(this: ShikiTransformerContext, hast: Element, line: number, col: number, lineElement: Element): Element | void;
1051
+ /**
1052
+ * Transform the generated HTML string before returning.
1053
+ * This hook will only be called with `codeToHtml`.
1054
+ */
1055
+ postprocess?(this: ShikiTransformerContextCommon, html: string, options: CodeToHastOptions): string | void;
1056
+ /**
1057
+ * @deprecated Use `span` instead
1058
+ */
1059
+ token?(this: ShikiTransformerContext, hast: Element, line: number, col: number, lineElement: Element): Element | void;
1060
+ }
1061
+ interface HtmlRendererOptionsCommon extends TransformerOptions {
1062
+ lang?: string;
1063
+ langId?: string;
1064
+ fg?: string;
1065
+ bg?: string;
1066
+ themeName?: string;
1067
+ /**
1068
+ * Custom style string to be applied to the root `<pre>` element.
1069
+ * When specified, `fg` and `bg` will be ignored.
1070
+ */
1071
+ rootStyle?: string;
1072
+ }
1073
+ type HtmlRendererOptions = HtmlRendererOptionsCommon & CodeToHastOptions;
1074
+ interface ThemedTokenScopeExplanation {
1075
+ scopeName: string;
1076
+ themeMatches: any[];
1077
+ }
1078
+ interface ThemedTokenExplanation {
1079
+ content: string;
1080
+ scopes: ThemedTokenScopeExplanation[];
1081
+ }
1082
+ /**
1083
+ * A single token with color, and optionally with explanation.
1084
+ *
1085
+ * For example:
1086
+ *
1087
+ * ```json
1088
+ * {
1089
+ * "content": "shiki",
1090
+ * "color": "#D8DEE9",
1091
+ * "explanation": [
1092
+ * {
1093
+ * "content": "shiki",
1094
+ * "scopes": [
1095
+ * {
1096
+ * "scopeName": "source.js",
1097
+ * "themeMatches": []
1098
+ * },
1099
+ * {
1100
+ * "scopeName": "meta.objectliteral.js",
1101
+ * "themeMatches": []
1102
+ * },
1103
+ * {
1104
+ * "scopeName": "meta.object.member.js",
1105
+ * "themeMatches": []
1106
+ * },
1107
+ * {
1108
+ * "scopeName": "meta.array.literal.js",
1109
+ * "themeMatches": []
1110
+ * },
1111
+ * {
1112
+ * "scopeName": "variable.other.object.js",
1113
+ * "themeMatches": [
1114
+ * {
1115
+ * "name": "Variable",
1116
+ * "scope": "variable.other",
1117
+ * "settings": {
1118
+ * "foreground": "#D8DEE9"
1119
+ * }
1120
+ * },
1121
+ * {
1122
+ * "name": "[JavaScript] Variable Other Object",
1123
+ * "scope": "source.js variable.other.object",
1124
+ * "settings": {
1125
+ * "foreground": "#D8DEE9"
1126
+ * }
1127
+ * }
1128
+ * ]
1129
+ * }
1130
+ * ]
1131
+ * }
1132
+ * ]
1133
+ * }
1134
+ * ```
1135
+ */
1136
+ interface ThemedToken extends TokenStyles, TokenBase {
1137
+ }
1138
+ interface TokenBase {
1139
+ /**
1140
+ * The content of the token
1141
+ */
1142
+ content: string;
1143
+ /**
1144
+ * The start offset of the token, relative to the input code. 0-indexed.
1145
+ */
1146
+ offset: number;
1147
+ /**
1148
+ * Explanation of
1149
+ *
1150
+ * - token text's matching scopes
1151
+ * - reason that token text is given a color (one matching scope matches a rule (scope -> color) in the theme)
1152
+ */
1153
+ explanation?: ThemedTokenExplanation[];
1154
+ }
1155
+ interface TokenStyles {
1156
+ /**
1157
+ * 6 or 8 digit hex code representation of the token's color
1158
+ */
1159
+ color?: string;
1160
+ /**
1161
+ * Font style of token. Can be None/Italic/Bold/Underline
1162
+ */
1163
+ fontStyle?: FontStyle;
1164
+ /**
1165
+ * Override with custom inline style for HTML renderer.
1166
+ * When specified, `color` and `fontStyle` will be ignored.
1167
+ */
1168
+ htmlStyle?: string;
1169
+ }
1170
+ interface ThemedTokenWithVariants extends TokenBase {
1171
+ /**
1172
+ * An object of color name to token styles
1173
+ */
1174
+ variants: Record<string, TokenStyles>;
1175
+ }
1176
+ type DynamicImportLanguageRegistration = () => Promise<{
1177
+ default: LanguageRegistration[];
1178
+ }>;
1179
+ type DynamicImportThemeRegistration = () => Promise<{
1180
+ default: ThemeRegistration;
1181
+ }>;
1182
+ interface BundledLanguageInfo {
1183
+ id: string;
1184
+ name: string;
1185
+ import: DynamicImportLanguageRegistration;
1186
+ aliases?: string[];
1187
+ }
1188
+ interface BundledThemeInfo {
1189
+ id: string;
1190
+ displayName: string;
1191
+ type: 'light' | 'dark';
1192
+ import: DynamicImportThemeRegistration;
1193
+ }
1194
+ interface TokenizeWithThemeOptions {
1195
+ /**
1196
+ * Include explanation of why a token is given a color.
1197
+ *
1198
+ * @default false
1199
+ */
1200
+ includeExplanation?: boolean;
1201
+ /**
1202
+ * A map of color names to new color values.
1203
+ *
1204
+ * The color key starts with '#' and should be lowercased.
1205
+ *
1206
+ * This will be merged with theme's `colorReplacements` if any.
1207
+ */
1208
+ colorReplacements?: Record<string, string>;
1209
+ }
1210
+ /**
1211
+ * @deprecated Rnamed to `ShikiTransformer`
1212
+ */
1213
+ interface ShikijiTransformer extends ShikiTransformer {
1214
+ }
1215
+ /**
1216
+ * @deprecated Rnamed to `ShikiTransformerContext`
1217
+ */
1218
+ interface ShikijiTransformerContext extends ShikiTransformerContext {
1219
+ }
1220
+ /**
1221
+ * @deprecated Rnamed to `ShikiTransformerContextCommon`
1222
+ */
1223
+ interface ShikijiTransformerContextCommon extends ShikiTransformerContextCommon {
1224
+ }
1225
+
1226
+ export { type BundledLanguageInfo as $, type AnsiLanguage as A, type BundledHighlighterOptions as B, type CodeToHastOptions as C, type ThemeRegistrationRaw as D, type Element as E, FontStyle as F, type ThemeRegistration as G, type HighlighterGeneric as H, type IGrammar as I, type ShikiTransformerContextMeta as J, type ShikiTransformerContext as K, type LanguageInput as L, type MaybeArray as M, type Nodes as N, type ShikiTransformer as O, type PlainTextLanguage as P, type HtmlRendererOptionsCommon as Q, type Root as R, type SpecialTheme as S, type ThemeInput as T, type HtmlRendererOptions as U, type ThemedTokenScopeExplanation as V, type ThemedTokenExplanation as W, type TokenBase as X, type TokenStyles as Y, type DynamicImportLanguageRegistration as Z, type DynamicImportThemeRegistration as _, type HighlighterCoreOptions as a, type BundledThemeInfo as a0, type ShikijiTransformer as a1, type ShikijiTransformerContext as a2, type ShikijiTransformerContextCommon as a3, Registry as a4, INITIAL as a5, type StateStack as a6, type IRawTheme as a7, type IGrammarConfiguration as a8, type IOnigLib as a9, type RegistryOptions as aa, type IRawThemeSetting as ab, type RequireKeys as b, type CodeToThemedTokensOptions as c, type ThemedToken as d, type CodeToTokensWithThemesOptions as e, type ThemedTokenWithVariants as f, type ShikiInternal as g, type ThemeRegistrationResolved as h, type TokenizeWithThemeOptions as i, type ShikiTransformerContextCommon as j, type RootContent as k, type ThemeRegistrationAny as l, type IRawGrammar as m, type SpecialLanguage as n, type Awaitable as o, type MaybeGetter as p, type MaybeModule as q, type StringLiteralUnion as r, type ResolveBundleKey as s, type LanguageRegistration as t, type CodeToHastOptionsCommon as u, type CodeOptionsSingleTheme as v, type CodeOptionsMultipleThemes as w, type CodeOptionsThemes as x, type CodeOptionsMeta as y, type TransformerOptions as z };