@shikijs/core 1.0.0-beta.5 → 1.0.0-beta.6
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 +10 -10
- package/dist/index.d.mts +13 -13
- package/dist/index.mjs +20 -7
- package/dist/types.d.mts +24 -24
- package/package.json +1 -1
package/dist/chunk-tokens.d.mts
CHANGED
|
@@ -814,44 +814,44 @@ 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
|
|
850
|
+
postprocess?: (this: ShikiTransformerContextCommon, html: string, options: CodeToHastOptions) => string | void;
|
|
851
851
|
/**
|
|
852
852
|
* @deprecated Use `span` instead
|
|
853
853
|
*/
|
|
854
|
-
token
|
|
854
|
+
token?: (this: ShikiTransformerContext, hast: Element, line: number, col: number, lineElement: Element) => Element | void;
|
|
855
855
|
}
|
|
856
856
|
/**
|
|
857
857
|
* @deprecated Rnamed to `ShikiTransformer`
|
|
@@ -1235,4 +1235,4 @@ declare enum FontStyle {
|
|
|
1235
1235
|
Underline = 4
|
|
1236
1236
|
}
|
|
1237
1237
|
|
|
1238
|
-
export { type DynamicImportThemeRegistration as $, type
|
|
1238
|
+
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 ShikijiTransformer as a7, type ShikijiTransformerContext as a8, type ShikijiTransformerContextCommon as a9, type Awaitable as aa, type MaybeGetter as ab, type MaybeModule as ac, type StringLiteralUnion as ad, type DecorationOptions as ae, type DecorationItem as af, type ResolvedDecorationItem as ag, type DecorationTransformType as ah, type Offset as ai, type OffsetOrPosition as aj, type ResolvedPosition as ak, 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,6 +1,6 @@
|
|
|
1
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 {
|
|
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, aa 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, af as DecorationItem, ae as DecorationOptions, ah as DecorationTransformType, O as DynamicImportLanguageRegistration, $ as DynamicImportThemeRegistration, F as FontStyle, b as IRawGrammar, J as LanguageRegistration, ab as MaybeGetter, ac as MaybeModule, ai as Offset, aj as OffsetOrPosition, b as RawGrammar, a as RawTheme, g as RawThemeSetting, G as ResolveBundleKey, ag as ResolvedDecorationItem, ak as ResolvedPosition, a6 as ShikiTransformerContext, a5 as ShikiTransformerContextMeta, a7 as ShikijiTransformer, a8 as ShikijiTransformerContext, a9 as ShikijiTransformerContextCommon, ad 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
|
|
|
@@ -29,45 +29,45 @@ interface ShorthandsBundle<L extends string, T extends string> {
|
|
|
29
29
|
*
|
|
30
30
|
* Differences from `highlighter.codeToHtml()`, this function is async.
|
|
31
31
|
*/
|
|
32
|
-
codeToHtml(code: string, options: CodeToHastOptions<L, T>)
|
|
32
|
+
codeToHtml: (code: string, options: CodeToHastOptions<L, T>) => Promise<string>;
|
|
33
33
|
/**
|
|
34
34
|
* Shorthand for `codeToHtml` with auto-loaded theme and language.
|
|
35
35
|
* A singleton highlighter it maintained internally.
|
|
36
36
|
*
|
|
37
37
|
* Differences from `highlighter.codeToHtml()`, this function is async.
|
|
38
38
|
*/
|
|
39
|
-
codeToHast(code: string, options: CodeToHastOptions<L, T>)
|
|
39
|
+
codeToHast: (code: string, options: CodeToHastOptions<L, T>) => Promise<Root>;
|
|
40
40
|
/**
|
|
41
41
|
* Shorthand for `codeToTokens` with auto-loaded theme and language.
|
|
42
42
|
* A singleton highlighter it maintained internally.
|
|
43
43
|
*
|
|
44
44
|
* Differences from `highlighter.codeToTokens()`, this function is async.
|
|
45
45
|
*/
|
|
46
|
-
codeToTokens(code: string, options: CodeToTokensOptions<L, T>)
|
|
46
|
+
codeToTokens: (code: string, options: CodeToTokensOptions<L, T>) => Promise<TokensResult>;
|
|
47
47
|
/**
|
|
48
48
|
* Shorthand for `codeToTokensBase` with auto-loaded theme and language.
|
|
49
49
|
* A singleton highlighter it maintained internally.
|
|
50
50
|
*
|
|
51
51
|
* Differences from `highlighter.codeToTokensBase()`, this function is async.
|
|
52
52
|
*/
|
|
53
|
-
codeToTokensBase(code: string, options: RequireKeys<CodeToTokensBaseOptions<L, T>, 'theme' | 'lang'>)
|
|
53
|
+
codeToTokensBase: (code: string, options: RequireKeys<CodeToTokensBaseOptions<L, T>, 'theme' | 'lang'>) => Promise<ThemedToken[][]>;
|
|
54
54
|
/**
|
|
55
55
|
* Shorthand for `codeToTokensWithThemes` with auto-loaded theme and language.
|
|
56
56
|
* A singleton highlighter it maintained internally.
|
|
57
57
|
*
|
|
58
58
|
* Differences from `highlighter.codeToTokensWithThemes()`, this function is async.
|
|
59
59
|
*/
|
|
60
|
-
codeToTokensWithThemes(code: string, options: RequireKeys<CodeToTokensWithThemesOptions<L, T>, 'themes' | 'lang'>)
|
|
60
|
+
codeToTokensWithThemes: (code: string, options: RequireKeys<CodeToTokensWithThemesOptions<L, T>, 'themes' | 'lang'>) => Promise<ThemedTokenWithVariants[][]>;
|
|
61
61
|
/**
|
|
62
62
|
* Get internal singleton highlighter.
|
|
63
63
|
*
|
|
64
64
|
* @internal
|
|
65
65
|
*/
|
|
66
|
-
getSingletonHighlighter()
|
|
66
|
+
getSingletonHighlighter: () => Promise<HighlighterGeneric<L, T>>;
|
|
67
67
|
/**
|
|
68
68
|
* @deprecated Use `codeToTokensBase` instead.
|
|
69
69
|
*/
|
|
70
|
-
codeToThemedTokens(code: string, options: RequireKeys<CodeToTokensBaseOptions<L, T>, 'theme' | 'lang'>)
|
|
70
|
+
codeToThemedTokens: (code: string, options: RequireKeys<CodeToTokensBaseOptions<L, T>, 'theme' | 'lang'>) => Promise<ThemedToken[][]>;
|
|
71
71
|
}
|
|
72
72
|
declare function createSingletonShorthands<L extends string, T extends string>(getHighlighter: GetHighlighterFactory<L, T>): ShorthandsBundle<L, T>;
|
|
73
73
|
|
|
@@ -75,19 +75,19 @@ declare function toArray<T>(x: MaybeArray<T>): T[];
|
|
|
75
75
|
/**
|
|
76
76
|
* Slipt a string into lines, each line preserves the line ending.
|
|
77
77
|
*/
|
|
78
|
-
declare function splitLines(
|
|
78
|
+
declare function splitLines(code: string, preserveEnding?: boolean): [string, number][];
|
|
79
79
|
/**
|
|
80
80
|
* Check if the language is plaintext that is ignored by Shiki.
|
|
81
81
|
*
|
|
82
82
|
* Hard-coded plain text languages: `plaintext`, `txt`, `text`, `plain`.
|
|
83
83
|
*/
|
|
84
|
-
declare function isPlainLang(lang: string | null | undefined):
|
|
84
|
+
declare function isPlainLang(lang: string | null | undefined): lang is PlainTextLanguage;
|
|
85
85
|
/**
|
|
86
86
|
* Check if the language is specially handled or bypassed by Shiki.
|
|
87
87
|
*
|
|
88
88
|
* Hard-coded languages: `ansi` and plaintexts like `plaintext`, `txt`, `text`, `plain`.
|
|
89
89
|
*/
|
|
90
|
-
declare function isSpecialLang(lang:
|
|
90
|
+
declare function isSpecialLang(lang: any): lang is SpecialLanguage;
|
|
91
91
|
/**
|
|
92
92
|
* Check if the theme is specially handled or bypassed by Shiki.
|
|
93
93
|
*
|
|
@@ -406,4 +406,4 @@ declare class ShikiError extends Error {
|
|
|
406
406
|
constructor(message: string);
|
|
407
407
|
}
|
|
408
408
|
|
|
409
|
-
export { BundledHighlighterOptions, CodeToHastOptions, CodeToHastRenderOptions, CodeToTokensBaseOptions, CodeToTokensOptions, CodeToTokensWithThemesOptions, type GetHighlighterFactory, IGrammar as Grammar, type HighlighterCore, HighlighterCoreOptions, HighlighterGeneric, IGrammar, LanguageInput, MaybeArray, Position, RequireKeys, ShikiError, ShikiInternal, ShikiTransformer, ShikiTransformerContextCommon, ShikiTransformerContextSource, type ShorthandsBundle, 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, isPlaintext, isSpecialLang, isSpecialTheme, normalizeTheme, setDefaultWasmLoader, splitLines, splitToken, splitTokens, stringifyTokenStyle, toArray, tokenizeAnsiWithTheme, tokenizeWithTheme, tokensToHast, transformerDecorations };
|
|
409
|
+
export { BundledHighlighterOptions, CodeToHastOptions, CodeToHastRenderOptions, CodeToTokensBaseOptions, CodeToTokensOptions, CodeToTokensWithThemesOptions, type GetHighlighterFactory, IGrammar as Grammar, type HighlighterCore, HighlighterCoreOptions, HighlighterGeneric, IGrammar, 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, isPlaintext, 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.
|
|
@@ -140,7 +151,7 @@ function stringifyTokenStyle(token) {
|
|
|
140
151
|
* Creates a converter between index and position in a code block.
|
|
141
152
|
*/
|
|
142
153
|
function createPositionConverter(code) {
|
|
143
|
-
const lines =
|
|
154
|
+
const lines = splitLines(code, true).map(([line]) => line);
|
|
144
155
|
function indexToPos(index) {
|
|
145
156
|
let character = index;
|
|
146
157
|
let line = 0;
|
|
@@ -871,8 +882,8 @@ function transformerDecorations() {
|
|
|
871
882
|
return;
|
|
872
883
|
const ctx = getContext(this);
|
|
873
884
|
const lines = Array.from(codeEl.children).filter(i => i.type === 'element' && i.tagName === 'span');
|
|
874
|
-
|
|
875
|
-
|
|
885
|
+
if (lines.length !== ctx.converter.lines.length)
|
|
886
|
+
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
887
|
function applyLineSection(line, start, end, decoration) {
|
|
877
888
|
const lineEl = lines[line];
|
|
878
889
|
let text = '';
|
|
@@ -5249,7 +5260,9 @@ async function getShikiInternal(options = {}) {
|
|
|
5249
5260
|
return Promise.resolve(typeof p === 'function' ? p() : p).then(r => r.default || r);
|
|
5250
5261
|
}
|
|
5251
5262
|
async function resolveLangs(langs) {
|
|
5252
|
-
return Array.from(new Set((await Promise.all(langs
|
|
5263
|
+
return Array.from(new Set((await Promise.all(langs
|
|
5264
|
+
.filter(l => !isSpecialLang(l))
|
|
5265
|
+
.map(async (lang) => await normalizeGetter(lang).then(r => Array.isArray(r) ? r : [r])))).flat()));
|
|
5253
5266
|
}
|
|
5254
5267
|
const wasmLoader = options.loadWasm || _defaultWasmLoader;
|
|
5255
5268
|
const [themes, langs,] = await Promise.all([
|
|
@@ -5270,7 +5283,7 @@ async function getShikiInternal(options = {}) {
|
|
|
5270
5283
|
await _registry.init();
|
|
5271
5284
|
let _lastTheme;
|
|
5272
5285
|
function getLangGrammar(name) {
|
|
5273
|
-
const _lang = _registry.getGrammar(name);
|
|
5286
|
+
const _lang = _registry.getGrammar(typeof name === 'string' ? name : name.name);
|
|
5274
5287
|
if (!_lang)
|
|
5275
5288
|
throw new ShikiError(`Language \`${name}\` not found, you may need to load it first`);
|
|
5276
5289
|
return _lang;
|
package/dist/types.d.mts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { z as ThemeRegistrationAny, t as ThemeRegistrationResolved, J as LanguageRegistration, c as IGrammar, L as LanguageInput, p as SpecialLanguage, T as ThemeInput, q as SpecialTheme, 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, aa 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, af as DecorationItem, ae as DecorationOptions, ah as DecorationTransformType, O as DynamicImportLanguageRegistration, $ as DynamicImportThemeRegistration, F as FontStyle, H as HighlighterCoreOptions, b as IRawGrammar, M as MaybeArray, ab as MaybeGetter, ac as MaybeModule, ai as Offset, aj as OffsetOrPosition, P as PlainTextLanguage, s as Position, b as RawGrammar, a as RawTheme, g as RawThemeSetting, k as RequireKeys, ag as ResolvedDecorationItem, ak as ResolvedPosition, A as ShikiTransformer, a6 as ShikiTransformerContext, v as ShikiTransformerContextCommon, a5 as ShikiTransformerContextMeta, x as ShikiTransformerContextSource, a7 as ShikijiTransformer, a8 as ShikijiTransformerContext, a9 as ShikijiTransformerContextCommon, ad 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
5
|
interface ShikiInternal {
|
|
6
|
-
setTheme(name: string | ThemeRegistrationAny)
|
|
6
|
+
setTheme: (name: string | ThemeRegistrationAny) => {
|
|
7
7
|
theme: ThemeRegistrationResolved;
|
|
8
8
|
colorMap: string[];
|
|
9
9
|
};
|
|
10
|
-
getTheme(name: string | ThemeRegistrationAny)
|
|
11
|
-
getLangGrammar(name: string)
|
|
12
|
-
getLoadedThemes()
|
|
13
|
-
getLoadedLanguages()
|
|
14
|
-
loadLanguage(...langs: LanguageInput[])
|
|
15
|
-
loadTheme(...themes: ThemeInput[])
|
|
16
|
-
getAlias()
|
|
17
|
-
updateAlias(alias: Record<string, string>)
|
|
10
|
+
getTheme: (name: string | ThemeRegistrationAny) => ThemeRegistrationResolved;
|
|
11
|
+
getLangGrammar: (name: string | LanguageRegistration) => IGrammar;
|
|
12
|
+
getLoadedThemes: () => string[];
|
|
13
|
+
getLoadedLanguages: () => string[];
|
|
14
|
+
loadLanguage: (...langs: (LanguageInput | SpecialLanguage)[]) => Promise<void>;
|
|
15
|
+
loadTheme: (...themes: (ThemeInput | SpecialTheme)[]) => Promise<void>;
|
|
16
|
+
getAlias: () => Record<string, string>;
|
|
17
|
+
updateAlias: (alias: Record<string, string>) => void;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* Generic instance interface of Shiki
|
|
@@ -23,21 +23,21 @@ interface HighlighterGeneric<BundledLangKeys extends string, BundledThemeKeys ex
|
|
|
23
23
|
/**
|
|
24
24
|
* Get highlighted code in HTML string
|
|
25
25
|
*/
|
|
26
|
-
codeToHtml(code: string, options: CodeToHastOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>)
|
|
26
|
+
codeToHtml: (code: string, options: CodeToHastOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>) => string;
|
|
27
27
|
/**
|
|
28
28
|
* Get highlighted code in HAST.
|
|
29
29
|
* @see https://github.com/syntax-tree/hast
|
|
30
30
|
*/
|
|
31
|
-
codeToHast(code: string, options: CodeToHastOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>)
|
|
31
|
+
codeToHast: (code: string, options: CodeToHastOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>) => Root;
|
|
32
32
|
/**
|
|
33
33
|
* Get highlighted code in tokens. Uses `codeToTokensWithThemes` or `codeToTokensBase` based on the options.
|
|
34
34
|
*/
|
|
35
|
-
codeToTokens(code: string, options: CodeToTokensOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>)
|
|
35
|
+
codeToTokens: (code: string, options: CodeToTokensOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>) => TokensResult;
|
|
36
36
|
/**
|
|
37
37
|
* Get highlighted code in tokens with a single theme.
|
|
38
38
|
* @returns A 2D array of tokens, first dimension is lines, second dimension is tokens in a line.
|
|
39
39
|
*/
|
|
40
|
-
codeToTokensBase(code: string, options: CodeToTokensBaseOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>)
|
|
40
|
+
codeToTokensBase: (code: string, options: CodeToTokensBaseOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>) => ThemedToken[][];
|
|
41
41
|
/**
|
|
42
42
|
* Get highlighted code in tokens with multiple themes.
|
|
43
43
|
*
|
|
@@ -45,27 +45,27 @@ interface HighlighterGeneric<BundledLangKeys extends string, BundledThemeKeys ex
|
|
|
45
45
|
*
|
|
46
46
|
* @returns A 2D array of tokens, first dimension is lines, second dimension is tokens in a line.
|
|
47
47
|
*/
|
|
48
|
-
codeToTokensWithThemes(code: string, options: CodeToTokensWithThemesOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>)
|
|
48
|
+
codeToTokensWithThemes: (code: string, options: CodeToTokensWithThemesOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>) => ThemedTokenWithVariants[][];
|
|
49
49
|
/**
|
|
50
50
|
* @deprecated Renamed to `codeToTokensBase`, or use high-level `codeToTokens` directly.
|
|
51
51
|
*/
|
|
52
|
-
codeToThemedTokens(code: string, options: CodeToTokensBaseOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>)
|
|
52
|
+
codeToThemedTokens: (code: string, options: CodeToTokensBaseOptions<ResolveBundleKey<BundledLangKeys>, ResolveBundleKey<BundledThemeKeys>>) => ThemedToken[][];
|
|
53
53
|
/**
|
|
54
54
|
* Load a theme to the highlighter, so later it can be used synchronously.
|
|
55
55
|
*/
|
|
56
|
-
loadTheme(...themes: (ThemeInput | BundledThemeKeys | SpecialTheme)[])
|
|
56
|
+
loadTheme: (...themes: (ThemeInput | BundledThemeKeys | SpecialTheme)[]) => Promise<void>;
|
|
57
57
|
/**
|
|
58
58
|
* Load a language to the highlighter, so later it can be used synchronously.
|
|
59
59
|
*/
|
|
60
|
-
loadLanguage(...langs: (LanguageInput | BundledLangKeys | SpecialLanguage)[])
|
|
60
|
+
loadLanguage: (...langs: (LanguageInput | BundledLangKeys | SpecialLanguage)[]) => Promise<void>;
|
|
61
61
|
/**
|
|
62
62
|
* Get the registered theme object
|
|
63
63
|
*/
|
|
64
|
-
getTheme(name: string | ThemeRegistrationAny)
|
|
64
|
+
getTheme: (name: string | ThemeRegistrationAny) => ThemeRegistrationResolved;
|
|
65
65
|
/**
|
|
66
66
|
* Get the registered language object
|
|
67
67
|
*/
|
|
68
|
-
getLangGrammar(name: string | LanguageRegistration)
|
|
68
|
+
getLangGrammar: (name: string | LanguageRegistration) => IGrammar;
|
|
69
69
|
/**
|
|
70
70
|
* Set the current theme and get the resolved theme object and color map.
|
|
71
71
|
* @internal
|
|
@@ -76,19 +76,19 @@ interface HighlighterGeneric<BundledLangKeys extends string, BundledThemeKeys ex
|
|
|
76
76
|
*
|
|
77
77
|
* Special-handled languages like `text`, `plain` and `ansi` are not included.
|
|
78
78
|
*/
|
|
79
|
-
getLoadedLanguages()
|
|
79
|
+
getLoadedLanguages: () => string[];
|
|
80
80
|
/**
|
|
81
81
|
* Get the names of loaded themes
|
|
82
82
|
*
|
|
83
83
|
* Special-handled themes like `none` are not included.
|
|
84
84
|
*/
|
|
85
|
-
getLoadedThemes()
|
|
85
|
+
getLoadedThemes: () => string[];
|
|
86
86
|
/**
|
|
87
87
|
* Get internal context object
|
|
88
88
|
* @internal
|
|
89
89
|
* @deprecated
|
|
90
90
|
*/
|
|
91
|
-
getInternalContext()
|
|
91
|
+
getInternalContext: () => ShikiInternal;
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
export { CodeToHastOptions, CodeToTokensBaseOptions, CodeToTokensOptions, CodeToTokensWithThemesOptions, IGrammar as Grammar, type HighlighterGeneric, IGrammar, LanguageInput, LanguageRegistration, ResolveBundleKey, type ShikiInternal, SpecialLanguage, SpecialTheme, ThemeInput, ThemeRegistrationAny, ThemeRegistrationResolved, ThemedToken, ThemedTokenWithVariants, TokensResult };
|
package/package.json
CHANGED