@shikijs/core 3.23.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +110 -189
- package/dist/index.mjs +1323 -2352
- package/dist/textmate.d.mts +1 -1
- package/dist/textmate.mjs +3 -1
- package/dist/types.d.mts +1 -2
- package/dist/types.mjs +3 -1
- package/package.json +8 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { Awaitable, BundledHighlighterOptions, CodeOptionsMultipleThemes, CodeToHastOptions, CodeToHastRenderOptions, CodeToTokensBaseOptions, CodeToTokensOptions, CodeToTokensWithThemesOptions, CreateBundledHighlighterOptions, CreateHighlighterFactory, GrammarState, HighlighterCore, HighlighterCoreOptions, HighlighterGeneric, Position, RequireKeys, ShikiPrimitive, ShikiTransformer, ShikiTransformerContextCommon, ShikiTransformerContextSource, ThemeRegistration, ThemeRegistrationResolved, ThemedToken, ThemedTokenWithVariants, TokenStyles, TokenizeWithThemeOptions, TokensResult } from "@shikijs/types";
|
|
2
|
+
import { ShikiError, applyColorReplacements, codeToTokensWithThemes, createShikiInternal, createShikiInternalSync, createShikiPrimitive, createShikiPrimitiveAsync, getLastGrammarState, isNoneTheme, isPlainLang, isSpecialLang, isSpecialTheme, normalizeGetter, normalizeTheme, resolveColorReplacements, splitLines, toArray, tokenizeWithTheme } from "@shikijs/primitive";
|
|
3
|
+
import { toHtml } from "hast-util-to-html";
|
|
4
|
+
import { Element, Root } from "hast";
|
|
5
|
+
export * from "@shikijs/types";
|
|
5
6
|
|
|
7
|
+
//#region src/constructors/bundle-factory.d.ts
|
|
6
8
|
/**
|
|
7
9
|
* Create a `createHighlighter` function with bundled themes, languages, and engine.
|
|
8
10
|
*
|
|
@@ -25,64 +27,61 @@ import { toHtml } from 'hast-util-to-html';
|
|
|
25
27
|
*/
|
|
26
28
|
declare function createBundledHighlighter<BundledLangs extends string, BundledThemes extends string>(options: CreateBundledHighlighterOptions<BundledLangs, BundledThemes>): CreateHighlighterFactory<BundledLangs, BundledThemes>;
|
|
27
29
|
interface ShorthandsBundle<L extends string, T extends string> {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Shorthand for `codeToHtml` with auto-loaded theme and language.
|
|
32
|
+
* A singleton highlighter it maintained internally.
|
|
33
|
+
*
|
|
34
|
+
* Differences from `highlighter.codeToHtml()`, this function is async.
|
|
35
|
+
*/
|
|
36
|
+
codeToHtml: (code: string, options: CodeToHastOptions<L, T>) => Promise<string>;
|
|
37
|
+
/**
|
|
38
|
+
* Shorthand for `codeToHtml` with auto-loaded theme and language.
|
|
39
|
+
* A singleton highlighter it maintained internally.
|
|
40
|
+
*
|
|
41
|
+
* Differences from `highlighter.codeToHtml()`, this function is async.
|
|
42
|
+
*/
|
|
43
|
+
codeToHast: (code: string, options: CodeToHastOptions<L, T>) => Promise<Root>;
|
|
44
|
+
/**
|
|
45
|
+
* Shorthand for `codeToTokens` with auto-loaded theme and language.
|
|
46
|
+
* A singleton highlighter it maintained internally.
|
|
47
|
+
*
|
|
48
|
+
* Differences from `highlighter.codeToTokens()`, this function is async.
|
|
49
|
+
*/
|
|
50
|
+
codeToTokens: (code: string, options: CodeToTokensOptions<L, T>) => Promise<TokensResult>;
|
|
51
|
+
/**
|
|
52
|
+
* Shorthand for `codeToTokensBase` with auto-loaded theme and language.
|
|
53
|
+
* A singleton highlighter it maintained internally.
|
|
54
|
+
*
|
|
55
|
+
* Differences from `highlighter.codeToTokensBase()`, this function is async.
|
|
56
|
+
*/
|
|
57
|
+
codeToTokensBase: (code: string, options: RequireKeys<CodeToTokensBaseOptions<L, T>, 'theme' | 'lang'>) => Promise<ThemedToken[][]>;
|
|
58
|
+
/**
|
|
59
|
+
* Shorthand for `codeToTokensWithThemes` with auto-loaded theme and language.
|
|
60
|
+
* A singleton highlighter it maintained internally.
|
|
61
|
+
*
|
|
62
|
+
* Differences from `highlighter.codeToTokensWithThemes()`, this function is async.
|
|
63
|
+
*/
|
|
64
|
+
codeToTokensWithThemes: (code: string, options: RequireKeys<CodeToTokensWithThemesOptions<L, T>, 'themes' | 'lang'>) => Promise<ThemedTokenWithVariants[][]>;
|
|
65
|
+
/**
|
|
66
|
+
* Get the singleton highlighter.
|
|
67
|
+
*/
|
|
68
|
+
getSingletonHighlighter: (options?: Partial<BundledHighlighterOptions<L, T>>) => Promise<HighlighterGeneric<L, T>>;
|
|
69
|
+
/**
|
|
70
|
+
* Shorthand for `getLastGrammarState` with auto-loaded theme and language.
|
|
71
|
+
* A singleton highlighter it maintained internally.
|
|
72
|
+
*/
|
|
73
|
+
getLastGrammarState: ((element: ThemedToken[][] | Root) => GrammarState) | ((code: string, options: CodeToTokensBaseOptions<L, T>) => Promise<GrammarState>);
|
|
72
74
|
}
|
|
73
75
|
declare function makeSingletonHighlighter<L extends string, T extends string>(createHighlighter: CreateHighlighterFactory<L, T>): (options?: Partial<BundledHighlighterOptions<L, T>>) => Promise<HighlighterGeneric<L, T>>;
|
|
74
76
|
interface CreateSingletonShorthandsOptions<L extends string, T extends string> {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
/**
|
|
78
|
+
* A custom function to guess embedded languages to be loaded.
|
|
79
|
+
*/
|
|
80
|
+
guessEmbeddedLanguages?: (code: string, lang: string | undefined, highlighter: HighlighterGeneric<L, T>) => Awaitable<string[] | undefined>;
|
|
79
81
|
}
|
|
80
82
|
declare function createSingletonShorthands<L extends string, T extends string>(createHighlighter: CreateHighlighterFactory<L, T>, config?: CreateSingletonShorthandsOptions<L, T>): ShorthandsBundle<L, T>;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
*/
|
|
84
|
-
declare const createdBundledHighlighter: typeof createBundledHighlighter;
|
|
85
|
-
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/constructors/highlighter.d.ts
|
|
86
85
|
/**
|
|
87
86
|
* Create a Shiki core highlighter instance, with no languages or themes bundled.
|
|
88
87
|
* Wasm and each language and theme must be loaded manually.
|
|
@@ -101,78 +100,62 @@ declare function createHighlighterCore(options: HighlighterCoreOptions<false>):
|
|
|
101
100
|
declare function createHighlighterCoreSync(options: HighlighterCoreOptions<true>): HighlighterCore;
|
|
102
101
|
declare function makeSingletonHighlighterCore(createHighlighter: typeof createHighlighterCore): (options: HighlighterCoreOptions) => Promise<HighlighterCore>;
|
|
103
102
|
declare const getSingletonHighlighterCore: (options: HighlighterCoreOptions) => Promise<HighlighterCore>;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
*/
|
|
108
|
-
declare function createShikiInternal(options: HighlighterCoreOptions): Promise<ShikiInternal>;
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Get the minimal shiki context for rendering.
|
|
112
|
-
*
|
|
113
|
-
* Synchronous version of `createShikiInternal`, which requires to provide the engine and all themes and languages upfront.
|
|
114
|
-
*/
|
|
115
|
-
declare function createShikiInternalSync(options: HighlighterCoreOptions<true>): ShikiInternal;
|
|
116
|
-
|
|
117
|
-
declare function codeToHast(internal: ShikiInternal, code: string, options: CodeToHastOptions, transformerContext?: ShikiTransformerContextCommon): Root;
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src/highlight/code-to-hast.d.ts
|
|
105
|
+
declare function codeToHast(primitive: ShikiPrimitive, code: string, options: CodeToHastOptions, transformerContext?: ShikiTransformerContextCommon): Root;
|
|
118
106
|
declare function tokensToHast(tokens: ThemedToken[][], options: CodeToHastRenderOptions, transformerContext: ShikiTransformerContextSource, grammarState?: GrammarState | undefined): Root;
|
|
119
|
-
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region src/highlight/code-to-html.d.ts
|
|
120
109
|
declare const hastToHtml: typeof toHtml;
|
|
121
110
|
/**
|
|
122
111
|
* Get highlighted code in HTML.
|
|
123
112
|
*/
|
|
124
|
-
declare function codeToHtml(
|
|
125
|
-
|
|
113
|
+
declare function codeToHtml(primitive: ShikiPrimitive, code: string, options: CodeToHastOptions): string;
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region src/highlight/code-to-tokens.d.ts
|
|
126
116
|
/**
|
|
127
117
|
* High-level code-to-tokens API.
|
|
128
118
|
*
|
|
129
119
|
* It will use `codeToTokensWithThemes` or `codeToTokensBase` based on the options.
|
|
130
120
|
*/
|
|
131
|
-
declare function codeToTokens(
|
|
132
|
-
|
|
121
|
+
declare function codeToTokens(primitive: ShikiPrimitive, code: string, options: CodeToTokensOptions): TokensResult;
|
|
122
|
+
//#endregion
|
|
123
|
+
//#region src/highlight/code-to-tokens-ansi.d.ts
|
|
133
124
|
declare function tokenizeAnsiWithTheme(theme: ThemeRegistrationResolved, fileContents: string, options?: TokenizeWithThemeOptions): ThemedToken[][];
|
|
134
|
-
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region src/highlight/code-to-tokens-base.d.ts
|
|
135
127
|
/**
|
|
136
128
|
* Code to tokens, with a simple theme.
|
|
129
|
+
* This wraps the tokenizer's implementation to add ANSI support.
|
|
137
130
|
*/
|
|
138
|
-
declare function codeToTokensBase(
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Get tokens with multiple themes
|
|
143
|
-
*/
|
|
144
|
-
declare function codeToTokensWithThemes(internal: ShikiInternal, code: string, options: CodeToTokensWithThemesOptions): ThemedTokenWithVariants[][];
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Normalize a textmate theme to shiki theme
|
|
148
|
-
*/
|
|
149
|
-
declare function normalizeTheme(rawTheme: ThemeRegistrationAny): ThemeRegistrationResolved;
|
|
150
|
-
|
|
131
|
+
declare function codeToTokensBase(primitive: ShikiPrimitive, code: string, options?: CodeToTokensBaseOptions): ThemedToken[][];
|
|
132
|
+
//#endregion
|
|
133
|
+
//#region src/theme-css-variables.d.ts
|
|
151
134
|
interface CssVariablesThemeOptions {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
135
|
+
/**
|
|
136
|
+
* Theme name. Need to unique if multiple css variables themes are created
|
|
137
|
+
*
|
|
138
|
+
* @default 'css-variables'
|
|
139
|
+
*/
|
|
140
|
+
name?: string;
|
|
141
|
+
/**
|
|
142
|
+
* Prefix for css variables
|
|
143
|
+
*
|
|
144
|
+
* @default '--shiki-'
|
|
145
|
+
*/
|
|
146
|
+
variablePrefix?: string;
|
|
147
|
+
/**
|
|
148
|
+
* Default value for css variables, the key is without the prefix
|
|
149
|
+
*
|
|
150
|
+
* @example `{ 'token-comment': '#888' }` will generate `var(--shiki-token-comment, #888)` for comments
|
|
151
|
+
*/
|
|
152
|
+
variableDefaults?: Record<string, string>;
|
|
153
|
+
/**
|
|
154
|
+
* Enable font style
|
|
155
|
+
*
|
|
156
|
+
* @default true
|
|
157
|
+
*/
|
|
158
|
+
fontStyle?: boolean;
|
|
176
159
|
}
|
|
177
160
|
/**
|
|
178
161
|
* A factory function to create a css-variable-based theme
|
|
@@ -180,79 +163,31 @@ interface CssVariablesThemeOptions {
|
|
|
180
163
|
* @see https://shiki.style/guide/theme-colors#css-variables-theme
|
|
181
164
|
*/
|
|
182
165
|
declare function createCssVariablesTheme(options?: CssVariablesThemeOptions): ThemeRegistration;
|
|
183
|
-
|
|
166
|
+
//#endregion
|
|
167
|
+
//#region src/transformer-decorations.d.ts
|
|
184
168
|
/**
|
|
185
169
|
* A built-in transformer to add decorations to the highlighted code.
|
|
186
170
|
*/
|
|
187
171
|
declare function transformerDecorations(): ShikiTransformer;
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
declare function applyColorReplacements(color: string, replacements?: Record<string, string | undefined>): string;
|
|
191
|
-
declare function applyColorReplacements(color?: string | undefined, replacements?: Record<string, string | undefined>): string | undefined;
|
|
192
|
-
|
|
193
|
-
declare function toArray<T>(x: MaybeArray<T>): T[];
|
|
194
|
-
/**
|
|
195
|
-
* Normalize a getter to a promise.
|
|
196
|
-
*/
|
|
197
|
-
declare function normalizeGetter<T>(p: MaybeGetter<T>): Promise<T>;
|
|
198
|
-
/**
|
|
199
|
-
* Check if the language is plaintext that is ignored by Shiki.
|
|
200
|
-
*
|
|
201
|
-
* Hard-coded plain text languages: `plaintext`, `txt`, `text`, `plain`.
|
|
202
|
-
*/
|
|
203
|
-
declare function isPlainLang(lang: string | null | undefined): lang is PlainTextLanguage;
|
|
204
|
-
/**
|
|
205
|
-
* Check if the language is specially handled or bypassed by Shiki.
|
|
206
|
-
*
|
|
207
|
-
* Hard-coded languages: `ansi` and plaintexts like `plaintext`, `txt`, `text`, `plain`.
|
|
208
|
-
*/
|
|
209
|
-
declare function isSpecialLang(lang: any): lang is SpecialLanguage;
|
|
210
|
-
/**
|
|
211
|
-
* Check if the theme is specially handled or bypassed by Shiki.
|
|
212
|
-
*
|
|
213
|
-
* Hard-coded themes: `none`.
|
|
214
|
-
*/
|
|
215
|
-
declare function isNoneTheme(theme: string | ThemeInput | null | undefined): theme is 'none';
|
|
216
|
-
/**
|
|
217
|
-
* Check if the theme is specially handled or bypassed by Shiki.
|
|
218
|
-
*
|
|
219
|
-
* Hard-coded themes: `none`.
|
|
220
|
-
*/
|
|
221
|
-
declare function isSpecialTheme(theme: string | ThemeInput | null | undefined): theme is SpecialTheme;
|
|
222
|
-
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region src/utils/hast.d.ts
|
|
223
174
|
/**
|
|
224
175
|
* Utility to append class to a hast node
|
|
225
176
|
*
|
|
226
177
|
* If the `property.class` is a string, it will be splitted by space and converted to an array.
|
|
227
178
|
*/
|
|
228
179
|
declare function addClassToHast(node: Element, className: string | string[]): Element;
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
* Split a string into lines, each line preserves the line ending.
|
|
232
|
-
*
|
|
233
|
-
* @param code - The code string to split into lines
|
|
234
|
-
* @param preserveEnding - Whether to preserve line endings in the result
|
|
235
|
-
* @returns Array of tuples containing [line content, offset index]
|
|
236
|
-
*
|
|
237
|
-
* @example
|
|
238
|
-
* ```ts
|
|
239
|
-
* splitLines('hello\nworld', false)
|
|
240
|
-
* // => [['hello', 0], ['world', 6]]
|
|
241
|
-
*
|
|
242
|
-
* splitLines('hello\nworld', true)
|
|
243
|
-
* // => [['hello\n', 0], ['world', 6]]
|
|
244
|
-
* ```
|
|
245
|
-
*/
|
|
246
|
-
declare function splitLines(code: string, preserveEnding?: boolean): [string, number][];
|
|
180
|
+
//#endregion
|
|
181
|
+
//#region src/utils/strings.d.ts
|
|
247
182
|
/**
|
|
248
183
|
* Creates a converter between index and position in a code block.
|
|
249
184
|
*
|
|
250
185
|
* Overflow/underflow are unchecked.
|
|
251
186
|
*/
|
|
252
187
|
declare function createPositionConverter(code: string): {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
188
|
+
lines: string[];
|
|
189
|
+
indexToPos: (index: number) => Position;
|
|
190
|
+
posToIndex: (line: number, character: number) => number;
|
|
256
191
|
};
|
|
257
192
|
/**
|
|
258
193
|
* Guess embedded languages from given code and highlighter.
|
|
@@ -274,7 +209,8 @@ declare function createPositionConverter(code: string): {
|
|
|
274
209
|
* ```
|
|
275
210
|
*/
|
|
276
211
|
declare function guessEmbeddedLanguages(code: string, _lang: string | undefined, highlighter?: HighlighterGeneric<any, any>): string[];
|
|
277
|
-
|
|
212
|
+
//#endregion
|
|
213
|
+
//#region src/utils/tokens.d.ts
|
|
278
214
|
/**
|
|
279
215
|
* Split a token into multiple tokens by given offsets.
|
|
280
216
|
*
|
|
@@ -288,20 +224,5 @@ declare function splitTokens<T extends Pick<ThemedToken, 'content' | 'offset'>>(
|
|
|
288
224
|
declare function flatTokenVariants(merged: ThemedTokenWithVariants, variantsOrder: string[], cssVariablePrefix: string, defaultColor: CodeOptionsMultipleThemes['defaultColor'], colorsRendering?: CodeOptionsMultipleThemes['colorsRendering']): ThemedToken;
|
|
289
225
|
declare function getTokenStyleObject(token: TokenStyles): Record<string, string>;
|
|
290
226
|
declare function stringifyTokenStyle(token: string | Record<string, string>): string;
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
/**
|
|
294
|
-
* Enable runtime warning for deprecated APIs, for the future versions of Shiki.
|
|
295
|
-
*
|
|
296
|
-
* You can pass a major version to only warn for deprecations that will be removed in that version.
|
|
297
|
-
*
|
|
298
|
-
* By default, deprecation warning is set to 3 since Shiki v2.0.0
|
|
299
|
-
*/
|
|
300
|
-
declare function enableDeprecationWarnings(emitDeprecation?: DeprecationTarget | boolean, emitError?: boolean): void;
|
|
301
|
-
/**
|
|
302
|
-
* @internal
|
|
303
|
-
*/
|
|
304
|
-
declare function warnDeprecated(message: string, version?: DeprecationTarget): void;
|
|
305
|
-
|
|
306
|
-
export { addClassToHast, applyColorReplacements, codeToHast, codeToHtml, codeToTokens, codeToTokensBase, codeToTokensWithThemes, createBundledHighlighter, createCssVariablesTheme, createHighlighterCore, createHighlighterCoreSync, createPositionConverter, createShikiInternal, createShikiInternalSync, createSingletonShorthands, createdBundledHighlighter, enableDeprecationWarnings, flatTokenVariants, getSingletonHighlighterCore, getTokenStyleObject, guessEmbeddedLanguages, hastToHtml, isNoneTheme, isPlainLang, isSpecialLang, isSpecialTheme, makeSingletonHighlighter, makeSingletonHighlighterCore, normalizeGetter, normalizeTheme, resolveColorReplacements, splitLines, splitToken, splitTokens, stringifyTokenStyle, toArray, tokenizeAnsiWithTheme, tokenizeWithTheme, tokensToHast, transformerDecorations, warnDeprecated };
|
|
307
|
-
export type { CreateSingletonShorthandsOptions, CssVariablesThemeOptions, ShorthandsBundle };
|
|
227
|
+
//#endregion
|
|
228
|
+
export { CreateSingletonShorthandsOptions, CssVariablesThemeOptions, ShikiError, ShorthandsBundle, addClassToHast, applyColorReplacements, codeToHast, codeToHtml, codeToTokens, codeToTokensBase, codeToTokensWithThemes, createBundledHighlighter, createCssVariablesTheme, createHighlighterCore, createHighlighterCoreSync, createPositionConverter, createShikiInternal, createShikiInternalSync, createShikiPrimitive, createShikiPrimitiveAsync, createSingletonShorthands, flatTokenVariants, getLastGrammarState, getSingletonHighlighterCore, getTokenStyleObject, guessEmbeddedLanguages, hastToHtml, isNoneTheme, isPlainLang, isSpecialLang, isSpecialTheme, makeSingletonHighlighter, makeSingletonHighlighterCore, normalizeGetter, normalizeTheme, resolveColorReplacements, splitLines, splitToken, splitTokens, stringifyTokenStyle, toArray, tokenizeAnsiWithTheme, tokenizeWithTheme, tokensToHast, transformerDecorations };
|