@shikijs/core 1.15.2 → 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/chunk-engines.d.mts +223 -1
- package/dist/index.d.mts +133 -78
- package/dist/index.mjs +5307 -2114
- package/dist/types.d.mts +663 -5
- package/package.json +3 -2
- package/dist/chunk-tokens.d.mts +0 -1062
- package/dist/textmate.d.mts +0 -3
- package/dist/textmate.mjs +0 -3135
package/dist/chunk-engines.d.mts
CHANGED
|
@@ -1,4 +1,226 @@
|
|
|
1
|
+
interface IOnigCaptureIndex {
|
|
2
|
+
start: number;
|
|
3
|
+
end: number;
|
|
4
|
+
length: number;
|
|
5
|
+
}
|
|
6
|
+
interface IOnigMatch {
|
|
7
|
+
index: number;
|
|
8
|
+
captureIndices: IOnigCaptureIndex[];
|
|
9
|
+
}
|
|
10
|
+
declare const enum FindOption {
|
|
11
|
+
None = 0,
|
|
12
|
+
/**
|
|
13
|
+
* equivalent of ONIG_OPTION_NOT_BEGIN_STRING: (str) isn't considered as begin of string (* fail \A)
|
|
14
|
+
*/
|
|
15
|
+
NotBeginString = 1,
|
|
16
|
+
/**
|
|
17
|
+
* equivalent of ONIG_OPTION_NOT_END_STRING: (end) isn't considered as end of string (* fail \z, \Z)
|
|
18
|
+
*/
|
|
19
|
+
NotEndString = 2,
|
|
20
|
+
/**
|
|
21
|
+
* equivalent of ONIG_OPTION_NOT_BEGIN_POSITION: (start) isn't considered as start position of search (* fail \G)
|
|
22
|
+
*/
|
|
23
|
+
NotBeginPosition = 4,
|
|
24
|
+
/**
|
|
25
|
+
* used for debugging purposes.
|
|
26
|
+
*/
|
|
27
|
+
DebugCall = 8
|
|
28
|
+
}
|
|
29
|
+
interface OnigScanner {
|
|
30
|
+
findNextMatchSync(string: string | OnigString, startPosition: number, options: OrMask<FindOption>): IOnigMatch | null;
|
|
31
|
+
dispose?(): void;
|
|
32
|
+
}
|
|
33
|
+
interface OnigString {
|
|
34
|
+
readonly content: string;
|
|
35
|
+
dispose?(): void;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A union of given const enum values.
|
|
40
|
+
*/
|
|
41
|
+
type OrMask<T extends number> = number;
|
|
42
|
+
/**
|
|
43
|
+
* Identifiers with a binary dot operator.
|
|
44
|
+
* Examples: `baz` or `foo.bar`
|
|
45
|
+
*/
|
|
46
|
+
type ScopeName = string;
|
|
47
|
+
/**
|
|
48
|
+
* An expression language of ScopePathStr with a binary comma (to indicate alternatives) operator.
|
|
49
|
+
* Examples: `foo.bar boo.baz,quick quack`
|
|
50
|
+
*/
|
|
51
|
+
type ScopePattern = string;
|
|
52
|
+
/**
|
|
53
|
+
* A TextMate theme.
|
|
54
|
+
*/
|
|
55
|
+
interface IRawTheme {
|
|
56
|
+
readonly name?: string;
|
|
57
|
+
readonly settings: IRawThemeSetting[];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A single theme setting.
|
|
61
|
+
*/
|
|
62
|
+
interface IRawThemeSetting {
|
|
63
|
+
readonly name?: string;
|
|
64
|
+
readonly scope?: ScopePattern | ScopePattern[];
|
|
65
|
+
readonly settings: {
|
|
66
|
+
readonly fontStyle?: string;
|
|
67
|
+
readonly foreground?: string;
|
|
68
|
+
readonly background?: string;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
declare const ruleIdSymbol: unique symbol;
|
|
73
|
+
type RuleId = {
|
|
74
|
+
__brand: typeof ruleIdSymbol;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
interface IRawGrammar extends ILocatable {
|
|
78
|
+
repository: IRawRepository;
|
|
79
|
+
readonly scopeName: ScopeName;
|
|
80
|
+
readonly patterns: IRawRule[];
|
|
81
|
+
readonly injections?: {
|
|
82
|
+
[expression: string]: IRawRule;
|
|
83
|
+
};
|
|
84
|
+
readonly injectionSelector?: string;
|
|
85
|
+
readonly fileTypes?: string[];
|
|
86
|
+
readonly name?: string;
|
|
87
|
+
readonly firstLineMatch?: string;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Allowed values:
|
|
91
|
+
* * Scope Name, e.g. `source.ts`
|
|
92
|
+
* * Top level scope reference, e.g. `source.ts#entity.name.class`
|
|
93
|
+
* * Relative scope reference, e.g. `#entity.name.class`
|
|
94
|
+
* * self, e.g. `$self`
|
|
95
|
+
* * base, e.g. `$base`
|
|
96
|
+
*/
|
|
97
|
+
type IncludeString = string;
|
|
98
|
+
type RegExpString = string;
|
|
99
|
+
interface IRawRepositoryMap {
|
|
100
|
+
[name: string]: IRawRule;
|
|
101
|
+
$self: IRawRule;
|
|
102
|
+
$base: IRawRule;
|
|
103
|
+
}
|
|
104
|
+
type IRawRepository = IRawRepositoryMap & ILocatable;
|
|
105
|
+
interface IRawRule extends ILocatable {
|
|
106
|
+
id?: RuleId;
|
|
107
|
+
readonly include?: IncludeString;
|
|
108
|
+
readonly name?: ScopeName;
|
|
109
|
+
readonly contentName?: ScopeName;
|
|
110
|
+
readonly match?: RegExpString;
|
|
111
|
+
readonly captures?: IRawCaptures;
|
|
112
|
+
readonly begin?: RegExpString;
|
|
113
|
+
readonly beginCaptures?: IRawCaptures;
|
|
114
|
+
readonly end?: RegExpString;
|
|
115
|
+
readonly endCaptures?: IRawCaptures;
|
|
116
|
+
readonly while?: RegExpString;
|
|
117
|
+
readonly whileCaptures?: IRawCaptures;
|
|
118
|
+
readonly patterns?: IRawRule[];
|
|
119
|
+
readonly repository?: IRawRepository;
|
|
120
|
+
readonly applyEndPatternLast?: boolean;
|
|
121
|
+
}
|
|
122
|
+
type IRawCaptures = IRawCapturesMap & ILocatable;
|
|
123
|
+
interface IRawCapturesMap {
|
|
124
|
+
[captureId: string]: IRawRule;
|
|
125
|
+
}
|
|
126
|
+
interface ILocation {
|
|
127
|
+
readonly filename: string;
|
|
128
|
+
readonly line: number;
|
|
129
|
+
readonly char: number;
|
|
130
|
+
}
|
|
131
|
+
interface ILocatable {
|
|
132
|
+
readonly $vscodeTextmateLocation?: ILocation;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* A grammar
|
|
136
|
+
*/
|
|
137
|
+
interface IGrammar {
|
|
138
|
+
/**
|
|
139
|
+
* Tokenize `lineText` using previous line state `prevState`.
|
|
140
|
+
*/
|
|
141
|
+
tokenizeLine(lineText: string, prevState: StateStack | null, timeLimit?: number): ITokenizeLineResult;
|
|
142
|
+
/**
|
|
143
|
+
* Tokenize `lineText` using previous line state `prevState`.
|
|
144
|
+
* The result contains the tokens in binary format, resolved with the following information:
|
|
145
|
+
* - language
|
|
146
|
+
* - token type (regex, string, comment, other)
|
|
147
|
+
* - font style
|
|
148
|
+
* - foreground color
|
|
149
|
+
* - background color
|
|
150
|
+
* e.g. for getting the languageId: `(metadata & MetadataConsts.LANGUAGEID_MASK) >>> MetadataConsts.LANGUAGEID_OFFSET`
|
|
151
|
+
*/
|
|
152
|
+
tokenizeLine2(lineText: string, prevState: StateStack | null, timeLimit?: number): ITokenizeLineResult2;
|
|
153
|
+
}
|
|
154
|
+
interface ITokenizeLineResult {
|
|
155
|
+
readonly tokens: IToken[];
|
|
156
|
+
/**
|
|
157
|
+
* The `prevState` to be passed on to the next line tokenization.
|
|
158
|
+
*/
|
|
159
|
+
readonly ruleStack: StateStack;
|
|
160
|
+
/**
|
|
161
|
+
* Did tokenization stop early due to reaching the time limit.
|
|
162
|
+
*/
|
|
163
|
+
readonly stoppedEarly: boolean;
|
|
164
|
+
}
|
|
165
|
+
interface ITokenizeLineResult2 {
|
|
166
|
+
/**
|
|
167
|
+
* The tokens in binary format. Each token occupies two array indices. For token i:
|
|
168
|
+
* - at offset 2*i => startIndex
|
|
169
|
+
* - at offset 2*i + 1 => metadata
|
|
170
|
+
*
|
|
171
|
+
*/
|
|
172
|
+
readonly tokens: Uint32Array;
|
|
173
|
+
/**
|
|
174
|
+
* The `prevState` to be passed on to the next line tokenization.
|
|
175
|
+
*/
|
|
176
|
+
readonly ruleStack: StateStack;
|
|
177
|
+
/**
|
|
178
|
+
* Did tokenization stop early due to reaching the time limit.
|
|
179
|
+
*/
|
|
180
|
+
readonly stoppedEarly: boolean;
|
|
181
|
+
}
|
|
182
|
+
interface IToken {
|
|
183
|
+
startIndex: number;
|
|
184
|
+
readonly endIndex: number;
|
|
185
|
+
readonly scopes: string[];
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* **IMPORTANT** - Immutable!
|
|
189
|
+
*/
|
|
190
|
+
interface StateStack {
|
|
191
|
+
_stackElementBrand: void;
|
|
192
|
+
readonly depth: number;
|
|
193
|
+
clone(): StateStack;
|
|
194
|
+
equals(other: StateStack): boolean;
|
|
195
|
+
}
|
|
196
|
+
|
|
1
197
|
type Awaitable<T> = T | Promise<T>;
|
|
198
|
+
type MaybeGetter<T> = Awaitable<MaybeModule<T>> | (() => Awaitable<MaybeModule<T>>);
|
|
199
|
+
type MaybeModule<T> = T | {
|
|
200
|
+
default: T;
|
|
201
|
+
};
|
|
202
|
+
type MaybeArray<T> = T | T[];
|
|
203
|
+
type RequireKeys<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
|
204
|
+
interface Nothing {
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* type StringLiteralUnion<'foo'> = 'foo' | string
|
|
208
|
+
* This has auto completion whereas `'foo' | string` doesn't
|
|
209
|
+
* Adapted from https://github.com/microsoft/TypeScript/issues/29729
|
|
210
|
+
*/
|
|
211
|
+
type StringLiteralUnion<T extends U, U = string> = T | (U & Nothing);
|
|
212
|
+
|
|
213
|
+
interface PatternScanner extends OnigScanner {
|
|
214
|
+
}
|
|
215
|
+
interface RegexEngineString extends OnigString {
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Engine for RegExp matching and scanning.
|
|
219
|
+
*/
|
|
220
|
+
interface RegexEngine {
|
|
221
|
+
createScanner: (patterns: string[]) => PatternScanner;
|
|
222
|
+
createString: (s: string) => RegexEngineString;
|
|
223
|
+
}
|
|
2
224
|
interface WebAssemblyInstantiator {
|
|
3
225
|
(importObject: Record<string, Record<string, WebAssembly.ImportValue>> | undefined): Promise<WebAssemblyInstance>;
|
|
4
226
|
}
|
|
@@ -23,4 +245,4 @@ interface JavaScriptRegexEngineOptions {
|
|
|
23
245
|
cache?: Map<string, RegExp | Error>;
|
|
24
246
|
}
|
|
25
247
|
|
|
26
|
-
export type { JavaScriptRegexEngineOptions as J, LoadWasmOptions as L, WebAssemblyInstantiator as W,
|
|
248
|
+
export type { Awaitable as A, IGrammar as I, JavaScriptRegexEngineOptions as J, LoadWasmOptions as L, MaybeArray as M, OnigurumaLoadOptions as O, PatternScanner as P, RequireKeys as R, StringLiteralUnion as S, WebAssemblyInstantiator as W, RegexEngine as a, MaybeGetter as b, IRawGrammar as c, IRawTheme as d, IRawThemeSetting as e, MaybeModule as f, RegexEngineString as g, WebAssemblyInstance as h, LoadWasmOptionsPlain as i, StateStack as j };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
|
-
import { HighlighterCore, HighlighterGeneric, ShikiInternal } from './types.mjs';
|
|
2
|
-
export { Grammar } from './types.mjs';
|
|
3
|
-
import {
|
|
4
|
-
export { A as
|
|
5
|
-
import { Root,
|
|
6
|
-
import { L as LoadWasmOptions, J as JavaScriptRegexEngineOptions } from './chunk-engines.mjs';
|
|
7
|
-
export { a as WebAssemblyInstance, W as WebAssemblyInstantiator } from './chunk-engines.mjs';
|
|
1
|
+
import { HighlighterCoreOptions, HighlighterCore, BundledHighlighterOptions, HighlighterGeneric, CreatedBundledHighlighterOptions, LanguageInput, ThemeInput, CodeToHastOptions, CodeToTokensOptions, TokensResult, CodeToTokensBaseOptions, ThemedToken, CodeToTokensWithThemesOptions, ThemedTokenWithVariants, GrammarState, ShikiInternal, FontStyle, ThemeRegistrationAny, ThemeRegistrationResolved, TokenizeWithThemeOptions, ShikiTransformerContextCommon, CodeToHastRenderOptions, ShikiTransformerContextSource, PlainTextLanguage, SpecialLanguage, SpecialTheme, TokenStyles, Position, ShikiTransformer } from './types.mjs';
|
|
2
|
+
export { AnsiLanguage, BundledLanguageInfo, BundledThemeInfo, CodeOptionsMeta, CodeOptionsMultipleThemes, CodeOptionsSingleTheme, CodeOptionsThemes, CodeToHastOptionsCommon, CodeToHastRenderOptionsCommon, DecorationItem, DecorationOptions, DecorationTransformType, DynamicImportLanguageRegistration, DynamicImportThemeRegistration, Grammar, LanguageRegistration, Offset, OffsetOrPosition, ResolveBundleKey, ResolvedDecorationItem, ResolvedPosition, ShikiTransformerContext, ShikiTransformerContextMeta, ThemeRegistration, ThemeRegistrationRaw, ThemedTokenExplanation, ThemedTokenScopeExplanation, TokenBase, TransformerOptions } from './types.mjs';
|
|
3
|
+
import { R as RequireKeys, L as LoadWasmOptions, a as RegexEngine, J as JavaScriptRegexEngineOptions, I as IGrammar, M as MaybeArray, b as MaybeGetter } from './chunk-engines.mjs';
|
|
4
|
+
export { A as Awaitable, i as LoadWasmOptionsPlain, f as MaybeModule, O as OnigurumaLoadOptions, P as PatternScanner, c as RawGrammar, d as RawTheme, e as RawThemeSetting, g as RegexEngineString, S as StringLiteralUnion, h as WebAssemblyInstance, W as WebAssemblyInstantiator } from './chunk-engines.mjs';
|
|
5
|
+
import { Root, RootContent, Nodes, Element } from 'hast';
|
|
8
6
|
|
|
9
7
|
/**
|
|
10
8
|
* Create a Shiki core highlighter instance, with no languages or themes bundled.
|
|
11
9
|
* Wasm and each language and theme must be loaded manually.
|
|
12
10
|
*
|
|
13
|
-
* @see http://shiki.style/guide/
|
|
11
|
+
* @see http://shiki.style/guide/bundles#fine-grained-bundle
|
|
14
12
|
*/
|
|
15
13
|
declare function createHighlighterCore(options?: HighlighterCoreOptions): Promise<HighlighterCore>;
|
|
14
|
+
/**
|
|
15
|
+
* Create a Shiki core highlighter instance, with no languages or themes bundled.
|
|
16
|
+
* Wasm and each language and theme must be loaded manually.
|
|
17
|
+
*
|
|
18
|
+
* Synchronous version of `createHighlighterCore`, which requires to provide the engine and all themes and languages upfront.
|
|
19
|
+
*
|
|
20
|
+
* @see http://shiki.style/guide/bundles#fine-grained-bundle
|
|
21
|
+
*/
|
|
22
|
+
declare function createHighlighterCoreSync(options?: HighlighterCoreOptions<true>): HighlighterCore;
|
|
16
23
|
declare function makeSingletonHighlighterCore(createHighlighter: typeof createHighlighterCore): (options?: Partial<HighlighterCoreOptions>) => Promise<HighlighterCore>;
|
|
17
24
|
declare const getSingletonHighlighterCore: (options?: Partial<HighlighterCoreOptions>) => Promise<HighlighterCore>;
|
|
18
25
|
/**
|
|
@@ -21,12 +28,31 @@ declare const getSingletonHighlighterCore: (options?: Partial<HighlighterCoreOpt
|
|
|
21
28
|
declare function getHighlighterCore(options?: HighlighterCoreOptions): Promise<HighlighterCore>;
|
|
22
29
|
|
|
23
30
|
type CreateHighlighterFactory<L extends string, T extends string> = (options: BundledHighlighterOptions<L, T>) => Promise<HighlighterGeneric<L, T>>;
|
|
31
|
+
/**
|
|
32
|
+
* Create a `createHighlighter` function with bundled themes, languages, and engine.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* const createHighlighter = createdBundledHighlighter({
|
|
37
|
+
* langs: {
|
|
38
|
+
* typescript: () => import('shiki/langs/typescript.mjs'),
|
|
39
|
+
* // ...
|
|
40
|
+
* },
|
|
41
|
+
* themes: {
|
|
42
|
+
* nord: () => import('shiki/themes/nord.mjs'),
|
|
43
|
+
* // ...
|
|
44
|
+
* },
|
|
45
|
+
* engine: () => createWasmOnigEngine(), // or createJavaScriptRegexEngine()
|
|
46
|
+
* })
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @param options
|
|
50
|
+
*/
|
|
51
|
+
declare function createdBundledHighlighter<BundledLangs extends string, BundledThemes extends string>(options: CreatedBundledHighlighterOptions<BundledLangs, BundledThemes>): CreateHighlighterFactory<BundledLangs, BundledThemes>;
|
|
24
52
|
/**
|
|
25
53
|
* Create a `createHighlighter` function with bundled themes and languages.
|
|
26
54
|
*
|
|
27
|
-
* @
|
|
28
|
-
* @param bundledThemes
|
|
29
|
-
* @param loadWasm
|
|
55
|
+
* @deprecated Use `createdBundledHighlighter({ langs, themes, engine })` signature instead.
|
|
30
56
|
*/
|
|
31
57
|
declare function createdBundledHighlighter<BundledLangs extends string, BundledThemes extends string>(bundledLanguages: Record<BundledLangs, LanguageInput>, bundledThemes: Record<BundledThemes, ThemeInput>, loadWasm: HighlighterCoreOptions['loadWasm']): CreateHighlighterFactory<BundledLangs, BundledThemes>;
|
|
32
58
|
interface ShorthandsBundle<L extends string, T extends string> {
|
|
@@ -78,68 +104,26 @@ interface ShorthandsBundle<L extends string, T extends string> {
|
|
|
78
104
|
declare function makeSingletonHighlighter<L extends string, T extends string>(createHighlighter: CreateHighlighterFactory<L, T>): (options?: Partial<BundledHighlighterOptions<L, T>>) => Promise<HighlighterGeneric<L, T>>;
|
|
79
105
|
declare function createSingletonShorthands<L extends string, T extends string>(createHighlighter: CreateHighlighterFactory<L, T>): ShorthandsBundle<L, T>;
|
|
80
106
|
|
|
81
|
-
declare function toArray<T>(x: MaybeArray<T>): T[];
|
|
82
|
-
/**
|
|
83
|
-
* Split a string into lines, each line preserves the line ending.
|
|
84
|
-
*/
|
|
85
|
-
declare function splitLines(code: string, preserveEnding?: boolean): [string, number][];
|
|
86
|
-
/**
|
|
87
|
-
* Check if the language is plaintext that is ignored by Shiki.
|
|
88
|
-
*
|
|
89
|
-
* Hard-coded plain text languages: `plaintext`, `txt`, `text`, `plain`.
|
|
90
|
-
*/
|
|
91
|
-
declare function isPlainLang(lang: string | null | undefined): lang is PlainTextLanguage;
|
|
92
|
-
/**
|
|
93
|
-
* Check if the language is specially handled or bypassed by Shiki.
|
|
94
|
-
*
|
|
95
|
-
* Hard-coded languages: `ansi` and plaintexts like `plaintext`, `txt`, `text`, `plain`.
|
|
96
|
-
*/
|
|
97
|
-
declare function isSpecialLang(lang: any): lang is SpecialLanguage;
|
|
98
|
-
/**
|
|
99
|
-
* Check if the theme is specially handled or bypassed by Shiki.
|
|
100
|
-
*
|
|
101
|
-
* Hard-coded themes: `none`.
|
|
102
|
-
*/
|
|
103
|
-
declare function isNoneTheme(theme: string | ThemeInput | null | undefined): theme is 'none';
|
|
104
|
-
/**
|
|
105
|
-
* Check if the theme is specially handled or bypassed by Shiki.
|
|
106
|
-
*
|
|
107
|
-
* Hard-coded themes: `none`.
|
|
108
|
-
*/
|
|
109
|
-
declare function isSpecialTheme(theme: string | ThemeInput | null | undefined): theme is SpecialTheme;
|
|
110
107
|
/**
|
|
111
|
-
*
|
|
108
|
+
* Get the minimal shiki context for rendering.
|
|
112
109
|
*
|
|
113
|
-
*
|
|
110
|
+
* Synchronous version of `createShikiInternal`, which requires to provide the engine and all themes and languages upfront.
|
|
114
111
|
*/
|
|
115
|
-
declare function
|
|
112
|
+
declare function createShikiInternalSync(options: HighlighterCoreOptions<true>): ShikiInternal;
|
|
113
|
+
|
|
116
114
|
/**
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
* The offsets are relative to the token, and should be sorted.
|
|
115
|
+
* Set the default wasm loader for `loadWasm`.
|
|
116
|
+
* @internal
|
|
120
117
|
*/
|
|
121
|
-
declare function
|
|
118
|
+
declare function setDefaultWasmLoader(_loader: LoadWasmOptions): void;
|
|
122
119
|
/**
|
|
123
|
-
*
|
|
120
|
+
* Get the minimal shiki context for rendering.
|
|
124
121
|
*/
|
|
125
|
-
declare function
|
|
126
|
-
declare function resolveColorReplacements(theme: ThemeRegistrationAny | string, options?: TokenizeWithThemeOptions): {
|
|
127
|
-
[x: string]: string;
|
|
128
|
-
};
|
|
129
|
-
declare function applyColorReplacements(color: string, replacements?: Record<string, string>): string;
|
|
130
|
-
declare function applyColorReplacements(color?: string | undefined, replacements?: Record<string, string>): string | undefined;
|
|
131
|
-
declare function getTokenStyleObject(token: TokenStyles): Record<string, string>;
|
|
132
|
-
declare function stringifyTokenStyle(token: Record<string, string>): string;
|
|
122
|
+
declare function createShikiInternal(options?: HighlighterCoreOptions): Promise<ShikiInternal>;
|
|
133
123
|
/**
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
* Overflow/underflow are unchecked.
|
|
124
|
+
* @deprecated Use `createShikiInternal` instead.
|
|
137
125
|
*/
|
|
138
|
-
declare function
|
|
139
|
-
lines: string[];
|
|
140
|
-
indexToPos: (index: number) => Position;
|
|
141
|
-
posToIndex: (line: number, character: number) => number;
|
|
142
|
-
};
|
|
126
|
+
declare function getShikiInternal(options?: HighlighterCoreOptions): Promise<ShikiInternal>;
|
|
143
127
|
|
|
144
128
|
declare function loadWasm(options: LoadWasmOptions): Promise<void>;
|
|
145
129
|
|
|
@@ -156,19 +140,28 @@ declare function createWasmOnigEngine(options?: LoadWasmOptions | null): Promise
|
|
|
156
140
|
*/
|
|
157
141
|
declare function createJavaScriptRegexEngine(options?: JavaScriptRegexEngineOptions): RegexEngine;
|
|
158
142
|
|
|
143
|
+
declare const enum TemporaryStandardTokenType {
|
|
144
|
+
Other = 0,
|
|
145
|
+
Comment = 1,
|
|
146
|
+
String = 2,
|
|
147
|
+
RegEx = 4,
|
|
148
|
+
MetaEmbedded = 8
|
|
149
|
+
}
|
|
150
|
+
declare class StackElementMetadata {
|
|
151
|
+
static toBinaryStr(metadata: number): string;
|
|
152
|
+
static getLanguageId(metadata: number): number;
|
|
153
|
+
static getTokenType(metadata: number): number;
|
|
154
|
+
static getFontStyle(metadata: number): number;
|
|
155
|
+
static getForeground(metadata: number): number;
|
|
156
|
+
static getBackground(metadata: number): number;
|
|
157
|
+
static containsBalancedBrackets(metadata: number): boolean;
|
|
158
|
+
static set(metadata: number, languageId: number, tokenType: TemporaryStandardTokenType, fontStyle: FontStyle, foreground: number, background: number): number;
|
|
159
|
+
}
|
|
160
|
+
|
|
159
161
|
/**
|
|
160
|
-
*
|
|
161
|
-
* @internal
|
|
162
|
-
*/
|
|
163
|
-
declare function setDefaultWasmLoader(_loader: LoadWasmOptions): void;
|
|
164
|
-
/**
|
|
165
|
-
* Get the minimal shiki context for rendering.
|
|
166
|
-
*/
|
|
167
|
-
declare function createShikiInternal(options?: HighlighterCoreOptions): Promise<ShikiInternal>;
|
|
168
|
-
/**
|
|
169
|
-
* @deprecated Use `createShikiInternal` instead.
|
|
162
|
+
* Normalize a textmate theme to shiki theme
|
|
170
163
|
*/
|
|
171
|
-
declare function
|
|
164
|
+
declare function normalizeTheme(rawTheme: ThemeRegistrationAny): ThemeRegistrationResolved;
|
|
172
165
|
|
|
173
166
|
/**
|
|
174
167
|
* Code to tokens, with a simple theme.
|
|
@@ -417,10 +410,72 @@ declare function codeToHtml(internal: ShikiInternal, code: string, options: Code
|
|
|
417
410
|
*/
|
|
418
411
|
declare function codeToTokensWithThemes(internal: ShikiInternal, code: string, options: CodeToTokensWithThemesOptions): ThemedTokenWithVariants[][];
|
|
419
412
|
|
|
413
|
+
declare function toArray<T>(x: MaybeArray<T>): T[];
|
|
420
414
|
/**
|
|
421
|
-
*
|
|
415
|
+
* Split a string into lines, each line preserves the line ending.
|
|
422
416
|
*/
|
|
423
|
-
declare function
|
|
417
|
+
declare function splitLines(code: string, preserveEnding?: boolean): [string, number][];
|
|
418
|
+
/**
|
|
419
|
+
* Check if the language is plaintext that is ignored by Shiki.
|
|
420
|
+
*
|
|
421
|
+
* Hard-coded plain text languages: `plaintext`, `txt`, `text`, `plain`.
|
|
422
|
+
*/
|
|
423
|
+
declare function isPlainLang(lang: string | null | undefined): lang is PlainTextLanguage;
|
|
424
|
+
/**
|
|
425
|
+
* Check if the language is specially handled or bypassed by Shiki.
|
|
426
|
+
*
|
|
427
|
+
* Hard-coded languages: `ansi` and plaintexts like `plaintext`, `txt`, `text`, `plain`.
|
|
428
|
+
*/
|
|
429
|
+
declare function isSpecialLang(lang: any): lang is SpecialLanguage;
|
|
430
|
+
/**
|
|
431
|
+
* Check if the theme is specially handled or bypassed by Shiki.
|
|
432
|
+
*
|
|
433
|
+
* Hard-coded themes: `none`.
|
|
434
|
+
*/
|
|
435
|
+
declare function isNoneTheme(theme: string | ThemeInput | null | undefined): theme is 'none';
|
|
436
|
+
/**
|
|
437
|
+
* Check if the theme is specially handled or bypassed by Shiki.
|
|
438
|
+
*
|
|
439
|
+
* Hard-coded themes: `none`.
|
|
440
|
+
*/
|
|
441
|
+
declare function isSpecialTheme(theme: string | ThemeInput | null | undefined): theme is SpecialTheme;
|
|
442
|
+
/**
|
|
443
|
+
* Utility to append class to a hast node
|
|
444
|
+
*
|
|
445
|
+
* If the `property.class` is a string, it will be splitted by space and converted to an array.
|
|
446
|
+
*/
|
|
447
|
+
declare function addClassToHast(node: Element, className: string | string[]): Element;
|
|
448
|
+
/**
|
|
449
|
+
* Split a token into multiple tokens by given offsets.
|
|
450
|
+
*
|
|
451
|
+
* The offsets are relative to the token, and should be sorted.
|
|
452
|
+
*/
|
|
453
|
+
declare function splitToken<T extends Pick<ThemedToken, 'content' | 'offset'>>(token: T, offsets: number[]): T[];
|
|
454
|
+
/**
|
|
455
|
+
* Split 2D tokens array by given breakpoints.
|
|
456
|
+
*/
|
|
457
|
+
declare function splitTokens<T extends Pick<ThemedToken, 'content' | 'offset'>>(tokens: T[][], breakpoints: number[] | Set<number>): T[][];
|
|
458
|
+
/**
|
|
459
|
+
* Normalize a getter to a promise.
|
|
460
|
+
*/
|
|
461
|
+
declare function normalizeGetter<T>(p: MaybeGetter<T>): Promise<T>;
|
|
462
|
+
declare function resolveColorReplacements(theme: ThemeRegistrationAny | string, options?: TokenizeWithThemeOptions): {
|
|
463
|
+
[x: string]: string;
|
|
464
|
+
};
|
|
465
|
+
declare function applyColorReplacements(color: string, replacements?: Record<string, string>): string;
|
|
466
|
+
declare function applyColorReplacements(color?: string | undefined, replacements?: Record<string, string>): string | undefined;
|
|
467
|
+
declare function getTokenStyleObject(token: TokenStyles): Record<string, string>;
|
|
468
|
+
declare function stringifyTokenStyle(token: Record<string, string>): string;
|
|
469
|
+
/**
|
|
470
|
+
* Creates a converter between index and position in a code block.
|
|
471
|
+
*
|
|
472
|
+
* Overflow/underflow are unchecked.
|
|
473
|
+
*/
|
|
474
|
+
declare function createPositionConverter(code: string): {
|
|
475
|
+
lines: string[];
|
|
476
|
+
indexToPos: (index: number) => Position;
|
|
477
|
+
posToIndex: (line: number, character: number) => number;
|
|
478
|
+
};
|
|
424
479
|
|
|
425
480
|
/**
|
|
426
481
|
* A built-in transformer to add decorations to the highlighted code.
|
|
@@ -431,4 +486,4 @@ declare class ShikiError extends Error {
|
|
|
431
486
|
constructor(message: string);
|
|
432
487
|
}
|
|
433
488
|
|
|
434
|
-
export { BundledHighlighterOptions, CodeToHastOptions, CodeToHastRenderOptions, CodeToTokensBaseOptions, CodeToTokensOptions, CodeToTokensWithThemesOptions, type CreateHighlighterFactory, GrammarState, HighlighterCore, HighlighterCoreOptions, HighlighterGeneric, LanguageInput, LoadWasmOptions, MaybeArray, PlainTextLanguage, Position, RequireKeys, ShikiError, ShikiInternal, ShikiTransformer, ShikiTransformerContextCommon, ShikiTransformerContextSource, type ShorthandsBundle, SpecialLanguage, SpecialTheme, ThemeInput, ThemeRegistrationAny, ThemeRegistrationResolved, ThemedToken, ThemedTokenWithVariants, TokenStyles, TokenizeWithThemeOptions, TokensResult, addClassToHast, applyColorReplacements, codeToHast, codeToHtml, codeToTokens, codeToTokensBase, codeToTokensWithThemes, createHighlighterCore, createJavaScriptRegexEngine, createPositionConverter, createShikiInternal, createSingletonShorthands, createWasmOnigEngine, createdBundledHighlighter, getHighlighterCore, getShikiInternal, getSingletonHighlighterCore, getTokenStyleObject, toHtml as hastToHtml, isNoneTheme, isPlainLang, isSpecialLang, isSpecialTheme, loadWasm, makeSingletonHighlighter, makeSingletonHighlighterCore, normalizeTheme, resolveColorReplacements, setDefaultWasmLoader, splitLines, splitToken, splitTokens, stringifyTokenStyle, toArray, tokenizeAnsiWithTheme, tokenizeWithTheme, tokensToHast, transformerDecorations };
|
|
489
|
+
export { BundledHighlighterOptions, CodeToHastOptions, CodeToHastRenderOptions, CodeToTokensBaseOptions, CodeToTokensOptions, CodeToTokensWithThemesOptions, type CreateHighlighterFactory, CreatedBundledHighlighterOptions, FontStyle, GrammarState, HighlighterCore, HighlighterCoreOptions, HighlighterGeneric, JavaScriptRegexEngineOptions, LanguageInput, LoadWasmOptions, MaybeArray, MaybeGetter, PlainTextLanguage, Position, RegexEngine, RequireKeys, ShikiError, ShikiInternal, ShikiTransformer, ShikiTransformerContextCommon, ShikiTransformerContextSource, type ShorthandsBundle, SpecialLanguage, SpecialTheme, StackElementMetadata, ThemeInput, ThemeRegistrationAny, ThemeRegistrationResolved, ThemedToken, ThemedTokenWithVariants, TokenStyles, TokenizeWithThemeOptions, TokensResult, addClassToHast, applyColorReplacements, codeToHast, codeToHtml, codeToTokens, codeToTokensBase, codeToTokensWithThemes, createHighlighterCore, createHighlighterCoreSync, createJavaScriptRegexEngine, createPositionConverter, createShikiInternal, createShikiInternalSync, createSingletonShorthands, createWasmOnigEngine, createdBundledHighlighter, getHighlighterCore, getShikiInternal, getSingletonHighlighterCore, getTokenStyleObject, toHtml as hastToHtml, isNoneTheme, isPlainLang, isSpecialLang, isSpecialTheme, loadWasm, makeSingletonHighlighter, makeSingletonHighlighterCore, normalizeGetter, normalizeTheme, resolveColorReplacements, setDefaultWasmLoader, splitLines, splitToken, splitTokens, stringifyTokenStyle, toArray, tokenizeAnsiWithTheme, tokenizeWithTheme, tokensToHast, transformerDecorations };
|