@shikijs/core 1.16.1 → 1.16.3
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 +7 -1
- package/dist/index.d.mts +64 -60
- package/dist/index.mjs +4769 -5066
- package/dist/types.d.mts +300 -300
- package/package.json +4 -3
package/dist/chunk-engines.d.mts
CHANGED
|
@@ -49,6 +49,12 @@ interface JavaScriptRegexEngineOptions {
|
|
|
49
49
|
* Cache for regex patterns.
|
|
50
50
|
*/
|
|
51
51
|
cache?: Map<string, RegExp | Error>;
|
|
52
|
+
/**
|
|
53
|
+
* Custom pattern to RegExp constructor.
|
|
54
|
+
*
|
|
55
|
+
* By default `oniguruma-to-js` is used.
|
|
56
|
+
*/
|
|
57
|
+
regexConstructor?: (pattern: string) => RegExp;
|
|
52
58
|
}
|
|
53
59
|
|
|
54
|
-
export type { Awaitable as A, 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,
|
|
60
|
+
export type { Awaitable as A, 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, RegexEngineString as c, WebAssemblyInstance as d, LoadWasmOptionsPlain as e, MaybeModule as f };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,34 +1,11 @@
|
|
|
1
|
-
import { HighlighterCoreOptions, HighlighterCore, BundledHighlighterOptions, HighlighterGeneric, CreatedBundledHighlighterOptions, LanguageInput, ThemeInput, CodeToHastOptions, CodeToTokensOptions, TokensResult, CodeToTokensBaseOptions, ThemedToken, CodeToTokensWithThemesOptions, ThemedTokenWithVariants, GrammarState, ShikiInternal, 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, FontStyle, 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, M as MaybeArray, b as MaybeGetter } from './chunk-engines.mjs';
|
|
4
|
-
export { A as Awaitable, f as LoadWasmOptionsPlain, c as MaybeModule, O as OnigurumaLoadOptions, P as PatternScanner, d as RegexEngineString, S as StringLiteralUnion, e as WebAssemblyInstance, W as WebAssemblyInstantiator } from './chunk-engines.mjs';
|
|
5
1
|
import { Root, RootContent, Nodes, Element } from 'hast';
|
|
2
|
+
import { R as RequireKeys, L as LoadWasmOptions, J as JavaScriptRegexEngineOptions, a as RegexEngine, M as MaybeArray, b as MaybeGetter } from './chunk-engines.mjs';
|
|
3
|
+
export { A as Awaitable, e as LoadWasmOptionsPlain, f as MaybeModule, O as OnigurumaLoadOptions, P as PatternScanner, c as RegexEngineString, S as StringLiteralUnion, d as WebAssemblyInstance, W as WebAssemblyInstantiator } from './chunk-engines.mjs';
|
|
4
|
+
import { BundledHighlighterOptions, HighlighterGeneric, CreatedBundledHighlighterOptions, LanguageInput, ThemeInput, HighlighterCoreOptions, CodeToHastOptions, CodeToTokensOptions, TokensResult, CodeToTokensBaseOptions, ThemedToken, CodeToTokensWithThemesOptions, ThemedTokenWithVariants, GrammarState, HighlighterCore, ShikiInternal, ShikiTransformerContextCommon, CodeToHastRenderOptions, ShikiTransformerContextSource, ThemeRegistrationResolved, TokenizeWithThemeOptions, ThemeRegistrationAny, ShikiTransformer, PlainTextLanguage, SpecialLanguage, SpecialTheme, TokenStyles, Position } from './types.mjs';
|
|
5
|
+
export { AnsiLanguage, BundledLanguageInfo, BundledThemeInfo, CodeOptionsMeta, CodeOptionsMultipleThemes, CodeOptionsSingleTheme, CodeOptionsThemes, CodeToHastOptionsCommon, CodeToHastRenderOptionsCommon, DecorationItem, DecorationOptions, DecorationTransformType, DynamicImportLanguageRegistration, DynamicImportThemeRegistration, FontStyle, Grammar, LanguageRegistration, Offset, OffsetOrPosition, ResolveBundleKey, ResolvedDecorationItem, ResolvedPosition, ShikiTransformerContext, ShikiTransformerContextMeta, ThemeRegistration, ThemeRegistrationRaw, ThemedTokenExplanation, ThemedTokenScopeExplanation, TokenBase, TransformerOptions } from './types.mjs';
|
|
6
6
|
import { IGrammar } from '@shikijs/vscode-textmate';
|
|
7
7
|
export { IRawGrammar as RawGrammar, IRawTheme as RawTheme, IRawThemeSetting as RawThemeSetting, EncodedTokenMetadata as StackElementMetadata } from '@shikijs/vscode-textmate';
|
|
8
8
|
|
|
9
|
-
/**
|
|
10
|
-
* Create a Shiki core highlighter instance, with no languages or themes bundled.
|
|
11
|
-
* Wasm and each language and theme must be loaded manually.
|
|
12
|
-
*
|
|
13
|
-
* @see http://shiki.style/guide/bundles#fine-grained-bundle
|
|
14
|
-
*/
|
|
15
|
-
declare function createHighlighterCore(options?: HighlighterCoreOptions): Promise<HighlighterCore>;
|
|
16
|
-
/**
|
|
17
|
-
* Create a Shiki core highlighter instance, with no languages or themes bundled.
|
|
18
|
-
* Wasm and each language and theme must be loaded manually.
|
|
19
|
-
*
|
|
20
|
-
* Synchronous version of `createHighlighterCore`, which requires to provide the engine and all themes and languages upfront.
|
|
21
|
-
*
|
|
22
|
-
* @see http://shiki.style/guide/bundles#fine-grained-bundle
|
|
23
|
-
*/
|
|
24
|
-
declare function createHighlighterCoreSync(options?: HighlighterCoreOptions<true>): HighlighterCore;
|
|
25
|
-
declare function makeSingletonHighlighterCore(createHighlighter: typeof createHighlighterCore): (options?: Partial<HighlighterCoreOptions>) => Promise<HighlighterCore>;
|
|
26
|
-
declare const getSingletonHighlighterCore: (options?: Partial<HighlighterCoreOptions>) => Promise<HighlighterCore>;
|
|
27
|
-
/**
|
|
28
|
-
* @deprecated Use `createHighlighterCore` or `getSingletonHighlighterCore` instead.
|
|
29
|
-
*/
|
|
30
|
-
declare function getHighlighterCore(options?: HighlighterCoreOptions): Promise<HighlighterCore>;
|
|
31
|
-
|
|
32
9
|
type CreateHighlighterFactory<L extends string, T extends string> = (options: BundledHighlighterOptions<L, T>) => Promise<HighlighterGeneric<L, T>>;
|
|
33
10
|
/**
|
|
34
11
|
* Create a `createHighlighter` function with bundled themes, languages, and engine.
|
|
@@ -107,11 +84,27 @@ declare function makeSingletonHighlighter<L extends string, T extends string>(cr
|
|
|
107
84
|
declare function createSingletonShorthands<L extends string, T extends string>(createHighlighter: CreateHighlighterFactory<L, T>): ShorthandsBundle<L, T>;
|
|
108
85
|
|
|
109
86
|
/**
|
|
110
|
-
*
|
|
87
|
+
* Create a Shiki core highlighter instance, with no languages or themes bundled.
|
|
88
|
+
* Wasm and each language and theme must be loaded manually.
|
|
111
89
|
*
|
|
112
|
-
*
|
|
90
|
+
* @see http://shiki.style/guide/bundles#fine-grained-bundle
|
|
113
91
|
*/
|
|
114
|
-
declare function
|
|
92
|
+
declare function createHighlighterCore(options?: HighlighterCoreOptions): Promise<HighlighterCore>;
|
|
93
|
+
/**
|
|
94
|
+
* Create a Shiki core highlighter instance, with no languages or themes bundled.
|
|
95
|
+
* Wasm and each language and theme must be loaded manually.
|
|
96
|
+
*
|
|
97
|
+
* Synchronous version of `createHighlighterCore`, which requires to provide the engine and all themes and languages upfront.
|
|
98
|
+
*
|
|
99
|
+
* @see http://shiki.style/guide/bundles#fine-grained-bundle
|
|
100
|
+
*/
|
|
101
|
+
declare function createHighlighterCoreSync(options?: HighlighterCoreOptions<true>): HighlighterCore;
|
|
102
|
+
declare function makeSingletonHighlighterCore(createHighlighter: typeof createHighlighterCore): (options?: Partial<HighlighterCoreOptions>) => Promise<HighlighterCore>;
|
|
103
|
+
declare const getSingletonHighlighterCore: (options?: Partial<HighlighterCoreOptions>) => Promise<HighlighterCore>;
|
|
104
|
+
/**
|
|
105
|
+
* @deprecated Use `createHighlighterCore` or `getSingletonHighlighterCore` instead.
|
|
106
|
+
*/
|
|
107
|
+
declare function getHighlighterCore(options?: HighlighterCoreOptions): Promise<HighlighterCore>;
|
|
115
108
|
|
|
116
109
|
/**
|
|
117
110
|
* Set the default wasm loader for `loadWasm`.
|
|
@@ -127,10 +120,17 @@ declare function createShikiInternal(options?: HighlighterCoreOptions): Promise<
|
|
|
127
120
|
*/
|
|
128
121
|
declare function getShikiInternal(options?: HighlighterCoreOptions): Promise<ShikiInternal>;
|
|
129
122
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
123
|
+
/**
|
|
124
|
+
* Get the minimal shiki context for rendering.
|
|
125
|
+
*
|
|
126
|
+
* Synchronous version of `createShikiInternal`, which requires to provide the engine and all themes and languages upfront.
|
|
127
|
+
*/
|
|
128
|
+
declare function createShikiInternalSync(options: HighlighterCoreOptions<true>): ShikiInternal;
|
|
133
129
|
|
|
130
|
+
/**
|
|
131
|
+
* The default RegExp constructor for JavaScript regex engine.
|
|
132
|
+
*/
|
|
133
|
+
declare function defaultJavaScriptRegexConstructor(pattern: string): RegExp;
|
|
134
134
|
/**
|
|
135
135
|
* Use the modern JavaScript RegExp engine to implement the OnigScanner.
|
|
136
136
|
*
|
|
@@ -142,25 +142,13 @@ declare function createWasmOnigEngine(options?: LoadWasmOptions | null): Promise
|
|
|
142
142
|
*/
|
|
143
143
|
declare function createJavaScriptRegexEngine(options?: JavaScriptRegexEngineOptions): RegexEngine;
|
|
144
144
|
|
|
145
|
-
|
|
146
|
-
* Normalize a textmate theme to shiki theme
|
|
147
|
-
*/
|
|
148
|
-
declare function normalizeTheme(rawTheme: ThemeRegistrationAny): ThemeRegistrationResolved;
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Code to tokens, with a simple theme.
|
|
152
|
-
*/
|
|
153
|
-
declare function codeToTokensBase(internal: ShikiInternal, code: string, options?: CodeToTokensBaseOptions): ThemedToken[][];
|
|
154
|
-
declare function tokenizeWithTheme(code: string, grammar: IGrammar, theme: ThemeRegistrationResolved, colorMap: string[], options: TokenizeWithThemeOptions): ThemedToken[][];
|
|
145
|
+
declare function loadWasm(options: LoadWasmOptions): Promise<void>;
|
|
155
146
|
|
|
156
|
-
|
|
157
|
-
* High-level code-to-tokens API.
|
|
158
|
-
*
|
|
159
|
-
* It will use `codeToTokensWithThemes` or `codeToTokensBase` based on the options.
|
|
160
|
-
*/
|
|
161
|
-
declare function codeToTokens(internal: ShikiInternal, code: string, options: CodeToTokensOptions): TokensResult;
|
|
147
|
+
declare function createWasmOnigEngine(options?: LoadWasmOptions | null): Promise<RegexEngine>;
|
|
162
148
|
|
|
163
|
-
declare
|
|
149
|
+
declare class ShikiError extends Error {
|
|
150
|
+
constructor(message: string);
|
|
151
|
+
}
|
|
164
152
|
|
|
165
153
|
declare function codeToHast(internal: ShikiInternal, code: string, options: CodeToHastOptions, transformerContext?: ShikiTransformerContextCommon): Root;
|
|
166
154
|
declare function tokensToHast(tokens: ThemedToken[][], options: CodeToHastRenderOptions, transformerContext: ShikiTransformerContextSource): Root;
|
|
@@ -389,11 +377,36 @@ type Space = "html" | "svg";
|
|
|
389
377
|
*/
|
|
390
378
|
declare function codeToHtml(internal: ShikiInternal, code: string, options: CodeToHastOptions): string;
|
|
391
379
|
|
|
380
|
+
/**
|
|
381
|
+
* High-level code-to-tokens API.
|
|
382
|
+
*
|
|
383
|
+
* It will use `codeToTokensWithThemes` or `codeToTokensBase` based on the options.
|
|
384
|
+
*/
|
|
385
|
+
declare function codeToTokens(internal: ShikiInternal, code: string, options: CodeToTokensOptions): TokensResult;
|
|
386
|
+
|
|
387
|
+
declare function tokenizeAnsiWithTheme(theme: ThemeRegistrationResolved, fileContents: string, options?: TokenizeWithThemeOptions): ThemedToken[][];
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Code to tokens, with a simple theme.
|
|
391
|
+
*/
|
|
392
|
+
declare function codeToTokensBase(internal: ShikiInternal, code: string, options?: CodeToTokensBaseOptions): ThemedToken[][];
|
|
393
|
+
declare function tokenizeWithTheme(code: string, grammar: IGrammar, theme: ThemeRegistrationResolved, colorMap: string[], options: TokenizeWithThemeOptions): ThemedToken[][];
|
|
394
|
+
|
|
392
395
|
/**
|
|
393
396
|
* Get tokens with multiple themes
|
|
394
397
|
*/
|
|
395
398
|
declare function codeToTokensWithThemes(internal: ShikiInternal, code: string, options: CodeToTokensWithThemesOptions): ThemedTokenWithVariants[][];
|
|
396
399
|
|
|
400
|
+
/**
|
|
401
|
+
* Normalize a textmate theme to shiki theme
|
|
402
|
+
*/
|
|
403
|
+
declare function normalizeTheme(rawTheme: ThemeRegistrationAny): ThemeRegistrationResolved;
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* A built-in transformer to add decorations to the highlighted code.
|
|
407
|
+
*/
|
|
408
|
+
declare function transformerDecorations(): ShikiTransformer;
|
|
409
|
+
|
|
397
410
|
declare function toArray<T>(x: MaybeArray<T>): T[];
|
|
398
411
|
/**
|
|
399
412
|
* Split a string into lines, each line preserves the line ending.
|
|
@@ -461,13 +474,4 @@ declare function createPositionConverter(code: string): {
|
|
|
461
474
|
posToIndex: (line: number, character: number) => number;
|
|
462
475
|
};
|
|
463
476
|
|
|
464
|
-
|
|
465
|
-
* A built-in transformer to add decorations to the highlighted code.
|
|
466
|
-
*/
|
|
467
|
-
declare function transformerDecorations(): ShikiTransformer;
|
|
468
|
-
|
|
469
|
-
declare class ShikiError extends Error {
|
|
470
|
-
constructor(message: string);
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
export { BundledHighlighterOptions, CodeToHastOptions, CodeToHastRenderOptions, CodeToTokensBaseOptions, CodeToTokensOptions, CodeToTokensWithThemesOptions, type CreateHighlighterFactory, CreatedBundledHighlighterOptions, GrammarState, HighlighterCore, HighlighterCoreOptions, HighlighterGeneric, JavaScriptRegexEngineOptions, LanguageInput, LoadWasmOptions, MaybeArray, MaybeGetter, PlainTextLanguage, Position, RegexEngine, 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, 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 };
|
|
477
|
+
export { BundledHighlighterOptions, CodeToHastOptions, CodeToHastRenderOptions, CodeToTokensBaseOptions, CodeToTokensOptions, CodeToTokensWithThemesOptions, type CreateHighlighterFactory, CreatedBundledHighlighterOptions, GrammarState, HighlighterCore, HighlighterCoreOptions, HighlighterGeneric, JavaScriptRegexEngineOptions, LanguageInput, LoadWasmOptions, MaybeArray, MaybeGetter, PlainTextLanguage, Position, RegexEngine, 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, createHighlighterCoreSync, createJavaScriptRegexEngine, createPositionConverter, createShikiInternal, createShikiInternalSync, createSingletonShorthands, createWasmOnigEngine, createdBundledHighlighter, defaultJavaScriptRegexConstructor, 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 };
|