shiki 3.2.2 → 3.4.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.
@@ -1,4 +1,4 @@
1
- import { R as Root } from './types/index.d.mjs';
1
+ import * as hast from 'hast';
2
2
  import * as _shikijs_types from '@shikijs/types';
3
3
  import { HighlighterGeneric } from '@shikijs/types';
4
4
  import { BundledLanguage } from './langs.mjs';
@@ -20,12 +20,12 @@ type Highlighter = HighlighterGeneric<BundledLanguage, BundledTheme>;
20
20
  */
21
21
  declare const createHighlighter: _shikijs_types.CreateHighlighterFactory<BundledLanguage, BundledTheme>;
22
22
  declare const codeToHtml: (code: string, options: _shikijs_types.CodeToHastOptions<BundledLanguage, BundledTheme>) => Promise<string>;
23
- declare const codeToHast: (code: string, options: _shikijs_types.CodeToHastOptions<BundledLanguage, BundledTheme>) => Promise<Root>;
23
+ declare const codeToHast: (code: string, options: _shikijs_types.CodeToHastOptions<BundledLanguage, BundledTheme>) => Promise<hast.Root>;
24
24
  declare const codeToTokens: (code: string, options: _shikijs_types.CodeToTokensOptions<BundledLanguage, BundledTheme>) => Promise<_shikijs_types.TokensResult>;
25
25
  declare const codeToTokensBase: (code: string, options: _shikijs_types.RequireKeys<_shikijs_types.CodeToTokensBaseOptions<BundledLanguage, BundledTheme>, "theme" | "lang">) => Promise<_shikijs_types.ThemedToken[][]>;
26
26
  declare const codeToTokensWithThemes: (code: string, options: _shikijs_types.RequireKeys<_shikijs_types.CodeToTokensWithThemesOptions<BundledLanguage, BundledTheme>, "lang" | "themes">) => Promise<_shikijs_types.ThemedTokenWithVariants[][]>;
27
27
  declare const getSingletonHighlighter: (options?: Partial<_shikijs_types.BundledHighlighterOptions<BundledLanguage, BundledTheme>> | undefined) => Promise<HighlighterGeneric<BundledLanguage, BundledTheme>>;
28
- declare const getLastGrammarState: ((element: _shikijs_types.ThemedToken[][] | Root) => _shikijs_types.GrammarState) | ((code: string, options: _shikijs_types.CodeToTokensBaseOptions<BundledLanguage, BundledTheme>) => Promise<_shikijs_types.GrammarState>);
28
+ declare const getLastGrammarState: ((element: _shikijs_types.ThemedToken[][] | hast.Root) => _shikijs_types.GrammarState) | ((code: string, options: _shikijs_types.CodeToTokensBaseOptions<BundledLanguage, BundledTheme>) => Promise<_shikijs_types.GrammarState>);
29
29
 
30
30
  export { BundledLanguage, BundledTheme, codeToHast, codeToHtml, codeToTokens, codeToTokensBase, codeToTokensWithThemes, createHighlighter, getLastGrammarState, getSingletonHighlighter };
31
31
  export type { Highlighter };
@@ -1,4 +1,4 @@
1
- import { R as Root } from './types/index.d.mjs';
1
+ import * as hast from 'hast';
2
2
  import * as _shikijs_types from '@shikijs/types';
3
3
  import { BundledLanguageInfo, DynamicImportLanguageRegistration, HighlighterGeneric } from '@shikijs/types';
4
4
  import { BundledTheme } from './themes.mjs';
@@ -28,12 +28,12 @@ type Highlighter = HighlighterGeneric<BundledLanguage, BundledTheme>;
28
28
  */
29
29
  declare const createHighlighter: _shikijs_types.CreateHighlighterFactory<BundledLanguage, BundledTheme>;
30
30
  declare const codeToHtml: (code: string, options: _shikijs_types.CodeToHastOptions<BundledLanguage, BundledTheme>) => Promise<string>;
31
- declare const codeToHast: (code: string, options: _shikijs_types.CodeToHastOptions<BundledLanguage, BundledTheme>) => Promise<Root>;
31
+ declare const codeToHast: (code: string, options: _shikijs_types.CodeToHastOptions<BundledLanguage, BundledTheme>) => Promise<hast.Root>;
32
32
  declare const codeToTokensBase: (code: string, options: _shikijs_types.RequireKeys<_shikijs_types.CodeToTokensBaseOptions<BundledLanguage, BundledTheme>, "theme" | "lang">) => Promise<_shikijs_types.ThemedToken[][]>;
33
33
  declare const codeToTokens: (code: string, options: _shikijs_types.CodeToTokensOptions<BundledLanguage, BundledTheme>) => Promise<_shikijs_types.TokensResult>;
34
34
  declare const codeToTokensWithThemes: (code: string, options: _shikijs_types.RequireKeys<_shikijs_types.CodeToTokensWithThemesOptions<BundledLanguage, BundledTheme>, "lang" | "themes">) => Promise<_shikijs_types.ThemedTokenWithVariants[][]>;
35
35
  declare const getSingletonHighlighter: (options?: Partial<_shikijs_types.BundledHighlighterOptions<BundledLanguage, BundledTheme>> | undefined) => Promise<HighlighterGeneric<BundledLanguage, BundledTheme>>;
36
- declare const getLastGrammarState: ((element: _shikijs_types.ThemedToken[][] | Root) => _shikijs_types.GrammarState) | ((code: string, options: _shikijs_types.CodeToTokensBaseOptions<BundledLanguage, BundledTheme>) => Promise<_shikijs_types.GrammarState>);
36
+ declare const getLastGrammarState: ((element: _shikijs_types.ThemedToken[][] | hast.Root) => _shikijs_types.GrammarState) | ((code: string, options: _shikijs_types.CodeToTokensBaseOptions<BundledLanguage, BundledTheme>) => Promise<_shikijs_types.GrammarState>);
37
37
 
