@shikijs/core 1.16.2 → 1.17.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 +47 -288
- package/dist/index.d.ts +236 -0
- package/dist/index.mjs +1442 -5893
- package/dist/textmate.d.mts +1 -0
- package/dist/textmate.d.ts +1 -0
- package/dist/textmate.mjs +1 -0
- package/dist/types.d.mts +3 -766
- package/dist/types.d.ts +3 -0
- package/dist/types.mjs +1 -10
- package/dist/wasm-inlined.d.mts +1 -7
- package/dist/wasm-inlined.d.ts +1 -0
- package/dist/wasm-inlined.mjs +1 -9
- package/package.json +8 -9
- package/dist/chunk-engines.d.mts +0 -60
- package/dist/onig.d.mts +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,35 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
3
|
-
import {
|
|
4
|
-
export {
|
|
5
|
-
import { Root, RootContent, Nodes, Element } from 'hast';
|
|
1
|
+
import { CreatedBundledHighlighterOptions, CreateHighlighterFactory, LanguageInput, ThemeInput, HighlighterCoreOptions, CodeToHastOptions, CodeToTokensOptions, TokensResult, RequireKeys, CodeToTokensBaseOptions, ThemedToken, CodeToTokensWithThemesOptions, ThemedTokenWithVariants, BundledHighlighterOptions, HighlighterGeneric, GrammarState, HighlighterCore, ShikiInternal, LoadWasmOptions, ShikiTransformerContextCommon, CodeToHastRenderOptions, ShikiTransformerContextSource, ThemeRegistrationResolved, TokenizeWithThemeOptions, ThemeRegistrationAny, ShikiTransformer, MaybeArray, PlainTextLanguage, SpecialLanguage, SpecialTheme, MaybeGetter, TokenStyles, Position } from '@shikijs/types';
|
|
2
|
+
export * from '@shikijs/types';
|
|
3
|
+
import { Root, Element } from 'hast';
|
|
4
|
+
export { createJavaScriptRegexEngine, defaultJavaScriptRegexConstructor } from '@shikijs/engine-javascript';
|
|
6
5
|
import { IGrammar } from '@shikijs/vscode-textmate';
|
|
7
|
-
export {
|
|
6
|
+
export { FontStyle, EncodedTokenMetadata as StackElementMetadata } from '@shikijs/vscode-textmate';
|
|
7
|
+
export { createWasmOnigEngine, loadWasm } from '@shikijs/engine-oniguruma';
|
|
8
|
+
export { toHtml as hastToHtml } from 'hast-util-to-html';
|
|
8
9
|
|
|
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
|
-
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.
|
|
35
12
|
*
|
|
@@ -107,17 +84,28 @@ 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
|
|
115
|
-
|
|
92
|
+
declare function createHighlighterCore(options?: HighlighterCoreOptions): Promise<HighlighterCore>;
|
|
116
93
|
/**
|
|
117
|
-
*
|
|
118
|
-
*
|
|
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
|
|
119
100
|
*/
|
|
120
|
-
declare function
|
|
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>;
|
|
108
|
+
|
|
121
109
|
/**
|
|
122
110
|
* Get the minimal shiki context for rendering.
|
|
123
111
|
*/
|
|
@@ -127,35 +115,26 @@ declare function createShikiInternal(options?: HighlighterCoreOptions): Promise<
|
|
|
127
115
|
*/
|
|
128
116
|
declare function getShikiInternal(options?: HighlighterCoreOptions): Promise<ShikiInternal>;
|
|
129
117
|
|
|
130
|
-
declare function loadWasm(options: LoadWasmOptions): Promise<void>;
|
|
131
|
-
|
|
132
|
-
declare function createWasmOnigEngine(options?: LoadWasmOptions | null): Promise<RegexEngine>;
|
|
133
|
-
|
|
134
118
|
/**
|
|
135
|
-
*
|
|
136
|
-
*/
|
|
137
|
-
declare function defaultJavaScriptRegexConstructor(pattern: string): RegExp;
|
|
138
|
-
/**
|
|
139
|
-
* Use the modern JavaScript RegExp engine to implement the OnigScanner.
|
|
140
|
-
*
|
|
141
|
-
* As Oniguruma regex is more powerful than JavaScript regex, some patterns may not be supported.
|
|
142
|
-
* Errors will be thrown when parsing TextMate grammars with unsupported patterns.
|
|
143
|
-
* Set `forgiving` to `true` to ignore these errors and skip the unsupported patterns.
|
|
119
|
+
* Get the minimal shiki context for rendering.
|
|
144
120
|
*
|
|
145
|
-
*
|
|
121
|
+
* Synchronous version of `createShikiInternal`, which requires to provide the engine and all themes and languages upfront.
|
|
146
122
|
*/
|
|
147
|
-
declare function
|
|
123
|
+
declare function createShikiInternalSync(options: HighlighterCoreOptions<true>): ShikiInternal;
|
|
148
124
|
|
|
149
125
|
/**
|
|
150
|
-
*
|
|
126
|
+
* Set the default wasm loader for `loadWasm`.
|
|
127
|
+
* @internal
|
|
151
128
|
*/
|
|
152
|
-
declare function
|
|
129
|
+
declare function setDefaultWasmLoader(_loader: LoadWasmOptions): void;
|
|
130
|
+
|
|
131
|
+
declare function codeToHast(internal: ShikiInternal, code: string, options: CodeToHastOptions, transformerContext?: ShikiTransformerContextCommon): Root;
|
|
132
|
+
declare function tokensToHast(tokens: ThemedToken[][], options: CodeToHastRenderOptions, transformerContext: ShikiTransformerContextSource): Root;
|
|
153
133
|
|
|
154
134
|
/**
|
|
155
|
-
*
|
|
135
|
+
* Get highlighted code in HTML.
|
|
156
136
|
*/
|
|
157
|
-
declare function
|
|
158
|
-
declare function tokenizeWithTheme(code: string, grammar: IGrammar, theme: ThemeRegistrationResolved, colorMap: string[], options: TokenizeWithThemeOptions): ThemedToken[][];
|
|
137
|
+
declare function codeToHtml(internal: ShikiInternal, code: string, options: CodeToHastOptions): string;
|
|
159
138
|
|
|
160
139
|
/**
|
|
161
140
|
* High-level code-to-tokens API.
|
|
@@ -166,237 +145,26 @@ declare function codeToTokens(internal: ShikiInternal, code: string, options: Co
|
|
|
166
145
|
|
|
167
146
|
declare function tokenizeAnsiWithTheme(theme: ThemeRegistrationResolved, fileContents: string, options?: TokenizeWithThemeOptions): ThemedToken[][];
|
|
168
147
|
|
|
169
|
-
declare function codeToHast(internal: ShikiInternal, code: string, options: CodeToHastOptions, transformerContext?: ShikiTransformerContextCommon): Root;
|
|
170
|
-
declare function tokensToHast(tokens: ThemedToken[][], options: CodeToHastRenderOptions, transformerContext: ShikiTransformerContextSource): Root;
|
|
171
|
-
|
|
172
|
-
type FormatSmartOptions = {
|
|
173
|
-
/**
|
|
174
|
-
* Prefer named character references (`&`) where possible.
|
|
175
|
-
*/
|
|
176
|
-
useNamedReferences?: boolean | undefined
|
|
177
|
-
/**
|
|
178
|
-
* Prefer the shortest possible reference, if that results in less bytes.
|
|
179
|
-
* **Note**: `useNamedReferences` can be omitted when using `useShortestReferences`.
|
|
180
|
-
*/
|
|
181
|
-
useShortestReferences?: boolean | undefined
|
|
182
|
-
/**
|
|
183
|
-
* Whether to omit semicolons when possible.
|
|
184
|
-
* **Note**: This creates what HTML calls “parse errors” but is otherwise still valid HTML — don’t use this except when building a minifier.
|
|
185
|
-
* Omitting semicolons is possible for certain named and numeric references in some cases.
|
|
186
|
-
*/
|
|
187
|
-
omitOptionalSemicolons?: boolean | undefined
|
|
188
|
-
/**
|
|
189
|
-
* Create character references which don’t fail in attributes.
|
|
190
|
-
* **Note**: `attribute` only applies when operating dangerously with
|
|
191
|
-
* `omitOptionalSemicolons: true`.
|
|
192
|
-
*/
|
|
193
|
-
attribute?: boolean | undefined
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
type CoreOptions = {
|
|
197
|
-
/**
|
|
198
|
-
* Whether to only escape the given subset of characters.
|
|
199
|
-
*/
|
|
200
|
-
subset?: string[] | undefined
|
|
201
|
-
/**
|
|
202
|
-
* Whether to only escape possibly dangerous characters.
|
|
203
|
-
* Those characters are `"`, `&`, `'`, `<`, `>`, and `` ` ``.
|
|
204
|
-
*/
|
|
205
|
-
escapeOnly?: boolean | undefined
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
type Options$2 = CoreOptions &
|
|
209
|
-
FormatSmartOptions
|
|
210
|
-
|
|
211
|
-
type Options$1 = Options$2
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Serialize hast as HTML.
|
|
215
|
-
*
|
|
216
|
-
* @param {Array<RootContent> | Nodes} tree
|
|
217
|
-
* Tree to serialize.
|
|
218
|
-
* @param {Options | null | undefined} [options]
|
|
219
|
-
* Configuration (optional).
|
|
220
|
-
* @returns {string}
|
|
221
|
-
* Serialized HTML.
|
|
222
|
-
*/
|
|
223
|
-
declare function toHtml(tree: Array<RootContent> | Nodes, options?: Options | null | undefined): string;
|
|
224
|
-
type CharacterReferences = Omit<Options$1, "attribute" | "escapeOnly" | "subset">;
|
|
225
|
-
/**
|
|
226
|
-
* Configuration.
|
|
227
|
-
*/
|
|
228
|
-
type Options = {
|
|
229
|
-
/**
|
|
230
|
-
* Do not encode some characters which cause XSS vulnerabilities in older
|
|
231
|
-
* browsers (default: `false`).
|
|
232
|
-
*
|
|
233
|
-
* > ⚠️ **Danger**: only set this if you completely trust the content.
|
|
234
|
-
*/
|
|
235
|
-
allowDangerousCharacters?: boolean | null | undefined;
|
|
236
|
-
/**
|
|
237
|
-
* Allow `raw` nodes and insert them as raw HTML (default: `false`).
|
|
238
|
-
*
|
|
239
|
-
* When `false`, `Raw` nodes are encoded.
|
|
240
|
-
*
|
|
241
|
-
* > ⚠️ **Danger**: only set this if you completely trust the content.
|
|
242
|
-
*/
|
|
243
|
-
allowDangerousHtml?: boolean | null | undefined;
|
|
244
|
-
/**
|
|
245
|
-
* Do not encode characters which cause parse errors (even though they work),
|
|
246
|
-
* to save bytes (default: `false`).
|
|
247
|
-
*
|
|
248
|
-
* Not used in the SVG space.
|
|
249
|
-
*
|
|
250
|
-
* > 👉 **Note**: intentionally creates parse errors in markup (how parse
|
|
251
|
-
* > errors are handled is well defined, so this works but isn’t pretty).
|
|
252
|
-
*/
|
|
253
|
-
allowParseErrors?: boolean | null | undefined;
|
|
254
|
-
/**
|
|
255
|
-
* Use “bogus comments” instead of comments to save byes: `<?charlie>`
|
|
256
|
-
* instead of `<!--charlie-->` (default: `false`).
|
|
257
|
-
*
|
|
258
|
-
* > 👉 **Note**: intentionally creates parse errors in markup (how parse
|
|
259
|
-
* > errors are handled is well defined, so this works but isn’t pretty).
|
|
260
|
-
*/
|
|
261
|
-
bogusComments?: boolean | null | undefined;
|
|
262
|
-
/**
|
|
263
|
-
* Configure how to serialize character references (optional).
|
|
264
|
-
*/
|
|
265
|
-
characterReferences?: CharacterReferences | null | undefined;
|
|
266
|
-
/**
|
|
267
|
-
* Close SVG elements without any content with slash (`/`) on the opening tag
|
|
268
|
-
* instead of an end tag: `<circle />` instead of `<circle></circle>`
|
|
269
|
-
* (default: `false`).
|
|
270
|
-
*
|
|
271
|
-
* See `tightSelfClosing` to control whether a space is used before the
|
|
272
|
-
* slash.
|
|
273
|
-
*
|
|
274
|
-
* Not used in the HTML space.
|
|
275
|
-
*/
|
|
276
|
-
closeEmptyElements?: boolean | null | undefined;
|
|
277
|
-
/**
|
|
278
|
-
* Close self-closing nodes with an extra slash (`/`): `<img />` instead of
|
|
279
|
-
* `<img>` (default: `false`).
|
|
280
|
-
*
|
|
281
|
-
* See `tightSelfClosing` to control whether a space is used before the
|
|
282
|
-
* slash.
|
|
283
|
-
*
|
|
284
|
-
* Not used in the SVG space.
|
|
285
|
-
*/
|
|
286
|
-
closeSelfClosing?: boolean | null | undefined;
|
|
287
|
-
/**
|
|
288
|
-
* Collapse empty attributes: get `class` instead of `class=""` (default:
|
|
289
|
-
* `false`).
|
|
290
|
-
*
|
|
291
|
-
* Not used in the SVG space.
|
|
292
|
-
*
|
|
293
|
-
* > 👉 **Note**: boolean attributes (such as `hidden`) are always collapsed.
|
|
294
|
-
*/
|
|
295
|
-
collapseEmptyAttributes?: boolean | null | undefined;
|
|
296
|
-
/**
|
|
297
|
-
* Omit optional opening and closing tags (default: `false`).
|
|
298
|
-
*
|
|
299
|
-
* For example, in `<ol><li>one</li><li>two</li></ol>`, both `</li>` closing
|
|
300
|
-
* tags can be omitted.
|
|
301
|
-
* The first because it’s followed by another `li`, the last because it’s
|
|
302
|
-
* followed by nothing.
|
|
303
|
-
*
|
|
304
|
-
* Not used in the SVG space.
|
|
305
|
-
*/
|
|
306
|
-
omitOptionalTags?: boolean | null | undefined;
|
|
307
|
-
/**
|
|
308
|
-
* Leave attributes unquoted if that results in less bytes (default: `false`).
|
|
309
|
-
*
|
|
310
|
-
* Not used in the SVG space.
|
|
311
|
-
*/
|
|
312
|
-
preferUnquoted?: boolean | null | undefined;
|
|
313
|
-
/**
|
|
314
|
-
* Use the other quote if that results in less bytes (default: `false`).
|
|
315
|
-
*/
|
|
316
|
-
quoteSmart?: boolean | null | undefined;
|
|
317
|
-
/**
|
|
318
|
-
* Preferred quote to use (default: `'"'`).
|
|
319
|
-
*/
|
|
320
|
-
quote?: Quote | null | undefined;
|
|
321
|
-
/**
|
|
322
|
-
* When an `<svg>` element is found in the HTML space, this package already
|
|
323
|
-
* automatically switches to and from the SVG space when entering and exiting
|
|
324
|
-
* it (default: `'html'`).
|
|
325
|
-
*
|
|
326
|
-
* > 👉 **Note**: hast is not XML.
|
|
327
|
-
* > It supports SVG as embedded in HTML.
|
|
328
|
-
* > It does not support the features available in XML.
|
|
329
|
-
* > Passing SVG might break but fragments of modern SVG should be fine.
|
|
330
|
-
* > Use [`xast`][xast] if you need to support SVG as XML.
|
|
331
|
-
*/
|
|
332
|
-
space?: Space | null | undefined;
|
|
333
|
-
/**
|
|
334
|
-
* Join attributes together, without whitespace, if possible: get
|
|
335
|
-
* `class="a b"title="c d"` instead of `class="a b" title="c d"` to save
|
|
336
|
-
* bytes (default: `false`).
|
|
337
|
-
*
|
|
338
|
-
* Not used in the SVG space.
|
|
339
|
-
*
|
|
340
|
-
* > 👉 **Note**: intentionally creates parse errors in markup (how parse
|
|
341
|
-
* > errors are handled is well defined, so this works but isn’t pretty).
|
|
342
|
-
*/
|
|
343
|
-
tightAttributes?: boolean | null | undefined;
|
|
344
|
-
/**
|
|
345
|
-
* Join known comma-separated attribute values with just a comma (`,`),
|
|
346
|
-
* instead of padding them on the right as well (`,␠`, where `␠` represents a
|
|
347
|
-
* space) (default: `false`).
|
|
348
|
-
*/
|
|
349
|
-
tightCommaSeparatedLists?: boolean | null | undefined;
|
|
350
|
-
/**
|
|
351
|
-
* Drop unneeded spaces in doctypes: `<!doctypehtml>` instead of
|
|
352
|
-
* `<!doctype html>` to save bytes (default: `false`).
|
|
353
|
-
*
|
|
354
|
-
* > 👉 **Note**: intentionally creates parse errors in markup (how parse
|
|
355
|
-
* > errors are handled is well defined, so this works but isn’t pretty).
|
|
356
|
-
*/
|
|
357
|
-
tightDoctype?: boolean | null | undefined;
|
|
358
|
-
/**
|
|
359
|
-
* Do not use an extra space when closing self-closing elements: `<img/>`
|
|
360
|
-
* instead of `<img />` (default: `false`).
|
|
361
|
-
*
|
|
362
|
-
* > 👉 **Note**: only used if `closeSelfClosing: true` or
|
|
363
|
-
* > `closeEmptyElements: true`.
|
|
364
|
-
*/
|
|
365
|
-
tightSelfClosing?: boolean | null | undefined;
|
|
366
|
-
/**
|
|
367
|
-
* Use a `<!DOCTYPE…` instead of `<!doctype…` (default: `false`).
|
|
368
|
-
*
|
|
369
|
-
* Useless except for XHTML.
|
|
370
|
-
*/
|
|
371
|
-
upperDoctype?: boolean | null | undefined;
|
|
372
|
-
/**
|
|
373
|
-
* Tag names of elements to serialize without closing tag (default: `html-void-elements`).
|
|
374
|
-
*
|
|
375
|
-
* Not used in the SVG space.
|
|
376
|
-
*
|
|
377
|
-
* > 👉 **Note**: It’s highly unlikely that you want to pass this, because
|
|
378
|
-
* > hast is not for XML, and HTML will not add more void elements.
|
|
379
|
-
*/
|
|
380
|
-
voids?: ReadonlyArray<string> | null | undefined;
|
|
381
|
-
};
|
|
382
148
|
/**
|
|
383
|
-
*
|
|
149
|
+
* Code to tokens, with a simple theme.
|
|
384
150
|
*/
|
|
385
|
-
|
|
151
|
+
declare function codeToTokensBase(internal: ShikiInternal, code: string, options?: CodeToTokensBaseOptions): ThemedToken[][];
|
|
152
|
+
declare function tokenizeWithTheme(code: string, grammar: IGrammar, theme: ThemeRegistrationResolved, colorMap: string[], options: TokenizeWithThemeOptions): ThemedToken[][];
|
|
153
|
+
|
|
386
154
|
/**
|
|
387
|
-
*
|
|
155
|
+
* Get tokens with multiple themes
|
|
388
156
|
*/
|
|
389
|
-
|
|
157
|
+
declare function codeToTokensWithThemes(internal: ShikiInternal, code: string, options: CodeToTokensWithThemesOptions): ThemedTokenWithVariants[][];
|
|
390
158
|
|
|
391
159
|
/**
|
|
392
|
-
*
|
|
160
|
+
* Normalize a textmate theme to shiki theme
|
|
393
161
|
*/
|
|
394
|
-
declare function
|
|
162
|
+
declare function normalizeTheme(rawTheme: ThemeRegistrationAny): ThemeRegistrationResolved;
|
|
395
163
|
|
|
396
164
|
/**
|
|
397
|
-
*
|
|
165
|
+
* A built-in transformer to add decorations to the highlighted code.
|
|
398
166
|
*/
|
|
399
|
-
declare function
|
|
167
|
+
declare function transformerDecorations(): ShikiTransformer;
|
|
400
168
|
|
|
401
169
|
declare function toArray<T>(x: MaybeArray<T>): T[];
|
|
402
170
|
/**
|
|
@@ -465,13 +233,4 @@ declare function createPositionConverter(code: string): {
|
|
|
465
233
|
posToIndex: (line: number, character: number) => number;
|
|
466
234
|
};
|
|
467
235
|
|
|
468
|
-
|
|
469
|
-
* A built-in transformer to add decorations to the highlighted code.
|
|
470
|
-
*/
|
|
471
|
-
declare function transformerDecorations(): ShikiTransformer;
|
|
472
|
-
|
|
473
|
-
declare class ShikiError extends Error {
|
|
474
|
-
constructor(message: string);
|
|
475
|
-
}
|
|
476
|
-
|
|
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 };
|
|
236
|
+
export { type ShorthandsBundle, addClassToHast, applyColorReplacements, codeToHast, codeToHtml, codeToTokens, codeToTokensBase, codeToTokensWithThemes, createHighlighterCore, createHighlighterCoreSync, createPositionConverter, createShikiInternal, createShikiInternalSync, createSingletonShorthands, createdBundledHighlighter, getHighlighterCore, getShikiInternal, getSingletonHighlighterCore, getTokenStyleObject, isNoneTheme, isPlainLang, isSpecialLang, isSpecialTheme, makeSingletonHighlighter, makeSingletonHighlighterCore, normalizeGetter, normalizeTheme, resolveColorReplacements, setDefaultWasmLoader, splitLines, splitToken, splitTokens, stringifyTokenStyle, toArray, tokenizeAnsiWithTheme, tokenizeWithTheme, tokensToHast, transformerDecorations };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { CreatedBundledHighlighterOptions, CreateHighlighterFactory, LanguageInput, ThemeInput, HighlighterCoreOptions, CodeToHastOptions, CodeToTokensOptions, TokensResult, RequireKeys, CodeToTokensBaseOptions, ThemedToken, CodeToTokensWithThemesOptions, ThemedTokenWithVariants, BundledHighlighterOptions, HighlighterGeneric, GrammarState, HighlighterCore, ShikiInternal, LoadWasmOptions, ShikiTransformerContextCommon, CodeToHastRenderOptions, ShikiTransformerContextSource, ThemeRegistrationResolved, TokenizeWithThemeOptions, ThemeRegistrationAny, ShikiTransformer, MaybeArray, PlainTextLanguage, SpecialLanguage, SpecialTheme, MaybeGetter, TokenStyles, Position } from '@shikijs/types';
|
|
2
|
+
export * from '@shikijs/types';
|
|
3
|
+
import { Root, Element } from 'hast';
|
|
4
|
+
export { createJavaScriptRegexEngine, defaultJavaScriptRegexConstructor } from '@shikijs/engine-javascript';
|
|
5
|
+
import { IGrammar } from '@shikijs/vscode-textmate';
|
|
6
|
+
export { FontStyle, EncodedTokenMetadata as StackElementMetadata } from '@shikijs/vscode-textmate';
|
|
7
|
+
export { createWasmOnigEngine, loadWasm } from '@shikijs/engine-oniguruma';
|
|
8
|
+
export { toHtml as hastToHtml } from 'hast-util-to-html';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Create a `createHighlighter` function with bundled themes, languages, and engine.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const createHighlighter = createdBundledHighlighter({
|
|
16
|
+
* langs: {
|
|
17
|
+
* typescript: () => import('shiki/langs/typescript.mjs'),
|
|
18
|
+
* // ...
|
|
19
|
+
* },
|
|
20
|
+
* themes: {
|
|
21
|
+
* nord: () => import('shiki/themes/nord.mjs'),
|
|
22
|
+
* // ...
|
|
23
|
+
* },
|
|
24
|
+
* engine: () => createWasmOnigEngine(), // or createJavaScriptRegexEngine()
|
|
25
|
+
* })
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @param options
|
|
29
|
+
*/
|
|
30
|
+
declare function createdBundledHighlighter<BundledLangs extends string, BundledThemes extends string>(options: CreatedBundledHighlighterOptions<BundledLangs, BundledThemes>): CreateHighlighterFactory<BundledLangs, BundledThemes>;
|
|
31
|
+
/**
|
|
32
|
+
* Create a `createHighlighter` function with bundled themes and languages.
|
|
33
|
+
*
|
|
34
|
+
* @deprecated Use `createdBundledHighlighter({ langs, themes, engine })` signature instead.
|
|
35
|
+
*/
|
|
36
|
+
declare function createdBundledHighlighter<BundledLangs extends string, BundledThemes extends string>(bundledLanguages: Record<BundledLangs, LanguageInput>, bundledThemes: Record<BundledThemes, ThemeInput>, loadWasm: HighlighterCoreOptions['loadWasm']): CreateHighlighterFactory<BundledLangs, BundledThemes>;
|
|
37
|
+
interface ShorthandsBundle<L extends string, T extends string> {
|
|
38
|
+
/**
|
|
39
|
+
* Shorthand for `codeToHtml` with auto-loaded theme and language.
|
|
40
|
+
* A singleton highlighter it maintained internally.
|
|
41
|
+
*
|
|
42
|
+
* Differences from `highlighter.codeToHtml()`, this function is async.
|
|
43
|
+
*/
|
|
44
|
+
codeToHtml: (code: string, options: CodeToHastOptions<L, T>) => Promise<string>;
|
|
45
|
+
/**
|
|
46
|
+
* Shorthand for `codeToHtml` with auto-loaded theme and language.
|
|
47
|
+
* A singleton highlighter it maintained internally.
|
|
48
|
+
*
|
|
49
|
+
* Differences from `highlighter.codeToHtml()`, this function is async.
|
|
50
|
+
*/
|
|
51
|
+
codeToHast: (code: string, options: CodeToHastOptions<L, T>) => Promise<Root>;
|
|
52
|
+
/**
|
|
53
|
+
* Shorthand for `codeToTokens` with auto-loaded theme and language.
|
|
54
|
+
* A singleton highlighter it maintained internally.
|
|
55
|
+
*
|
|
56
|
+
* Differences from `highlighter.codeToTokens()`, this function is async.
|
|
57
|
+
*/
|
|
58
|
+
codeToTokens: (code: string, options: CodeToTokensOptions<L, T>) => Promise<TokensResult>;
|
|
59
|
+
/**
|
|
60
|
+
* Shorthand for `codeToTokensBase` with auto-loaded theme and language.
|
|
61
|
+
* A singleton highlighter it maintained internally.
|
|
62
|
+
*
|
|
63
|
+
* Differences from `highlighter.codeToTokensBase()`, this function is async.
|
|
64
|
+
*/
|
|
65
|
+
codeToTokensBase: (code: string, options: RequireKeys<CodeToTokensBaseOptions<L, T>, 'theme' | 'lang'>) => Promise<ThemedToken[][]>;
|
|
66
|
+
/**
|
|
67
|
+
* Shorthand for `codeToTokensWithThemes` with auto-loaded theme and language.
|
|
68
|
+
* A singleton highlighter it maintained internally.
|
|
69
|
+
*
|
|
70
|
+
* Differences from `highlighter.codeToTokensWithThemes()`, this function is async.
|
|
71
|
+
*/
|
|
72
|
+
codeToTokensWithThemes: (code: string, options: RequireKeys<CodeToTokensWithThemesOptions<L, T>, 'themes' | 'lang'>) => Promise<ThemedTokenWithVariants[][]>;
|
|
73
|
+
/**
|
|
74
|
+
* Get the singleton highlighter.
|
|
75
|
+
*/
|
|
76
|
+
getSingletonHighlighter: (options?: Partial<BundledHighlighterOptions<L, T>>) => Promise<HighlighterGeneric<L, T>>;
|
|
77
|
+
/**
|
|
78
|
+
* Shorthand for `getLastGrammarState` with auto-loaded theme and language.
|
|
79
|
+
* A singleton highlighter it maintained internally.
|
|
80
|
+
*/
|
|
81
|
+
getLastGrammarState: (code: string, options: CodeToTokensBaseOptions<L, T>) => Promise<GrammarState>;
|
|
82
|
+
}
|
|
83
|
+
declare function makeSingletonHighlighter<L extends string, T extends string>(createHighlighter: CreateHighlighterFactory<L, T>): (options?: Partial<BundledHighlighterOptions<L, T>>) => Promise<HighlighterGeneric<L, T>>;
|
|
84
|
+
declare function createSingletonShorthands<L extends string, T extends string>(createHighlighter: CreateHighlighterFactory<L, T>): ShorthandsBundle<L, T>;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Create a Shiki core highlighter instance, with no languages or themes bundled.
|
|
88
|
+
* Wasm and each language and theme must be loaded manually.
|
|
89
|
+
*
|
|
90
|
+
* @see http://shiki.style/guide/bundles#fine-grained-bundle
|
|
91
|
+
*/
|
|
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>;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Get the minimal shiki context for rendering.
|
|
111
|
+
*/
|
|
112
|
+
declare function createShikiInternal(options?: HighlighterCoreOptions): Promise<ShikiInternal>;
|
|
113
|
+
/**
|
|
114
|
+
* @deprecated Use `createShikiInternal` instead.
|
|
115
|
+
*/
|
|
116
|
+
declare function getShikiInternal(options?: HighlighterCoreOptions): Promise<ShikiInternal>;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Get the minimal shiki context for rendering.
|
|
120
|
+
*
|
|
121
|
+
* Synchronous version of `createShikiInternal`, which requires to provide the engine and all themes and languages upfront.
|
|
122
|
+
*/
|
|
123
|
+
declare function createShikiInternalSync(options: HighlighterCoreOptions<true>): ShikiInternal;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Set the default wasm loader for `loadWasm`.
|
|
127
|
+
* @internal
|
|
128
|
+
*/
|
|
129
|
+
declare function setDefaultWasmLoader(_loader: LoadWasmOptions): void;
|
|
130
|
+
|
|
131
|
+
declare function codeToHast(internal: ShikiInternal, code: string, options: CodeToHastOptions, transformerContext?: ShikiTransformerContextCommon): Root;
|
|
132
|
+
declare function tokensToHast(tokens: ThemedToken[][], options: CodeToHastRenderOptions, transformerContext: ShikiTransformerContextSource): Root;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Get highlighted code in HTML.
|
|
136
|
+
*/
|
|
137
|
+
declare function codeToHtml(internal: ShikiInternal, code: string, options: CodeToHastOptions): string;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* High-level code-to-tokens API.
|
|
141
|
+
*
|
|
142
|
+
* It will use `codeToTokensWithThemes` or `codeToTokensBase` based on the options.
|
|
143
|
+
*/
|
|
144
|
+
declare function codeToTokens(internal: ShikiInternal, code: string, options: CodeToTokensOptions): TokensResult;
|
|
145
|
+
|
|
146
|
+
declare function tokenizeAnsiWithTheme(theme: ThemeRegistrationResolved, fileContents: string, options?: TokenizeWithThemeOptions): ThemedToken[][];
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Code to tokens, with a simple theme.
|
|
150
|
+
*/
|
|
151
|
+
declare function codeToTokensBase(internal: ShikiInternal, code: string, options?: CodeToTokensBaseOptions): ThemedToken[][];
|
|
152
|
+
declare function tokenizeWithTheme(code: string, grammar: IGrammar, theme: ThemeRegistrationResolved, colorMap: string[], options: TokenizeWithThemeOptions): ThemedToken[][];
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Get tokens with multiple themes
|
|
156
|
+
*/
|
|
157
|
+
declare function codeToTokensWithThemes(internal: ShikiInternal, code: string, options: CodeToTokensWithThemesOptions): ThemedTokenWithVariants[][];
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Normalize a textmate theme to shiki theme
|
|
161
|
+
*/
|
|
162
|
+
declare function normalizeTheme(rawTheme: ThemeRegistrationAny): ThemeRegistrationResolved;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* A built-in transformer to add decorations to the highlighted code.
|
|
166
|
+
*/
|
|
167
|
+
declare function transformerDecorations(): ShikiTransformer;
|
|
168
|
+
|
|
169
|
+
declare function toArray<T>(x: MaybeArray<T>): T[];
|
|
170
|
+
/**
|
|
171
|
+
* Split a string into lines, each line preserves the line ending.
|
|
172
|
+
*/
|
|
173
|
+
declare function splitLines(code: string, preserveEnding?: boolean): [string, number][];
|
|
174
|
+
/**
|
|
175
|
+
* Check if the language is plaintext that is ignored by Shiki.
|
|
176
|
+
*
|
|
177
|
+
* Hard-coded plain text languages: `plaintext`, `txt`, `text`, `plain`.
|
|
178
|
+
*/
|
|
179
|
+
declare function isPlainLang(lang: string | null | undefined): lang is PlainTextLanguage;
|
|
180
|
+
/**
|
|
181
|
+
* Check if the language is specially handled or bypassed by Shiki.
|
|
182
|
+
*
|
|
183
|
+
* Hard-coded languages: `ansi` and plaintexts like `plaintext`, `txt`, `text`, `plain`.
|
|
184
|
+
*/
|
|
185
|
+
declare function isSpecialLang(lang: any): lang is SpecialLanguage;
|
|
186
|
+
/**
|
|
187
|
+
* Check if the theme is specially handled or bypassed by Shiki.
|
|
188
|
+
*
|
|
189
|
+
* Hard-coded themes: `none`.
|
|
190
|
+
*/
|
|
191
|
+
declare function isNoneTheme(theme: string | ThemeInput | null | undefined): theme is 'none';
|
|
192
|
+
/**
|
|
193
|
+
* Check if the theme is specially handled or bypassed by Shiki.
|
|
194
|
+
*
|
|
195
|
+
* Hard-coded themes: `none`.
|
|
196
|
+
*/
|
|
197
|
+
declare function isSpecialTheme(theme: string | ThemeInput | null | undefined): theme is SpecialTheme;
|
|
198
|
+
/**
|
|
199
|
+
* Utility to append class to a hast node
|
|
200
|
+
*
|
|
201
|
+
* If the `property.class` is a string, it will be splitted by space and converted to an array.
|
|
202
|
+
*/
|
|
203
|
+
declare function addClassToHast(node: Element, className: string | string[]): Element;
|
|
204
|
+
/**
|
|
205
|
+
* Split a token into multiple tokens by given offsets.
|
|
206
|
+
*
|
|
207
|
+
* The offsets are relative to the token, and should be sorted.
|
|
208
|
+
*/
|
|
209
|
+
declare function splitToken<T extends Pick<ThemedToken, 'content' | 'offset'>>(token: T, offsets: number[]): T[];
|
|
210
|
+
/**
|
|
211
|
+
* Split 2D tokens array by given breakpoints.
|
|
212
|
+
*/
|
|
213
|
+
declare function splitTokens<T extends Pick<ThemedToken, 'content' | 'offset'>>(tokens: T[][], breakpoints: number[] | Set<number>): T[][];
|
|
214
|
+
/**
|
|
215
|
+
* Normalize a getter to a promise.
|
|
216
|
+
*/
|
|
217
|
+
declare function normalizeGetter<T>(p: MaybeGetter<T>): Promise<T>;
|
|
218
|
+
declare function resolveColorReplacements(theme: ThemeRegistrationAny | string, options?: TokenizeWithThemeOptions): {
|
|
219
|
+
[x: string]: string;
|
|
220
|
+
};
|
|
221
|
+
declare function applyColorReplacements(color: string, replacements?: Record<string, string>): string;
|
|
222
|
+
declare function applyColorReplacements(color?: string | undefined, replacements?: Record<string, string>): string | undefined;
|
|
223
|
+
declare function getTokenStyleObject(token: TokenStyles): Record<string, string>;
|
|
224
|
+
declare function stringifyTokenStyle(token: Record<string, string>): string;
|
|
225
|
+
/**
|
|
226
|
+
* Creates a converter between index and position in a code block.
|
|
227
|
+
*
|
|
228
|
+
* Overflow/underflow are unchecked.
|
|
229
|
+
*/
|
|
230
|
+
declare function createPositionConverter(code: string): {
|
|
231
|
+
lines: string[];
|
|
232
|
+
indexToPos: (index: number) => Position;
|
|
233
|
+
posToIndex: (line: number, character: number) => number;
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
export { type ShorthandsBundle, addClassToHast, applyColorReplacements, codeToHast, codeToHtml, codeToTokens, codeToTokensBase, codeToTokensWithThemes, createHighlighterCore, createHighlighterCoreSync, createPositionConverter, createShikiInternal, createShikiInternalSync, createSingletonShorthands, createdBundledHighlighter, getHighlighterCore, getShikiInternal, getSingletonHighlighterCore, getTokenStyleObject, isNoneTheme, isPlainLang, isSpecialLang, isSpecialTheme, makeSingletonHighlighter, makeSingletonHighlighterCore, normalizeGetter, normalizeTheme, resolveColorReplacements, setDefaultWasmLoader, splitLines, splitToken, splitTokens, stringifyTokenStyle, toArray, tokenizeAnsiWithTheme, tokenizeWithTheme, tokensToHast, transformerDecorations };
|