@shikijs/core 1.0.0-beta.5 → 1.0.0-rc.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-tokens.d.mts +9 -28
- package/dist/index.d.mts +13 -22
- package/dist/index.mjs +26 -40
- package/dist/types.d.mts +51 -57
- package/package.json +1 -1
package/dist/chunk-tokens.d.mts
CHANGED
|
@@ -814,59 +814,40 @@ interface ShikiTransformer {
|
|
|
814
814
|
/**
|
|
815
815
|
* Transform the raw input code before passing to the highlighter.
|
|
816
816
|
*/
|
|
817
|
-
preprocess
|
|
817
|
+
preprocess?: (this: ShikiTransformerContextCommon, code: string, options: CodeToHastOptions) => string | void;
|
|
818
818
|
/**
|
|
819
819
|
* Transform the full tokens list before converting to HAST.
|
|
820
820
|
* Return a new tokens list will replace the original one.
|
|
821
821
|
*/
|
|
822
|
-
tokens
|
|
822
|
+
tokens?: (this: ShikiTransformerContextSource, tokens: ThemedToken[][]) => ThemedToken[][] | void;
|
|
823
823
|
/**
|
|
824
824
|
* Transform the entire generated HAST tree. Return a new Node will replace the original one.
|
|
825
825
|
*/
|
|
826
|
-
root
|
|
826
|
+
root?: (this: ShikiTransformerContext, hast: Root) => Root | void;
|
|
827
827
|
/**
|
|
828
828
|
* Transform the `<pre>` element. Return a new Node will replace the original one.
|
|
829
829
|
*/
|
|
830
|
-
pre
|
|
830
|
+
pre?: (this: ShikiTransformerContext, hast: Element) => Element | void;
|
|
831
831
|
/**
|
|
832
832
|
* Transform the `<code>` element. Return a new Node will replace the original one.
|
|
833
833
|
*/
|
|
834
|
-
code
|
|
834
|
+
code?: (this: ShikiTransformerContext, hast: Element) => Element | void;
|
|
835
835
|
/**
|
|
836
836
|
* Transform each line `<span class="line">` element.
|
|
837
837
|
*
|
|
838
838
|
* @param hast
|
|
839
839
|
* @param line 1-based line number
|
|
840
840
|
*/
|
|
841
|
-
line
|
|
841
|
+
line?: (this: ShikiTransformerContext, hast: Element, line: number) => Element | void;
|
|
842
842
|
/**
|
|
843
843
|
* Transform each token `<span>` element.
|
|
844
844
|
*/
|
|
845
|
-
span
|
|
845
|
+
span?: (this: ShikiTransformerContext, hast: Element, line: number, col: number, lineElement: Element) => Element | void;
|
|
846
846
|
/**
|
|
847
847
|
* Transform the generated HTML string before returning.
|
|
848
848
|
* This hook will only be called with `codeToHtml`.
|
|
849
849
|
*/
|
|
850
|
-
postprocess
|
|
851
|
-
/**
|
|
852
|
-
* @deprecated Use `span` instead
|
|
853
|
-
*/
|
|
854
|
-
token?(this: ShikiTransformerContext, hast: Element, line: number, col: number, lineElement: Element): Element | void;
|
|
855
|
-
}
|
|
856
|
-
/**
|
|
857
|
-
* @deprecated Rnamed to `ShikiTransformer`
|
|
858
|
-
*/
|
|
859
|
-
interface ShikijiTransformer extends ShikiTransformer {
|
|
860
|
-
}
|
|
861
|
-
/**
|
|
862
|
-
* @deprecated Rnamed to `ShikiTransformerContext`
|
|
863
|
-
*/
|
|
864
|
-
interface ShikijiTransformerContext extends ShikiTransformerContext {
|
|
865
|
-
}
|
|
866
|
-
/**
|
|
867
|
-
* @deprecated Rnamed to `ShikiTransformerContextCommon`
|
|
868
|
-
*/
|
|
869
|
-
interface ShikijiTransformerContextCommon extends ShikiTransformerContextCommon {
|
|
850
|
+
postprocess?: (this: ShikiTransformerContextCommon, html: string, options: CodeToHastOptions) => string | void;
|
|
870
851
|
}
|
|
871
852
|
|
|
872
853
|
interface DecorationOptions {
|
|
@@ -1235,4 +1216,4 @@ declare enum FontStyle {
|
|
|
1235
1216
|
Underline = 4
|
|
1236
1217
|
}
|
|
1237
1218
|
|
|
1238
|
-
export { type DynamicImportThemeRegistration as $, type
|
|
1219
|
+
export { type DynamicImportThemeRegistration as $, type ShikiTransformer as A, type BundledHighlighterOptions as B, type CodeToHastOptions as C, type AnsiLanguage as D, type Element as E, FontStyle as F, type ResolveBundleKey as G, type HighlighterCoreOptions as H, INITIAL as I, type LanguageRegistration as J, type BundledLanguageInfo as K, type LanguageInput as L, type MaybeArray as M, type Nodes as N, type DynamicImportLanguageRegistration as O, type PlainTextLanguage as P, type CodeOptionsSingleTheme as Q, Registry as R, type StateStack as S, type ThemeInput as T, type CodeOptionsMultipleThemes as U, type CodeOptionsThemes as V, type CodeToHastOptionsCommon as W, type CodeOptionsMeta as X, type CodeToHastRenderOptionsCommon as Y, type ThemeRegistrationRaw as Z, type ThemeRegistration as _, type IRawTheme as a, type BundledThemeInfo as a0, type ThemedTokenScopeExplanation as a1, type ThemedTokenExplanation as a2, type TokenBase as a3, type TransformerOptions as a4, type ShikiTransformerContextMeta as a5, type ShikiTransformerContext as a6, type Awaitable as a7, type MaybeGetter as a8, type MaybeModule as a9, type StringLiteralUnion as aa, type DecorationOptions as ab, type DecorationItem as ac, type ResolvedDecorationItem as ad, type DecorationTransformType as ae, type Offset as af, type OffsetOrPosition as ag, type ResolvedPosition as ah, type IRawGrammar as b, type IGrammar as c, type IGrammarConfiguration as d, type IOnigLib as e, type RegistryOptions as f, type IRawThemeSetting as g, type Root as h, type CodeToTokensOptions as i, type TokensResult as j, type RequireKeys as k, type CodeToTokensBaseOptions as l, type ThemedToken as m, type CodeToTokensWithThemesOptions as n, type ThemedTokenWithVariants as o, type SpecialLanguage as p, type SpecialTheme as q, type TokenStyles as r, type Position as s, type ThemeRegistrationResolved as t, type TokenizeWithThemeOptions as u, type ShikiTransformerContextCommon as v, type CodeToHastRenderOptions as w, type ShikiTransformerContextSource as x, type RootContent as y, type ThemeRegistrationAny as z };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { HighlighterGeneric, ShikiInternal } from './types.mjs';
|
|
2
|
-
import { H as HighlighterCoreOptions, B as BundledHighlighterOptions, L as LanguageInput, T as ThemeInput, C as CodeToHastOptions, h as Root, i as CodeToTokensOptions, j as TokensResult, k as RequireKeys, l as CodeToTokensBaseOptions, m as ThemedToken, n as CodeToTokensWithThemesOptions, o as ThemedTokenWithVariants, M as MaybeArray, p as SpecialTheme, E as Element,
|
|
3
|
-
export {
|
|
1
|
+
import { HighlighterCore, HighlighterGeneric, ShikiInternal } from './types.mjs';
|
|
2
|
+
import { H as HighlighterCoreOptions, B as BundledHighlighterOptions, L as LanguageInput, T as ThemeInput, C as CodeToHastOptions, h as Root, i as CodeToTokensOptions, j as TokensResult, k as RequireKeys, l as CodeToTokensBaseOptions, m as ThemedToken, n as CodeToTokensWithThemesOptions, o as ThemedTokenWithVariants, M as MaybeArray, P as PlainTextLanguage, p as SpecialLanguage, q as SpecialTheme, E as Element, r as TokenStyles, s as Position, c as IGrammar, t as ThemeRegistrationResolved, u as TokenizeWithThemeOptions, v as ShikiTransformerContextCommon, w as CodeToHastRenderOptions, x as ShikiTransformerContextSource, N as Nodes$1, y as RootContent$1, z as ThemeRegistrationAny, A as ShikiTransformer } from './chunk-tokens.mjs';
|
|
3
|
+
export { D as AnsiLanguage, a7 as Awaitable, K as BundledLanguageInfo, a0 as BundledThemeInfo, X as CodeOptionsMeta, U as CodeOptionsMultipleThemes, Q as CodeOptionsSingleTheme, V as CodeOptionsThemes, W as CodeToHastOptionsCommon, Y as CodeToHastRenderOptionsCommon, ac as DecorationItem, ab as DecorationOptions, ae as DecorationTransformType, O as DynamicImportLanguageRegistration, $ as DynamicImportThemeRegistration, F as FontStyle, J as LanguageRegistration, a8 as MaybeGetter, a9 as MaybeModule, af as Offset, ag as OffsetOrPosition, b as RawGrammar, a as RawTheme, g as RawThemeSetting, G as ResolveBundleKey, ad as ResolvedDecorationItem, ah as ResolvedPosition, a6 as ShikiTransformerContext, a5 as ShikiTransformerContextMeta, aa as StringLiteralUnion, _ as ThemeRegistration, Z as ThemeRegistrationRaw, a2 as ThemedTokenExplanation, a1 as ThemedTokenScopeExplanation, a3 as TokenBase, a4 as TransformerOptions } from './chunk-tokens.mjs';
|
|
4
4
|
import { L as LoadWasmOptions } from './chunk-index.mjs';
|
|
5
5
|
export { l as loadWasm } from './chunk-index.mjs';
|
|
6
6
|
|
|
7
|
-
type HighlighterCore = HighlighterGeneric<never, never>;
|
|
8
7
|
/**
|
|
9
8
|
* Create a Shiki core highlighter instance, with no languages or themes bundled.
|
|
10
9
|
* Wasm and each language and theme must be loaded manually.
|
|
@@ -29,45 +28,41 @@ interface ShorthandsBundle<L extends string, T extends string> {
|
|
|
29
28
|
*
|
|
30
29
|
* Differences from `highlighter.codeToHtml()`, this function is async.
|
|
31
30
|
*/
|
|
32
|
-
codeToHtml(code: string, options: CodeToHastOptions<L, T>)
|
|
31
|
+
codeToHtml: (code: string, options: CodeToHastOptions<L, T>) => Promise<string>;
|
|
33
32
|
/**
|
|
34
33
|
* Shorthand for `codeToHtml` with auto-loaded theme and language.
|
|
35
34
|
* A singleton highlighter it maintained internally.
|
|
36
35
|
*
|
|
37
36
|
* Differences from `highlighter.codeToHtml()`, this function is async.
|
|
38
37
|
*/
|
|
39
|
-
codeToHast(code: string, options: CodeToHastOptions<L, T>)
|
|
38
|
+
codeToHast: (code: string, options: CodeToHastOptions<L, T>) => Promise<Root>;
|
|
40
39
|
/**
|
|
41
40
|
* Shorthand for `codeToTokens` with auto-loaded theme and language.
|
|
42
41
|
* A singleton highlighter it maintained internally.
|
|
43
42
|
*
|
|
44
43
|
* Differences from `highlighter.codeToTokens()`, this function is async.
|
|
45
44
|
*/
|
|
46
|
-
codeToTokens(code: string, options: CodeToTokensOptions<L, T>)
|
|
45
|
+
codeToTokens: (code: string, options: CodeToTokensOptions<L, T>) => Promise<TokensResult>;
|
|
47
46
|
/**
|
|
48
47
|
* Shorthand for `codeToTokensBase` with auto-loaded theme and language.
|
|
49
48
|
* A singleton highlighter it maintained internally.
|
|
50
49
|
*
|
|
51
50
|
* Differences from `highlighter.codeToTokensBase()`, this function is async.
|
|
52
51
|
*/
|
|
53
|
-
codeToTokensBase(code: string, options: RequireKeys<CodeToTokensBaseOptions<L, T>, 'theme' | 'lang'>)
|
|
52
|
+
codeToTokensBase: (code: string, options: RequireKeys<CodeToTokensBaseOptions<L, T>, 'theme' | 'lang'>) => Promise<ThemedToken[][]>;
|
|
54
53
|
/**
|
|
55
54
|
* Shorthand for `codeToTokensWithThemes` with auto-loaded theme and language.
|
|
56
55
|
* A singleton highlighter it maintained internally.
|
|
57
56
|
*
|
|
58
57
|
* Differences from `highlighter.codeToTokensWithThemes()`, this function is async.
|
|
59
58
|
*/
|
|
60
|
-
codeToTokensWithThemes(code: string, options: RequireKeys<CodeToTokensWithThemesOptions<L, T>, 'themes' | 'lang'>)
|
|
59
|
+
codeToTokensWithThemes: (code: string, options: RequireKeys<CodeToTokensWithThemesOptions<L, T>, 'themes' | 'lang'>) => Promise<ThemedTokenWithVariants[][]>;
|
|
61
60
|
/**
|
|
62
61
|
* Get internal singleton highlighter.
|
|
63
62
|
*
|
|
64
63
|
* @internal
|
|
65
64
|
*/
|
|
66
|
-
getSingletonHighlighter()
|
|
67
|
-
/**
|
|
68
|
-
* @deprecated Use `codeToTokensBase` instead.
|
|
69
|
-
*/
|
|
70
|
-
codeToThemedTokens(code: string, options: RequireKeys<CodeToTokensBaseOptions<L, T>, 'theme' | 'lang'>): Promise<ThemedToken[][]>;
|
|
65
|
+
getSingletonHighlighter: () => Promise<HighlighterGeneric<L, T>>;
|
|
71
66
|
}
|
|
72
67
|
declare function createSingletonShorthands<L extends string, T extends string>(getHighlighter: GetHighlighterFactory<L, T>): ShorthandsBundle<L, T>;
|
|
73
68
|
|
|
@@ -75,19 +70,19 @@ declare function toArray<T>(x: MaybeArray<T>): T[];
|
|
|
75
70
|
/**
|
|
76
71
|
* Slipt a string into lines, each line preserves the line ending.
|
|
77
72
|
*/
|
|
78
|
-
declare function splitLines(
|
|
73
|
+
declare function splitLines(code: string, preserveEnding?: boolean): [string, number][];
|
|
79
74
|
/**
|
|
80
75
|
* Check if the language is plaintext that is ignored by Shiki.
|
|
81
76
|
*
|
|
82
77
|
* Hard-coded plain text languages: `plaintext`, `txt`, `text`, `plain`.
|
|
83
78
|
*/
|
|
84
|
-
declare function isPlainLang(lang: string | null | undefined):
|
|
79
|
+
declare function isPlainLang(lang: string | null | undefined): lang is PlainTextLanguage;
|
|
85
80
|
/**
|
|
86
81
|
* Check if the language is specially handled or bypassed by Shiki.
|
|
87
82
|
*
|
|
88
83
|
* Hard-coded languages: `ansi` and plaintexts like `plaintext`, `txt`, `text`, `plain`.
|
|
89
84
|
*/
|
|
90
|
-
declare function isSpecialLang(lang:
|
|
85
|
+
declare function isSpecialLang(lang: any): lang is SpecialLanguage;
|
|
91
86
|
/**
|
|
92
87
|
* Check if the theme is specially handled or bypassed by Shiki.
|
|
93
88
|
*
|
|
@@ -117,10 +112,6 @@ declare function splitToken<T extends Pick<ThemedToken, 'content' | 'offset'>>(t
|
|
|
117
112
|
*/
|
|
118
113
|
declare function splitTokens<T extends Pick<ThemedToken, 'content' | 'offset'>>(tokens: T[][], breakpoints: number[] | Set<number>): T[][];
|
|
119
114
|
declare function applyColorReplacements(color: string, replacements?: Record<string, string>): string;
|
|
120
|
-
/**
|
|
121
|
-
* @deprecated Use `isPlainLang` instead.
|
|
122
|
-
*/
|
|
123
|
-
declare const isPlaintext: typeof isPlainLang;
|
|
124
115
|
declare function getTokenStyleObject(token: TokenStyles): Record<string, string>;
|
|
125
116
|
declare function stringifyTokenStyle(token: Record<string, string>): string;
|
|
126
117
|
/**
|
|
@@ -406,4 +397,4 @@ declare class ShikiError extends Error {
|
|
|
406
397
|
constructor(message: string);
|
|
407
398
|
}
|
|
408
399
|
|
|
409
|
-
export { BundledHighlighterOptions, CodeToHastOptions, CodeToHastRenderOptions, CodeToTokensBaseOptions, CodeToTokensOptions, CodeToTokensWithThemesOptions, type GetHighlighterFactory, IGrammar as Grammar,
|
|
400
|
+
export { BundledHighlighterOptions, CodeToHastOptions, CodeToHastRenderOptions, CodeToTokensBaseOptions, CodeToTokensOptions, CodeToTokensWithThemesOptions, type GetHighlighterFactory, IGrammar as Grammar, HighlighterCore, HighlighterCoreOptions, HighlighterGeneric, LanguageInput, 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, createPositionConverter, createSingletonShorthands, createdBundledHighlighter, getHighlighterCore, getShikiInternal, getTokenStyleObject, toHtml as hastToHtml, isNoneTheme, isPlainLang, isSpecialLang, isSpecialTheme, normalizeTheme, setDefaultWasmLoader, splitLines, splitToken, splitTokens, stringifyTokenStyle, toArray, tokenizeAnsiWithTheme, tokenizeWithTheme, tokensToHast, transformerDecorations };
|
package/dist/index.mjs
CHANGED
|
@@ -7,8 +7,19 @@ function toArray(x) {
|
|
|
7
7
|
/**
|
|
8
8
|
* Slipt a string into lines, each line preserves the line ending.
|
|
9
9
|
*/
|
|
10
|
-
function splitLines(
|
|
11
|
-
|
|
10
|
+
function splitLines(code, preserveEnding = false) {
|
|
11
|
+
const parts = code.split(/(\r?\n)/g);
|
|
12
|
+
let index = 0;
|
|
13
|
+
const lines = [];
|
|
14
|
+
for (let i = 0; i < parts.length; i += 2) {
|
|
15
|
+
const line = preserveEnding
|
|
16
|
+
? parts[i] + (parts[i + 1] || '')
|
|
17
|
+
: parts[i];
|
|
18
|
+
lines.push([line, index]);
|
|
19
|
+
index += parts[i].length;
|
|
20
|
+
index += parts[i + 1]?.length || 0;
|
|
21
|
+
}
|
|
22
|
+
return lines;
|
|
12
23
|
}
|
|
13
24
|
/**
|
|
14
25
|
* Check if the language is plaintext that is ignored by Shiki.
|
|
@@ -113,10 +124,6 @@ function splitTokens(tokens, breakpoints) {
|
|
|
113
124
|
function applyColorReplacements(color, replacements) {
|
|
114
125
|
return replacements?.[color.toLowerCase()] || color;
|
|
115
126
|
}
|
|
116
|
-
/**
|
|
117
|
-
* @deprecated Use `isPlainLang` instead.
|
|
118
|
-
*/
|
|
119
|
-
const isPlaintext = isPlainLang;
|
|
120
127
|
function getTokenStyleObject(token) {
|
|
121
128
|
const styles = {};
|
|
122
129
|
if (token.color)
|
|
@@ -140,7 +147,7 @@ function stringifyTokenStyle(token) {
|
|
|
140
147
|
* Creates a converter between index and position in a code block.
|
|
141
148
|
*/
|
|
142
149
|
function createPositionConverter(code) {
|
|
143
|
-
const lines =
|
|
150
|
+
const lines = splitLines(code, true).map(([line]) => line);
|
|
144
151
|
function indexToPos(index) {
|
|
145
152
|
let character = index;
|
|
146
153
|
let line = 0;
|
|
@@ -509,7 +516,7 @@ function codeToTokensBase(internal, code, options = {}) {
|
|
|
509
516
|
const { theme, colorMap } = internal.setTheme(themeName);
|
|
510
517
|
if (lang === 'ansi')
|
|
511
518
|
return tokenizeAnsiWithTheme(theme, code, options);
|
|
512
|
-
const _grammar = internal.
|
|
519
|
+
const _grammar = internal.getLanguage(lang);
|
|
513
520
|
return tokenizeWithTheme(code, _grammar, theme, colorMap, options);
|
|
514
521
|
}
|
|
515
522
|
function tokenizeWithTheme(code, grammar, theme, colorMap, options) {
|
|
@@ -871,8 +878,8 @@ function transformerDecorations() {
|
|
|
871
878
|
return;
|
|
872
879
|
const ctx = getContext(this);
|
|
873
880
|
const lines = Array.from(codeEl.children).filter(i => i.type === 'element' && i.tagName === 'span');
|
|
874
|
-
|
|
875
|
-
|
|
881
|
+
if (lines.length !== ctx.converter.lines.length)
|
|
882
|
+
throw new ShikiError(`Number of lines in code element (${lines.length}) does not match the number of lines in the source (${ctx.converter.lines.length}). Failed to apply decorations.`);
|
|
876
883
|
function applyLineSection(line, start, end, decoration) {
|
|
877
884
|
const lineEl = lines[line];
|
|
878
885
|
let text = '';
|
|
@@ -1075,7 +1082,7 @@ function tokensToHast(tokens, options, transformerContext) {
|
|
|
1075
1082
|
if (style)
|
|
1076
1083
|
tokenNode.properties.style = style;
|
|
1077
1084
|
for (const transformer of transformers)
|
|
1078
|
-
tokenNode =
|
|
1085
|
+
tokenNode = transformer?.span?.call(context, tokenNode, idx + 1, col, lineNode) || tokenNode;
|
|
1079
1086
|
lineNode.children.push(tokenNode);
|
|
1080
1087
|
col += token.content.length;
|
|
1081
1088
|
}
|
|
@@ -5249,7 +5256,9 @@ async function getShikiInternal(options = {}) {
|
|
|
5249
5256
|
return Promise.resolve(typeof p === 'function' ? p() : p).then(r => r.default || r);
|
|
5250
5257
|
}
|
|
5251
5258
|
async function resolveLangs(langs) {
|
|
5252
|
-
return Array.from(new Set((await Promise.all(langs
|
|
5259
|
+
return Array.from(new Set((await Promise.all(langs
|
|
5260
|
+
.filter(l => !isSpecialLang(l))
|
|
5261
|
+
.map(async (lang) => await normalizeGetter(lang).then(r => Array.isArray(r) ? r : [r])))).flat()));
|
|
5253
5262
|
}
|
|
5254
5263
|
const wasmLoader = options.loadWasm || _defaultWasmLoader;
|
|
5255
5264
|
const [themes, langs,] = await Promise.all([
|
|
@@ -5269,8 +5278,8 @@ async function getShikiInternal(options = {}) {
|
|
|
5269
5278
|
Object.assign(_registry.alias, options.langAlias);
|
|
5270
5279
|
await _registry.init();
|
|
5271
5280
|
let _lastTheme;
|
|
5272
|
-
function
|
|
5273
|
-
const _lang = _registry.getGrammar(name);
|
|
5281
|
+
function getLanguage(name) {
|
|
5282
|
+
const _lang = _registry.getGrammar(typeof name === 'string' ? name : name.name);
|
|
5274
5283
|
if (!_lang)
|
|
5275
5284
|
throw new ShikiError(`Language \`${name}\` not found, you may need to load it first`);
|
|
5276
5285
|
return _lang;
|
|
@@ -5309,20 +5318,12 @@ async function getShikiInternal(options = {}) {
|
|
|
5309
5318
|
? null
|
|
5310
5319
|
: _registry.loadTheme(await normalizeGetter(theme))));
|
|
5311
5320
|
}
|
|
5312
|
-
function updateAlias(alias) {
|
|
5313
|
-
Object.assign(_registry.alias, alias);
|
|
5314
|
-
}
|
|
5315
|
-
function getAlias() {
|
|
5316
|
-
return _registry.alias;
|
|
5317
|
-
}
|
|
5318
5321
|
return {
|
|
5319
5322
|
setTheme,
|
|
5320
5323
|
getTheme,
|
|
5321
|
-
|
|
5324
|
+
getLanguage,
|
|
5322
5325
|
getLoadedThemes,
|
|
5323
5326
|
getLoadedLanguages,
|
|
5324
|
-
getAlias,
|
|
5325
|
-
updateAlias,
|
|
5326
5327
|
loadLanguage,
|
|
5327
5328
|
loadTheme,
|
|
5328
5329
|
};
|
|
@@ -5342,16 +5343,8 @@ async function getHighlighterCore(options = {}) {
|
|
|
5342
5343
|
codeToTokens: (code, options) => codeToTokens(internal, code, options),
|
|
5343
5344
|
codeToHast: (code, options) => codeToHast(internal, code, options),
|
|
5344
5345
|
codeToHtml: (code, options) => codeToHtml(internal, code, options),
|
|
5345
|
-
|
|
5346
|
-
loadTheme: internal.loadTheme,
|
|
5347
|
-
getTheme: internal.getTheme,
|
|
5348
|
-
getLangGrammar: internal.getLangGrammar,
|
|
5349
|
-
setTheme: internal.setTheme,
|
|
5350
|
-
getLoadedThemes: internal.getLoadedThemes,
|
|
5351
|
-
getLoadedLanguages: internal.getLoadedLanguages,
|
|
5346
|
+
...internal,
|
|
5352
5347
|
getInternalContext: () => internal,
|
|
5353
|
-
/** @deprecated */
|
|
5354
|
-
codeToThemedTokens: (code, options) => codeToTokensBase(internal, code, options),
|
|
5355
5348
|
};
|
|
5356
5349
|
}
|
|
5357
5350
|
|
|
@@ -5453,13 +5446,6 @@ function createSingletonShorthands(getHighlighter) {
|
|
|
5453
5446
|
const shiki = await _getHighlighter(options);
|
|
5454
5447
|
return shiki.codeToTokensBase(code, options);
|
|
5455
5448
|
},
|
|
5456
|
-
/**
|
|
5457
|
-
* @deprecated Use `codeToTokensBase` instead.
|
|
5458
|
-
*/
|
|
5459
|
-
async codeToThemedTokens(code, options) {
|
|
5460
|
-
const shiki = await _getHighlighter(options);
|
|
5461
|
-
return shiki.codeToThemedTokens(code, options);
|
|
5462
|
-
},
|
|
5463
5449
|
async codeToTokensWithThemes(code, options) {
|
|
5464
5450
|
const shiki = await _getHighlighter({
|
|
5465
5451
|
lang: options.lang,
|
|
@@ -5470,4 +5456,4 @@ function createSingletonShorthands(getHighlighter) {
|
|
|
5470
5456
|
};
|
|
5471
5457
|
}
|
|
5472
5458
|
|
|
5473
|
-
export { FontStyle, ShikiError, addClassToHast, applyColorReplacements, codeToHast, codeToHtml, codeToTokens, codeToTokensBase, codeToTokensWithThemes, createPositionConverter, createSingletonShorthands, createdBundledHighlighter, getHighlighterCore, getShikiInternal, getTokenStyleObject, toHtml as hastToHtml, isNoneTheme, isPlainLang,
|
|
5459
|
+
export { FontStyle, ShikiError, addClassToHast, applyColorReplacements, codeToHast, codeToHtml, codeToTokens, codeToTokensBase, codeToTokensWithThemes, createPositionConverter, createSingletonShorthands, createdBundledHighlighter, getHighlighterCore, getShikiInternal, getTokenStyleObject, toHtml as hastToHtml, isNoneTheme, isPlainLang, isSpecialLang, isSpecialTheme, loadWasm, normalizeTheme, setDefaultWasmLoader, splitLines, splitToken, splitTokens, stringifyTokenStyle, toArray, tokenizeAnsiWithTheme, tokenizeWithTheme, tokensToHast, transformerDecorations };
|
package/dist/types.d.mts
CHANGED
|
@@ -1,94 +1,88 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { T as ThemeInput, q as SpecialTheme, L as LanguageInput, p as SpecialLanguage, z as ThemeRegistrationAny, t as ThemeRegistrationResolved, J as LanguageRegistration, c as IGrammar, C as CodeToHastOptions, G as ResolveBundleKey, h as Root, i as CodeToTokensOptions, j as TokensResult, l as CodeToTokensBaseOptions, m as ThemedToken, n as CodeToTokensWithThemesOptions, o as ThemedTokenWithVariants } from './chunk-tokens.mjs';
|
|
2
|
+
export { D as AnsiLanguage, a7 as Awaitable, B as BundledHighlighterOptions, K as BundledLanguageInfo, a0 as BundledThemeInfo, X as CodeOptionsMeta, U as CodeOptionsMultipleThemes, Q as CodeOptionsSingleTheme, V as CodeOptionsThemes, W as CodeToHastOptionsCommon, w as CodeToHastRenderOptions, Y as CodeToHastRenderOptionsCommon, ac as DecorationItem, ab as DecorationOptions, ae as DecorationTransformType, O as DynamicImportLanguageRegistration, $ as DynamicImportThemeRegistration, F as FontStyle, H as HighlighterCoreOptions, M as MaybeArray, a8 as MaybeGetter, a9 as MaybeModule, af as Offset, ag as OffsetOrPosition, P as PlainTextLanguage, s as Position, b as RawGrammar, a as RawTheme, g as RawThemeSetting, k as RequireKeys, ad as ResolvedDecorationItem, ah as ResolvedPosition, A as ShikiTransformer, a6 as ShikiTransformerContext, v as ShikiTransformerContextCommon, a5 as ShikiTransformerContextMeta, x as ShikiTransformerContextSource, aa as StringLiteralUnion, _ as ThemeRegistration, Z as ThemeRegistrationRaw, a2 as ThemedTokenExplanation, a1 as ThemedTokenScopeExplanation, a3 as TokenBase, r as TokenStyles, u as TokenizeWithThemeOptions, a4 as TransformerOptions } from './chunk-tokens.mjs';
|
|
3
3
|
import './chunk-index.mjs';
|
|
4
4
|
|
|
5
|
-
interface ShikiInternal {
|
|
6
|
-
setTheme(name: string | ThemeRegistrationAny): {
|
|
7
|
-
theme: ThemeRegistrationResolved;
|
|
8
|
-
colorMap: string[];
|
|
9
|
-
};
|
|
10
|
-
getTheme(name: string | ThemeRegistrationAny): ThemeRegistrationResolved;
|
|
11
|
-
getLangGrammar(name: string): IGrammar;
|
|
12
|
-
getLoadedThemes(): string[];
|
|
13
|
-
getLoadedLanguages(): string[];
|
|
14
|
-
loadLanguage(...langs: LanguageInput[]): Promise<void>;
|
|
15
|
-
loadTheme(...themes: ThemeInput[]): Promise<void>;
|
|
16
|
-
getAlias(): Record<string, string>;
|
|
17
|
-
updateAlias(alias: Record<string, string>): void;
|
|
18
|
-
}
|
|
19
5
|
/**
|
|
20
|
-
*
|
|
6
|
+
* Internal context of Shiki, core textmate logic
|
|
21
7
|
*/
|
|
22
|
-
interface
|
|
23
|
-
/**
|
|
24
|
-
* Get highlighted code in HTML string
|
|
25
|
-
*/
|
|
26
|
-
codeToHtml(code: string, options: CodeToHastOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>): string;
|
|
27
|
-
/**
|
|
28
|
-
* Get highlighted code in HAST.
|
|
29
|
-
* @see https://github.com/syntax-tree/hast
|
|
30
|
-
*/
|
|
31
|
-
codeToHast(code: string, options: CodeToHastOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>): Root;
|
|
32
|
-
/**
|
|
33
|
-
* Get highlighted code in tokens. Uses `codeToTokensWithThemes` or `codeToTokensBase` based on the options.
|
|
34
|
-
*/
|
|
35
|
-
codeToTokens(code: string, options: CodeToTokensOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>): TokensResult;
|
|
36
|
-
/**
|
|
37
|
-
* Get highlighted code in tokens with a single theme.
|
|
38
|
-
* @returns A 2D array of tokens, first dimension is lines, second dimension is tokens in a line.
|
|
39
|
-
*/
|
|
40
|
-
codeToTokensBase(code: string, options: CodeToTokensBaseOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>): ThemedToken[][];
|
|
41
|
-
/**
|
|
42
|
-
* Get highlighted code in tokens with multiple themes.
|
|
43
|
-
*
|
|
44
|
-
* Different from `codeToTokensBase`, each token will have a `variants` property consisting of an object of color name to token styles.
|
|
45
|
-
*
|
|
46
|
-
* @returns A 2D array of tokens, first dimension is lines, second dimension is tokens in a line.
|
|
47
|
-
*/
|
|
48
|
-
codeToTokensWithThemes(code: string, options: CodeToTokensWithThemesOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>): ThemedTokenWithVariants[][];
|
|
49
|
-
/**
|
|
50
|
-
* @deprecated Renamed to `codeToTokensBase`, or use high-level `codeToTokens` directly.
|
|
51
|
-
*/
|
|
52
|
-
codeToThemedTokens(code: string, options: CodeToTokensBaseOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>): ThemedToken[][];
|
|
8
|
+
interface ShikiInternal<BundledLangKeys extends string = never, BundledThemeKeys extends string = never> {
|
|
53
9
|
/**
|
|
54
10
|
* Load a theme to the highlighter, so later it can be used synchronously.
|
|
55
11
|
*/
|
|
56
|
-
loadTheme(...themes: (ThemeInput | BundledThemeKeys | SpecialTheme)[])
|
|
12
|
+
loadTheme: (...themes: (ThemeInput | BundledThemeKeys | SpecialTheme)[]) => Promise<void>;
|
|
57
13
|
/**
|
|
58
14
|
* Load a language to the highlighter, so later it can be used synchronously.
|
|
59
15
|
*/
|
|
60
|
-
loadLanguage(...langs: (LanguageInput | BundledLangKeys | SpecialLanguage)[])
|
|
16
|
+
loadLanguage: (...langs: (LanguageInput | BundledLangKeys | SpecialLanguage)[]) => Promise<void>;
|
|
61
17
|
/**
|
|
62
18
|
* Get the registered theme object
|
|
63
19
|
*/
|
|
64
|
-
getTheme(name: string | ThemeRegistrationAny)
|
|
20
|
+
getTheme: (name: string | ThemeRegistrationAny) => ThemeRegistrationResolved;
|
|
65
21
|
/**
|
|
66
22
|
* Get the registered language object
|
|
67
23
|
*/
|
|
68
|
-
|
|
24
|
+
getLanguage: (name: string | LanguageRegistration) => IGrammar;
|
|
69
25
|
/**
|
|
70
26
|
* Set the current theme and get the resolved theme object and color map.
|
|
71
27
|
* @internal
|
|
72
28
|
*/
|
|
73
|
-
setTheme:
|
|
29
|
+
setTheme: (themeName: string | ThemeRegistrationAny) => {
|
|
30
|
+
theme: ThemeRegistrationResolved;
|
|
31
|
+
colorMap: string[];
|
|
32
|
+
};
|
|
74
33
|
/**
|
|
75
34
|
* Get the names of loaded languages
|
|
76
35
|
*
|
|
77
36
|
* Special-handled languages like `text`, `plain` and `ansi` are not included.
|
|
78
37
|
*/
|
|
79
|
-
getLoadedLanguages()
|
|
38
|
+
getLoadedLanguages: () => string[];
|
|
80
39
|
/**
|
|
81
40
|
* Get the names of loaded themes
|
|
82
41
|
*
|
|
83
42
|
* Special-handled themes like `none` are not included.
|
|
84
43
|
*/
|
|
85
|
-
getLoadedThemes()
|
|
44
|
+
getLoadedThemes: () => string[];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Generic instance interface of Shiki
|
|
48
|
+
*/
|
|
49
|
+
interface HighlighterGeneric<BundledLangKeys extends string, BundledThemeKeys extends string> extends ShikiInternal<BundledLangKeys, BundledThemeKeys> {
|
|
50
|
+
/**
|
|
51
|
+
* Get highlighted code in HTML string
|
|
52
|
+
*/
|
|
53
|
+
codeToHtml: (code: string, options: CodeToHastOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>) => string;
|
|
54
|
+
/**
|
|
55
|
+
* Get highlighted code in HAST.
|
|
56
|
+
* @see https://github.com/syntax-tree/hast
|
|
57
|
+
*/
|
|
58
|
+
codeToHast: (code: string, options: CodeToHastOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>) => Root;
|
|
59
|
+
/**
|
|
60
|
+
* Get highlighted code in tokens. Uses `codeToTokensWithThemes` or `codeToTokensBase` based on the options.
|
|
61
|
+
*/
|
|
62
|
+
codeToTokens: (code: string, options: CodeToTokensOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>) => TokensResult;
|
|
63
|
+
/**
|
|
64
|
+
* Get highlighted code in tokens with a single theme.
|
|
65
|
+
* @returns A 2D array of tokens, first dimension is lines, second dimension is tokens in a line.
|
|
66
|
+
*/
|
|
67
|
+
codeToTokensBase: (code: string, options: CodeToTokensBaseOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>) => ThemedToken[][];
|
|
68
|
+
/**
|
|
69
|
+
* Get highlighted code in tokens with multiple themes.
|
|
70
|
+
*
|
|
71
|
+
* Different from `codeToTokensBase`, each token will have a `variants` property consisting of an object of color name to token styles.
|
|
72
|
+
*
|
|
73
|
+
* @returns A 2D array of tokens, first dimension is lines, second dimension is tokens in a line.
|
|
74
|
+
*/
|
|
75
|
+
codeToTokensWithThemes: (code: string, options: CodeToTokensWithThemesOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>) => ThemedTokenWithVariants[][];
|
|
86
76
|
/**
|
|
87
77
|
* Get internal context object
|
|
88
78
|
* @internal
|
|
89
79
|
* @deprecated
|
|
90
80
|
*/
|
|
91
|
-
getInternalContext()
|
|
81
|
+
getInternalContext: () => ShikiInternal;
|
|
92
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* The fine-grained core Shiki highlighter instance.
|
|
85
|
+
*/
|
|
86
|
+
type HighlighterCore = HighlighterGeneric<never, never>;
|
|
93
87
|
|
|
94
|
-
export { CodeToHastOptions, CodeToTokensBaseOptions, CodeToTokensOptions, CodeToTokensWithThemesOptions, IGrammar as Grammar, type
|
|
88
|
+
export { CodeToHastOptions, CodeToTokensBaseOptions, CodeToTokensOptions, CodeToTokensWithThemesOptions, IGrammar as Grammar, type HighlighterCore, type HighlighterGeneric, LanguageInput, LanguageRegistration, ResolveBundleKey, type ShikiInternal, SpecialLanguage, SpecialTheme, ThemeInput, ThemeRegistrationAny, ThemeRegistrationResolved, ThemedToken, ThemedTokenWithVariants, TokensResult };
|
package/package.json
CHANGED