38
38
  export { BundledTheme, bundledLanguages, bundledLanguagesAlias, bundledLanguagesBase, bundledLanguagesInfo, codeToHast, codeToHtml, codeToTokens, codeToTokensBase, codeToTokensWithThemes, createHighlighter, getLastGrammarState, getSingletonHighlighter };
39
39
  export type { BundledLanguage, Highlighter };
@@ -1,493 +1 @@
1
- import { ShikiInternal, CodeToHastOptions, ShikiTransformerContextCommon, CodeToTokensOptions, TokensResult, CodeToTokensBaseOptions, ThemedToken, CodeToTokensWithThemesOptions, ThemedTokenWithVariants, ThemeRegistration, HighlighterCoreOptions, HighlighterCore, Position, CreateHighlighterFactory, HighlighterGeneric, Awaitable, RequireKeys, BundledHighlighterOptions, GrammarState, CreatedBundledHighlighterOptions, TokenStyles, ThemeInput, PlainTextLanguage, SpecialLanguage, SpecialTheme, MaybeGetter, ThemeRegistrationAny, ThemeRegistrationResolved, TokenizeWithThemeOptions, MaybeArray, Grammar, CodeToHastRenderOptions, ShikiTransformerContextSource, ShikiTransformer } from '@shikijs/types';
2
- export * from '@shikijs/types';
3
- import { a as RootContent, N as Nodes, E as Element, R as Root } from './types/index.d.mjs';
4
-
5
- type FormatSmartOptions = {
6
- /**
7
- * Prefer named character references (`&amp;`) where possible.
8
- */
9
- useNamedReferences?: boolean;
10
- /**
11
- * Prefer the shortest possible reference, if that results in less bytes.
12
- * **Note**: `useNamedReferences` can be omitted when using `useShortestReferences`.
13
- */
14
- useShortestReferences?: boolean;
15
- /**
16
- * Whether to omit semicolons when possible.
17
- * **Note**: This creates what HTML calls “parse errors” but is otherwise still valid HTML — don’t use this except when building a minifier.
18
- * Omitting semicolons is possible for certain named and numeric references in some cases.
19
- */
20
- omitOptionalSemicolons?: boolean;
21
- /**
22
- * Create character references which don’t fail in attributes.
23
- * **Note**: `attribute` only applies when operating dangerously with
24
- * `omitOptionalSemicolons: true`.
25
- */
26
- attribute?: boolean;
27
- };
28
-
29
- type CoreOptions = {
30
- /**
31
- * Whether to only escape the given subset of characters.
32
- */
33
- subset?: ReadonlyArray<string>;
34
- /**
35
- * Whether to only escape possibly dangerous characters.
36
- * Those characters are `"`, `&`, `'`, `<`, `>`, and `` ` ``.
37
- */
38
- escapeOnly?: boolean;
39
- };
40
-
41
- type Options$2 = CoreOptions & FormatSmartOptions;
42
-
43
- type Options$1 = Options$2;
44
-
45
- /**
46
- * Serialize hast as HTML.
47
- *
48
- * @param {Array<RootContent> | Nodes} tree
49
- * Tree to serialize.
50
- * @param {Options | null | undefined} [options]
51
- * Configuration (optional).
52
- * @returns {string}
53
- * Serialized HTML.
54
- */
55
- declare function toHtml(tree: Array<RootContent> | Nodes, options?: Options | null | undefined): string;
56
- type CharacterReferences = Omit<Options$1, "attribute" | "escapeOnly" | "subset">;
57
- /**
58
- * Configuration.
59
- */
60
- type Options = {
61
- /**
62
- * Do not encode some characters which cause XSS vulnerabilities in older
63
- * browsers (default: `false`).
64
- *
65
- * > ⚠️ **Danger**: only set this if you completely trust the content.
66
- */
67
- allowDangerousCharacters?: boolean | null | undefined;
68
- /**
69
- * Allow `raw` nodes and insert them as raw HTML (default: `false`).
70
- *
71
- * When `false`, `Raw` nodes are encoded.
72
- *
73
- * > ⚠️ **Danger**: only set this if you completely trust the content.
74
- */
75
- allowDangerousHtml?: boolean | null | undefined;
76
- /**
77
- * Do not encode characters which cause parse errors (even though they work),
78
- * to save bytes (default: `false`).
79
- *
80
- * Not used in the SVG space.
81
- *
82
- * > 👉 **Note**: intentionally creates parse errors in markup (how parse
83
- * > errors are handled is well defined, so this works but isn’t pretty).
84
- */
85
- allowParseErrors?: boolean | null | undefined;
86
- /**
87
- * Use “bogus comments” instead of comments to save byes: `<?charlie>`
88
- * instead of `<!--charlie-->` (default: `false`).
89
- *
90
- * > 👉 **Note**: intentionally creates parse errors in markup (how parse
91
- * > errors are handled is well defined, so this works but isn’t pretty).
92
- */
93
- bogusComments?: boolean | null | undefined;
94
- /**
95
- * Configure how to serialize character references (optional).
96
- */
97
- characterReferences?: CharacterReferences | null | undefined;
98
- /**
99
- * Close SVG elements without any content with slash (`/`) on the opening tag
100
- * instead of an end tag: `<circle />` instead of `<circle></circle>`
101
- * (default: `false`).
102
- *
103
- * See `tightSelfClosing` to control whether a space is used before the
104
- * slash.
105
- *
106
- * Not used in the HTML space.
107
- */
108
- closeEmptyElements?: boolean | null | undefined;
109
- /**
110
- * Close self-closing nodes with an extra slash (`/`): `<img />` instead of
111
- * `<img>` (default: `false`).
112
- *
113
- * See `tightSelfClosing` to control whether a space is used before the
114
- * slash.
115
- *
116
- * Not used in the SVG space.
117
- */
118
- closeSelfClosing?: boolean | null | undefined;
119
- /**
120
- * Collapse empty attributes: get `class` instead of `class=""` (default:
121
- * `false`).
122
- *
123
- * Not used in the SVG space.
124
- *
125
- * > 👉 **Note**: boolean attributes (such as `hidden`) are always collapsed.
126
- */
127
- collapseEmptyAttributes?: boolean | null | undefined;
128
- /**
129
- * Omit optional opening and closing tags (default: `false`).
130
- *
131
- * For example, in `<ol><li>one</li><li>two</li></ol>`, both `</li>` closing
132
- * tags can be omitted.
133
- * The first because it’s followed by another `li`, the last because it’s
134
- * followed by nothing.
135
- *
136
- * Not used in the SVG space.
137
- */
138
- omitOptionalTags?: boolean | null | undefined;
139
- /**
140
- * Leave attributes unquoted if that results in less bytes (default: `false`).
141
- *
142
- * Not used in the SVG space.
143
- */
144
- preferUnquoted?: boolean | null | undefined;
145
- /**
146
- * Use the other quote if that results in less bytes (default: `false`).
147
- */
148
- quoteSmart?: boolean | null | undefined;
149
- /**
150
- * Preferred quote to use (default: `'"'`).
151
- */
152
- quote?: Quote | null | undefined;
153
- /**
154
- * When an `<svg>` element is found in the HTML space, this package already
155
- * automatically switches to and from the SVG space when entering and exiting
156
- * it (default: `'html'`).
157
- *
158
- * > 👉 **Note**: hast is not XML.
159
- * > It supports SVG as embedded in HTML.
160
- * > It does not support the features available in XML.
161
- * > Passing SVG might break but fragments of modern SVG should be fine.
162
- * > Use [`xast`][xast] if you need to support SVG as XML.
163
- */
164
- space?: Space | null | undefined;
165
- /**
166
- * Join attributes together, without whitespace, if possible: get
167
- * `class="a b"title="c d"` instead of `class="a b" title="c d"` to save
168
- * bytes (default: `false`).
169
- *
170
- * Not used in the SVG space.
171
- *
172
- * > 👉 **Note**: intentionally creates parse errors in markup (how parse
173
- * > errors are handled is well defined, so this works but isn’t pretty).
174
- */
175
- tightAttributes?: boolean | null | undefined;
176
- /**
177
- * Join known comma-separated attribute values with just a comma (`,`),
178
- * instead of padding them on the right as well (`,␠`, where `␠` represents a
179
- * space) (default: `false`).
180
- */
181
- tightCommaSeparatedLists?: boolean | null | undefined;
182
- /**
183
- * Drop unneeded spaces in doctypes: `<!doctypehtml>` instead of
184
- * `<!doctype html>` to save bytes (default: `false`).
185
- *
186
- * > 👉 **Note**: intentionally creates parse errors in markup (how parse
187
- * > errors are handled is well defined, so this works but isn’t pretty).
188
- */
189
- tightDoctype?: boolean | null | undefined;
190
- /**
191
- * Do not use an extra space when closing self-closing elements: `<img/>`
192
- * instead of `<img />` (default: `false`).
193
- *
194
- * > 👉 **Note**: only used if `closeSelfClosing: true` or
195
- * > `closeEmptyElements: true`.
196
- */
197
- tightSelfClosing?: boolean | null | undefined;
198
- /**
199
- * Use a `<!DOCTYPE…` instead of `<!doctype…` (default: `false`).
200
- *
201
- * Useless except for XHTML.
202
- */
203
- upperDoctype?: boolean | null | undefined;
204
- /**
205
- * Tag names of elements to serialize without closing tag (default: `html-void-elements`).
206
- *
207
- * Not used in the SVG space.
208
- *
209
- * > 👉 **Note**: It’s highly unlikely that you want to pass this, because
210
- * > hast is not for XML, and HTML will not add more void elements.
211
- */
212
- voids?: ReadonlyArray<string> | null | undefined;
213
- };
214
- /**
215
- * HTML quotes for attribute values.
216
- */
217
- type Quote = "\"" | "'";
218
- /**
219
- * Namespace.
220
- */
221
- type Space = "html" | "svg";
222
-
223
- /**
224
- * Create a `createHighlighter` function with bundled themes, languages, and engine.
225
- *
226
- * @example
227
- * ```ts
228
- * const createHighlighter = createdBundledHighlighter({
229
- * langs: {
230
- * typescript: () => import('@shikijs/langs/typescript'),
231
- * // ...
232
- * },
233
- * themes: {
234
- * nord: () => import('@shikijs/themes/nord'),
235
- * // ...
236
- * },
237
- * engine: () => createOnigurumaEngine(), // or createJavaScriptRegexEngine()
238
- * })
239
- * ```
240
- *
241
- * @param options
242
- */
243
- declare function createdBundledHighlighter<BundledLangs extends string, BundledThemes extends string>(options: CreatedBundledHighlighterOptions<BundledLangs, BundledThemes>): CreateHighlighterFactory<BundledLangs, BundledThemes>;
244
- interface ShorthandsBundle<L extends string, T extends string> {
245
- /**
246
- * Shorthand for `codeToHtml` with auto-loaded theme and language.
247
- * A singleton highlighter it maintained internally.
248
- *
249
- * Differences from `highlighter.codeToHtml()`, this function is async.
250
- */
251
- codeToHtml: (code: string, options: CodeToHastOptions<L, T>) => Promise<string>;
252
- /**
253
- * Shorthand for `codeToHtml` with auto-loaded theme and language.
254
- * A singleton highlighter it maintained internally.
255
- *
256
- * Differences from `highlighter.codeToHtml()`, this function is async.
257
- */
258
- codeToHast: (code: string, options: CodeToHastOptions<L, T>) => Promise<Root>;
259
- /**
260
- * Shorthand for `codeToTokens` with auto-loaded theme and language.
261
- * A singleton highlighter it maintained internally.
262
- *
263
- * Differences from `highlighter.codeToTokens()`, this function is async.
264
- */
265
- codeToTokens: (code: string, options: CodeToTokensOptions<L, T>) => Promise<TokensResult>;
266
- /**
267
- * Shorthand for `codeToTokensBase` with auto-loaded theme and language.
268
- * A singleton highlighter it maintained internally.
269
- *
270
- * Differences from `highlighter.codeToTokensBase()`, this function is async.
271
- */
272
- codeToTokensBase: (code: string, options: RequireKeys<CodeToTokensBaseOptions<L, T>, 'theme' | 'lang'>) => Promise<ThemedToken[][]>;
273
- /**
274
- * Shorthand for `codeToTokensWithThemes` with auto-loaded theme and language.
275
- * A singleton highlighter it maintained internally.
276
- *
277
- * Differences from `highlighter.codeToTokensWithThemes()`, this function is async.
278
- */
279
- codeToTokensWithThemes: (code: string, options: RequireKeys<CodeToTokensWithThemesOptions<L, T>, 'themes' | 'lang'>) => Promise<ThemedTokenWithVariants[][]>;
280
- /**
281
- * Get the singleton highlighter.
282
- */
283
- getSingletonHighlighter: (options?: Partial<BundledHighlighterOptions<L, T>>) => Promise<HighlighterGeneric<L, T>>;
284
- /**
285
- * Shorthand for `getLastGrammarState` with auto-loaded theme and language.
286
- * A singleton highlighter it maintained internally.
287
- */
288
- getLastGrammarState: ((element: ThemedToken[][] | Root) => GrammarState) | ((code: string, options: CodeToTokensBaseOptions<L, T>) => Promise<GrammarState>);
289
- }
290
- declare function makeSingletonHighlighter<L extends string, T extends string>(createHighlighter: CreateHighlighterFactory<L, T>): (options?: Partial<BundledHighlighterOptions<L, T>>) => Promise<HighlighterGeneric<L, T>>;
291
- interface CreateSingletonShorthandsOptions<L extends string, T extends string> {
292
- /**
293
- * A custom function to guess embedded languages to be loaded.
294
- */
295
- guessEmbeddedLanguages?: (code: string, lang: string | undefined, highlighter: HighlighterGeneric<L, T>) => Awaitable<string[] | undefined>;
296
- }
297
- declare function createSingletonShorthands<L extends string, T extends string>(createHighlighter: CreateHighlighterFactory<L, T>, config?: CreateSingletonShorthandsOptions<L, T>): ShorthandsBundle<L, T>;
298
-
299
- /**
300
- * Create a Shiki core highlighter instance, with no languages or themes bundled.
301
- * Wasm and each language and theme must be loaded manually.
302
- *
303
- * @see http://shiki.style/guide/bundles#fine-grained-bundle
304
- */
305
- declare function createHighlighterCore(options: HighlighterCoreOptions<false>): Promise<HighlighterCore>;
306
- /**
307
- * Create a Shiki core highlighter instance, with no languages or themes bundled.
308
- * Wasm and each language and theme must be loaded manually.
309
- *
310
- * Synchronous version of `createHighlighterCore`, which requires to provide the engine and all themes and languages upfront.
311
- *
312
- * @see http://shiki.style/guide/bundles#fine-grained-bundle
313
- */
314
- declare function createHighlighterCoreSync(options: HighlighterCoreOptions<true>): HighlighterCore;
315
- declare function makeSingletonHighlighterCore(createHighlighter: typeof createHighlighterCore): (options: HighlighterCoreOptions) => Promise<HighlighterCore>;
316
- declare const getSingletonHighlighterCore: (options: HighlighterCoreOptions) => Promise<HighlighterCore>;
317
-
318
- /**
319
- * Get the minimal shiki context for rendering.
320
- */
321
- declare function createShikiInternal(options: HighlighterCoreOptions): Promise<ShikiInternal>;
322
-
323
- /**
324
- * Get the minimal shiki context for rendering.
325
- *
326
- * Synchronous version of `createShikiInternal`, which requires to provide the engine and all themes and languages upfront.
327
- */
328
- declare function createShikiInternalSync(options: HighlighterCoreOptions<true>): ShikiInternal;
329
-
330
- declare function codeToHast(internal: ShikiInternal, code: string, options: CodeToHastOptions, transformerContext?: ShikiTransformerContextCommon): Root;
331
- declare function tokensToHast(tokens: ThemedToken[][], options: CodeToHastRenderOptions, transformerContext: ShikiTransformerContextSource, grammarState?: GrammarState | undefined): Root;
332
-
333
- declare const hastToHtml: typeof toHtml;
334
- /**
335
- * Get highlighted code in HTML.
336
- */
337
- declare function codeToHtml(internal: ShikiInternal, code: string, options: CodeToHastOptions): string;
338
-
339
- /**
340
- * High-level code-to-tokens API.
341
- *
342
- * It will use `codeToTokensWithThemes` or `codeToTokensBase` based on the options.
343
- */
344
- declare function codeToTokens(internal: ShikiInternal, code: string, options: CodeToTokensOptions): TokensResult;
345
-
346
- declare function tokenizeAnsiWithTheme(theme: ThemeRegistrationResolved, fileContents: string, options?: TokenizeWithThemeOptions): ThemedToken[][];
347
-
348
- /**
349
- * Code to tokens, with a simple theme.
350
- */
351
- declare function codeToTokensBase(internal: ShikiInternal, code: string, options?: CodeToTokensBaseOptions): ThemedToken[][];
352
- declare function tokenizeWithTheme(code: string, grammar: Grammar, theme: ThemeRegistrationResolved, colorMap: string[], options: TokenizeWithThemeOptions): ThemedToken[][];
353
-
354
- /**
355
- * Get tokens with multiple themes
356
- */
357
- declare function codeToTokensWithThemes(internal: ShikiInternal, code: string, options: CodeToTokensWithThemesOptions): ThemedTokenWithVariants[][];
358
-
359
- /**
360
- * Normalize a textmate theme to shiki theme
361
- */
362
- declare function normalizeTheme(rawTheme: ThemeRegistrationAny): ThemeRegistrationResolved;
363
-
364
- interface CssVariablesThemeOptions {
365
- /**
366
- * Theme name. Need to unique if multiple css variables themes are created
367
- *
368
- * @default 'css-variables'
369
- */
370
- name?: string;
371
- /**
372
- * Prefix for css variables
373
- *
374
- * @default '--shiki-'
375
- */
376
- variablePrefix?: string;
377
- /**
378
- * Default value for css variables, the key is without the prefix
379
- *
380
- * @example `{ 'token-comment': '#888' }` will generate `var(--shiki-token-comment, #888)` for comments
381
- */
382
- variableDefaults?: Record<string, string>;
383
- /**
384
- * Enable font style
385
- *
386
- * @default true
387
- */
388
- fontStyle?: boolean;
389
- }
390
- /**
391
- * A factory function to create a css-variable-based theme
392
- *
393
- * @see https://shiki.style/guide/theme-colors#css-variables-theme
394
- */
395
- declare function createCssVariablesTheme(options?: CssVariablesThemeOptions): ThemeRegistration;
396
-
397
- /**
398
- * A built-in transformer to add decorations to the highlighted code.
399
- */
400
- declare function transformerDecorations(): ShikiTransformer;
401
-
402
- declare function resolveColorReplacements(theme: ThemeRegistrationAny | string, options?: TokenizeWithThemeOptions): Record<string, string | undefined>;
403
- declare function applyColorReplacements(color: string, replacements?: Record<string, string | undefined>): string;
404
- declare function applyColorReplacements(color?: string | undefined, replacements?: Record<string, string | undefined>): string | undefined;
405
-
406
- declare function toArray<T>(x: MaybeArray<T>): T[];
407
- /**
408
- * Normalize a getter to a promise.
409
- */
410
- declare function normalizeGetter<T>(p: MaybeGetter<T>): Promise<T>;
411
- /**
412
- * Check if the language is plaintext that is ignored by Shiki.
413
- *
414
- * Hard-coded plain text languages: `plaintext`, `txt`, `text`, `plain`.
415
- */
416
- declare function isPlainLang(lang: string | null | undefined): lang is PlainTextLanguage;
417
- /**
418
- * Check if the language is specially handled or bypassed by Shiki.
419
- *
420
- * Hard-coded languages: `ansi` and plaintexts like `plaintext`, `txt`, `text`, `plain`.
421
- */
422
- declare function isSpecialLang(lang: any): lang is SpecialLanguage;
423
- /**
424
- * Check if the theme is specially handled or bypassed by Shiki.
425
- *
426
- * Hard-coded themes: `none`.
427
- */
428
- declare function isNoneTheme(theme: string | ThemeInput | null | undefined): theme is 'none';
429
- /**
430
- * Check if the theme is specially handled or bypassed by Shiki.
431
- *
432
- * Hard-coded themes: `none`.
433
- */
434
- declare function isSpecialTheme(theme: string | ThemeInput | null | undefined): theme is SpecialTheme;
435
-
436
- /**
437
- * Utility to append class to a hast node
438
- *
439
- * If the `property.class` is a string, it will be splitted by space and converted to an array.
440
- */
441
- declare function addClassToHast(node: Element, className: string | string[]): Element;
442
-
443
- /**
444
- * Split a string into lines, each line preserves the line ending.
445
- */
446
- declare function splitLines(code: string, preserveEnding?: boolean): [string, number][];
447
- /**
448
- * Creates a converter between index and position in a code block.
449
- *
450
- * Overflow/underflow are unchecked.
451
- */
452
- declare function createPositionConverter(code: string): {
453
- lines: string[];
454
- indexToPos: (index: number) => Position;
455
- posToIndex: (line: number, character: number) => number;
456
- };
457
- /**
458
- * Guess embedded languages from given code and highlighter.
459
- *
460
- * When highlighter is provided, only bundled languages will be included.
461
- */
462
- declare function guessEmbeddedLanguages(code: string, _lang: string | undefined, highlighter?: HighlighterGeneric<any, any>): string[];
463
-
464
- /**
465
- * Split a token into multiple tokens by given offsets.
466
- *
467
- * The offsets are relative to the token, and should be sorted.
468
- */
469
- declare function splitToken<T extends Pick<ThemedToken, 'content' | 'offset'>>(token: T, offsets: number[]): T[];
470
- /**
471
- * Split 2D tokens array by given breakpoints.
472
- */
473
- declare function splitTokens<T extends Pick<ThemedToken, 'content' | 'offset'>>(tokens: T[][], breakpoints: number[] | Set<number>): T[][];
474
- declare function flatTokenVariants(merged: ThemedTokenWithVariants, variantsOrder: string[], cssVariablePrefix: string, defaultColor: string | boolean): ThemedToken;
475
- declare function getTokenStyleObject(token: TokenStyles): Record<string, string>;
476
- declare function stringifyTokenStyle(token: string | Record<string, string>): string;
477
-
478
- type DeprecationTarget = 3;
479
- /**
480
- * Enable runtime warning for deprecated APIs, for the future versions of Shiki.
481
- *
482
- * You can pass a major version to only warn for deprecations that will be removed in that version.
483
- *
484
- * By default, deprecation warning is set to 3 since Shiki v2.0.0
485
- */
486
- declare function enableDeprecationWarnings(emitDeprecation?: DeprecationTarget | boolean, emitError?: boolean): void;
487
- /**
488
- * @internal
489
- */
490
- declare function warnDeprecated(message: string, version?: DeprecationTarget): void;
491
-
492
- export { addClassToHast, applyColorReplacements, codeToHast, codeToHtml, codeToTokens, codeToTokensBase, codeToTokensWithThemes, createCssVariablesTheme, createHighlighterCore, createHighlighterCoreSync, createPositionConverter, createShikiInternal, createShikiInternalSync, createSingletonShorthands, createdBundledHighlighter, enableDeprecationWarnings, flatTokenVariants, getSingletonHighlighterCore, getTokenStyleObject, guessEmbeddedLanguages, hastToHtml, isNoneTheme, isPlainLang, isSpecialLang, isSpecialTheme, makeSingletonHighlighter, makeSingletonHighlighterCore, normalizeGetter, normalizeTheme, resolveColorReplacements, splitLines, splitToken, splitTokens, stringifyTokenStyle, toArray, tokenizeAnsiWithTheme, tokenizeWithTheme, tokensToHast, transformerDecorations, warnDeprecated };
493
- export type { CreateSingletonShorthandsOptions, CssVariablesThemeOptions, ShorthandsBundle };
1
+ export * from '@shikijs/core';
package/dist/core.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from '@shikijs/core';
2
2
  import '@shikijs/engine-oniguruma/wasm-inlined';
3
3
  import '@shikijs/engine-javascript';
4
+ import '@shikijs/engine-oniguruma';
4
5
  import '@shikijs/vscode-textmate';
@@ -1,83 +1 @@
1
- interface IOnigCaptureIndex {
2
- start: number;
3
- end: number;
4
- length: number;
5
- }
6
- interface IOnigMatch {
7
- index: number;
8
- captureIndices: IOnigCaptureIndex[];
9
- }
10
- declare const enum FindOption {
11
- None = 0,
12
- /**
13
- * equivalent of ONIG_OPTION_NOT_BEGIN_STRING: (str) isn't considered as begin of string (* fail \A)
14
- */
15
- NotBeginString = 1,
16
- /**
17
- * equivalent of ONIG_OPTION_NOT_END_STRING: (end) isn't considered as end of string (* fail \z, \Z)
18
- */
19
- NotEndString = 2,
20
- /**
21
- * equivalent of ONIG_OPTION_NOT_BEGIN_POSITION: (start) isn't considered as start position of search (* fail \G)
22
- */
23
- NotBeginPosition = 4,
24
- /**
25
- * used for debugging purposes.
26
- */
27
- DebugCall = 8
28
- }
29
- interface OnigScanner {
30
- findNextMatchSync(string: string | OnigString, startPosition: number, options: OrMask<FindOption>): IOnigMatch | null;
31
- dispose?(): void;
32
- }
33
- interface OnigString {
34
- readonly content: string;
35
- dispose?(): void;
36
- }
37
-
38
- /**
39
- * A union of given const enum values.
40
- */
41
- type OrMask<T extends number> = number;
42
-
43
- type Awaitable<T> = T | Promise<T>;
44
-
45
- interface PatternScanner extends OnigScanner {
46
- }
47
- interface RegexEngineString extends OnigString {
48
- }
49
- /**
50
- * Engine for RegExp matching and scanning.
51
- */
52
- interface RegexEngine {
53
- createScanner: (patterns: (string | RegExp)[]) => PatternScanner;
54
- createString: (s: string) => RegexEngineString;
55
- }
56
- interface WebAssemblyInstantiator {
57
- (importObject: Record<string, Record<string, WebAssembly.ImportValue>> | undefined): Promise<WebAssemblyInstance>;
58
- }
59
- type WebAssemblyInstance = WebAssembly.WebAssemblyInstantiatedSource | WebAssembly.Instance | WebAssembly.Instance['exports'];
60
- type OnigurumaLoadOptions = {
61
- instantiator: WebAssemblyInstantiator;
62
- } | {
63
- default: WebAssemblyInstantiator;
64
- } | {
65
- data: ArrayBufferView | ArrayBuffer | Response;
66
- };
67
- type LoadWasmOptionsPlain = OnigurumaLoadOptions | WebAssemblyInstantiator | ArrayBufferView | ArrayBuffer | Response;
68
- type LoadWasmOptions = Awaitable<LoadWasmOptionsPlain> | (() => Awaitable<LoadWasmOptionsPlain>);
69
-
70
- declare function loadWasm(options: LoadWasmOptions): Promise<void>;
71
-
72
- /**
73
- * Set the default wasm loader for `loadWasm`.
74
- * @internal
75
- */
76
- declare function setDefaultWasmLoader(_loader: LoadWasmOptions): void;
77
- /**
78
- * @internal
79
- */
80
- declare function getDefaultWasmLoader(): LoadWasmOptions | undefined;
81
- declare function createOnigurumaEngine(options?: LoadWasmOptions | null): Promise<RegexEngine>;
82
-
83
- export { createOnigurumaEngine, getDefaultWasmLoader, loadWasm, setDefaultWasmLoader };
1
+ export * from '@shikijs/engine-oniguruma';
package/dist/index.d.mts CHANGED
@@ -1,10 +1,10 @@
1
1
  export { Highlighter, codeToHast, codeToHtml, codeToTokens, codeToTokensBase, codeToTokensWithThemes, createHighlighter, getLastGrammarState, getSingletonHighlighter } from './bundle-full.mjs';
2
2
  export { BuiltinLanguage, BuiltinTheme } from './types.mjs';
3
3
  export { createJavaScriptRegexEngine, defaultJavaScriptRegexConstructor } from '@shikijs/engine-javascript';
4
- export { createOnigurumaEngine, loadWasm } from './engine-oniguruma.mjs';
4
+ export { createOnigurumaEngine, loadWasm } from '@shikijs/engine-oniguruma';
5
5
  export * from '@shikijs/core';
6
6
  export { BundledLanguage, bundledLanguages, bundledLanguagesAlias, bundledLanguagesBase, bundledLanguagesInfo } from './langs.mjs';
7
7
  export { BundledTheme, bundledThemes, bundledThemesInfo } from './themes.mjs';
8
- import './types/index.d.mjs';
8
+ import 'hast';
9
9
  import '@shikijs/types';
10
10
  import '@shikijs/core/types';
package/dist/types.d.mts CHANGED
@@ -1,8 +1,8 @@
1
- import { BundledLanguage } from './langs.mjs';
2
1
  import { BundledTheme } from './themes.mjs';
3
2
  export * from '@shikijs/core/types';
4
- import '@shikijs/types';
3
+ import { BundledLanguage } from './langs.mjs';
5
4
  import '@shikijs/core';
5
+ import '@shikijs/types';
6
6
 
7
7
  type BuiltinLanguage = BundledLanguage;
8
8
  type BuiltinTheme = BundledTheme;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "shiki",
3
3
  "type": "module",
4
- "version": "3.2.2",
4
+ "version": "3.4.0",
5
5
  "description": "A beautiful Syntax Highlighter.",
6
6
  "author": "Pine Wu <octref@gmail.com>; Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -48,22 +48,22 @@
48
48
  "dependencies": {
49
49
  "@shikijs/vscode-textmate": "^10.0.2",
50
50
  "@types/hast": "^3.0.4",
51
- "@shikijs/core": "3.2.2",
52
- "@shikijs/engine-javascript": "3.2.2",
53
- "@shikijs/themes": "3.2.2",
54
- "@shikijs/engine-oniguruma": "3.2.2",
55
- "@shikijs/types": "3.2.2",
56
- "@shikijs/langs": "3.2.2"
51
+ "@shikijs/engine-oniguruma": "3.4.0",
52
+ "@shikijs/themes": "3.4.0",
53
+ "@shikijs/types": "3.4.0",
54
+ "@shikijs/engine-javascript": "3.4.0",
55
+ "@shikijs/core": "3.4.0",
56
+ "@shikijs/langs": "3.4.0"
57
57
  },
58
58
  "devDependencies": {
59
59
  "rollup-plugin-copy": "^3.5.0",
60
- "tm-grammars": "^1.23.10",
61
- "tm-themes": "^1.10.3",
60
+ "tm-grammars": "^1.23.17",
61
+ "tm-themes": "^1.10.6",
62
62
  "vscode-oniguruma": "1.7.0"
63
63
  },
64
64
  "scripts": {
65
- "build": "rimraf dist && NODE_OPTIONS=--max-old-space-size=4096 rollup -c",
66
- "dev": "rollup -cw",
65
+ "build": "unbuild",
66
+ "dev": "unbuild --stub",
67
67
  "test": "vitest",
68
68
  "test:cf": "wrangler dev test/cf.ts --port 60001"
69
69
  }
@@ -1,344 +0,0 @@
1
- // ## Interfaces
2
-
3
- /**
4
- * Info associated with nodes by the ecosystem.
5
- *
6
- * This space is guaranteed to never be specified by unist or specifications
7
- * implementing unist.
8
- * But you can use it in utilities and plugins to store data.
9
- *
10
- * This type can be augmented to register custom data.
11
- * For example:
12
- *
13
- * ```ts
14
- * declare module 'unist' {
15
- * interface Data {
16
- * // `someNode.data.myId` is typed as `number | undefined`
17
- * myId?: number | undefined
18
- * }
19
- * }
20
- * ```
21
- */
22
- interface Data$1 {}
23
-
24
- /**
25
- * One place in a source file.
26
- */
27
- interface Point {
28
- /**
29
- * Line in a source file (1-indexed integer).
30
- */
31
- line: number;
32
-
33
- /**
34
- * Column in a source file (1-indexed integer).
35
- */
36
- column: number;
37
- /**
38
- * Character in a source file (0-indexed integer).
39
- */
40
- offset?: number | undefined;
41
- }
42
-
43
- /**
44
- * Position of a node in a source document.
45
- *
46
- * A position is a range between two points.
47
- */
48
- interface Position {
49
- /**
50
- * Place of the first character of the parsed source region.
51
- */
52
- start: Point;
53
-
54
- /**
55
- * Place of the first character after the parsed source region.
56
- */
57
- end: Point;
58
- }
59
-
60
- /**
61
- * Abstract unist node.
62
- *
63
- * The syntactic unit in unist syntax trees are called nodes.
64
- *
65
- * This interface is supposed to be extended.
66
- * If you can use {@link Literal} or {@link Parent}, you should.
67
- * But for example in markdown, a `thematicBreak` (`***`), is neither literal
68
- * nor parent, but still a node.
69
- */
70
- interface Node$1 {
71
- /**
72
- * Node type.
73
- */
74
- type: string;
75
-
76
- /**
77
- * Info from the ecosystem.
78
- */
79
- data?: Data$1 | undefined;
80
-
81
- /**
82
- * Position of a node in a source document.
83
- *
84
- * Nodes that are generated (not in the original source document) must not
85
- * have a position.
86
- */
87
- position?: Position | undefined;
88
- }
89
-
90
- // ## Interfaces
91
-
92
- /**
93
- * Info associated with hast nodes by the ecosystem.
94
- *
95
- * This space is guaranteed to never be specified by unist or hast.
96
- * But you can use it in utilities and plugins to store data.
97
- *
98
- * This type can be augmented to register custom data.
99
- * For example:
100
- *
101
- * ```ts
102
- * declare module 'hast' {
103
- * interface Data {
104
- * // `someNode.data.myId` is typed as `number | undefined`
105
- * myId?: number | undefined
106
- * }
107
- * }
108
- * ```
109
- */
110
- interface Data extends Data$1 {}
111
-
112
- /**
113
- * Info associated with an element.
114
- */
115
- interface Properties {
116
- [PropertyName: string]: boolean | number | string | null | undefined | Array<string | number>;
117
- }
118
-
119
- // ## Content maps
120
-
121
- /**
122
- * Union of registered hast nodes that can occur in {@link Element}.
123
- *
124
- * To register mote custom hast nodes, add them to {@link ElementContentMap}.
125
- * They will be automatically added here.
126
- */
127
- type ElementContent = ElementContentMap[keyof ElementContentMap];
128
-
129
- /**
130
- * Registry of all hast nodes that can occur as children of {@link Element}.
131
- *
132
- * For a union of all {@link Element} children, see {@link ElementContent}.
133
- */
134
- interface ElementContentMap {
135
- comment: Comment;
136
- element: Element;
137
- text: Text;
138
- }
139
-
140
- /**
141
- * Union of registered hast nodes that can occur in {@link Root}.
142
- *
143
- * To register custom hast nodes, add them to {@link RootContentMap}.
144
- * They will be automatically added here.
145
- */
146
- type RootContent = RootContentMap[keyof RootContentMap];
147
-
148
- /**
149
- * Registry of all hast nodes that can occur as children of {@link Root}.
150
- *
151
- * > 👉 **Note**: {@link Root} does not need to be an entire document.
152
- * > it can also be a fragment.
153
- *
154
- * For a union of all {@link Root} children, see {@link RootContent}.
155
- */
156
- interface RootContentMap {
157
- comment: Comment;
158
- doctype: Doctype;
159
- element: Element;
160
- text: Text;
161
- }
162
-
163
- /**
164
- * Union of registered hast nodes.
165
- *
166
- * To register custom hast nodes, add them to {@link RootContentMap} and other
167
- * places where relevant.
168
- * They will be automatically added here.
169
- */
170
- type Nodes = Root | RootContent;
171
-
172
- // ## Abstract nodes
173
-
174
- /**
175
- * Abstract hast node.
176
- *
177
- * This interface is supposed to be extended.
178
- * If you can use {@link Literal} or {@link Parent}, you should.
179
- * But for example in HTML, a `Doctype` is neither literal nor parent, but
180
- * still a node.
181
- *
182
- * To register custom hast nodes, add them to {@link RootContentMap} and other
183
- * places where relevant (such as {@link ElementContentMap}).
184
- *
185
- * For a union of all registered hast nodes, see {@link Nodes}.
186
- */
187
- interface Node extends Node$1 {
188
- /**
189
- * Info from the ecosystem.
190
- */
191
- data?: Data | undefined;
192
- }
193
-
194
- /**
195
- * Abstract hast node that contains the smallest possible value.
196
- *
197
- * This interface is supposed to be extended if you make custom hast nodes.
198
- *
199
- * For a union of all registered hast literals, see {@link Literals}.
200
- */
201
- interface Literal extends Node {
202
- /**
203
- * Plain-text value.
204
- */
205
- value: string;
206
- }
207
-
208
- /**
209
- * Abstract hast node that contains other hast nodes (*children*).
210
- *
211
- * This interface is supposed to be extended if you make custom hast nodes.
212
- *
213
- * For a union of all registered hast parents, see {@link Parents}.
214
- */
215
- interface Parent extends Node {
216
- /**
217
- * List of children.
218
- */
219
- children: RootContent[];
220
- }
221
-
222
- // ## Concrete nodes
223
-
224
- /**
225
- * HTML comment.
226
- */
227
- interface Comment extends Literal {
228
- /**
229
- * Node type of HTML comments in hast.
230
- */
231
- type: "comment";
232
- /**
233
- * Data associated with the comment.
234
- */
235
- data?: CommentData | undefined;
236
- }
237
-
238
- /**
239
- * Info associated with hast comments by the ecosystem.
240
- */
241
- interface CommentData extends Data {}
242
-
243
- /**
244
- * HTML document type.
245
- */
246
- interface Doctype extends Node$1 {
247
- /**
248
- * Node type of HTML document types in hast.
249
- */
250
- type: "doctype";
251
- /**
252
- * Data associated with the doctype.
253
- */
254
- data?: DoctypeData | undefined;
255
- }
256
-
257
- /**
258
- * Info associated with hast doctypes by the ecosystem.
259
- */
260
- interface DoctypeData extends Data {}
261
-
262
- /**
263
- * HTML element.
264
- */
265
- interface Element extends Parent {
266
- /**
267
- * Node type of elements.
268
- */
269
- type: "element";
270
- /**
271
- * Tag name (such as `'body'`) of the element.
272
- */
273
- tagName: string;
274
- /**
275
- * Info associated with the element.
276
- */
277
- properties: Properties;
278
- /**
279
- * Children of element.
280
- */
281
- children: ElementContent[];
282
- /**
283
- * When the `tagName` field is `'template'`, a `content` field can be
284
- * present.
285
- */
286
- content?: Root | undefined;
287
- /**
288
- * Data associated with the element.
289
- */
290
- data?: ElementData | undefined;
291
- }
292
-
293
- /**
294
- * Info associated with hast elements by the ecosystem.
295
- */
296
- interface ElementData extends Data {}
297
-
298
- /**
299
- * Document fragment or a whole document.
300
- *
301
- * Should be used as the root of a tree and must not be used as a child.
302
- *
303
- * Can also be used as the value for the content field on a `'template'` element.
304
- */
305
- interface Root extends Parent {
306
- /**
307
- * Node type of hast root.
308
- */
309
- type: "root";
310
- /**
311
- * Children of root.
312
- */
313
- children: RootContent[];
314
- /**
315
- * Data associated with the hast root.
316
- */
317
- data?: RootData | undefined;
318
- }
319
-
320
- /**
321
- * Info associated with hast root nodes by the ecosystem.
322
- */
323
- interface RootData extends Data {}
324
-
325
- /**
326
- * HTML character data (plain text).
327
- */
328
- interface Text extends Literal {
329
- /**
330
- * Node type of HTML character data (plain text) in hast.
331
- */
332
- type: "text";
333
- /**
334
- * Data associated with the text.
335
- */
336
- data?: TextData | undefined;
337
- }
338
-
339
- /**
340
- * Info associated with hast texts by the ecosystem.
341
- */
342
- interface TextData extends Data {}
343
-
344
- export type { Element as E, Nodes as N, Root as R, RootContent as a };