@shikijs/core 1.0.0-beta.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.
@@ -0,0 +1,363 @@
1
+ import { H as HighlighterGeneric, a as HighlighterCoreOptions, B as BundledHighlighterOptions, L as LanguageInput, T as ThemeInput, C as CodeToHastOptions, R as Root, b as RequireKeys, c as CodeToThemedTokensOptions, d as ThemedToken, e as CodeToTokensWithThemesOptions, f as ThemedTokenWithVariants, M as MaybeArray, S as SpecialTheme, E as Element, g as ShikiInternal, I as IGrammar, h as ThemeRegistrationResolved, i as TokenizeWithThemeOptions, j as ShikiTransformerContextCommon, N as Nodes$1, k as RootContent$1, l as ThemeRegistrationAny } from './chunk-types.mjs';
2
+ export { A as AnsiLanguage, o as Awaitable, $ as BundledLanguageInfo, a0 as BundledThemeInfo, y as CodeOptionsMeta, w as CodeOptionsMultipleThemes, v as CodeOptionsSingleTheme, x as CodeOptionsThemes, u as CodeToHastOptionsCommon, Z as DynamicImportLanguageRegistration, _ as DynamicImportThemeRegistration, F as FontStyle, U as HtmlRendererOptions, Q as HtmlRendererOptionsCommon, m as IRawGrammar, t as LanguageRegistration, p as MaybeGetter, q as MaybeModule, P as PlainTextLanguage, m as RawGrammar, s as ResolveBundleKey, O as ShikiTransformer, K as ShikiTransformerContext, J as ShikiTransformerContextMeta, a1 as ShikijiTransformer, a2 as ShikijiTransformerContext, a3 as ShikijiTransformerContextCommon, n as SpecialLanguage, r as StringLiteralUnion, G as ThemeRegistration, D as ThemeRegistrationRaw, W as ThemedTokenExplanation, V as ThemedTokenScopeExplanation, X as TokenBase, Y as TokenStyles, z as TransformerOptions } from './chunk-types.mjs';
3
+ import { L as LoadWasmOptions } from './chunk-index.mjs';
4
+ export { l as loadWasm } from './chunk-index.mjs';
5
+
6
+ type HighlighterCore = HighlighterGeneric<never, never>;
7
+ /**
8
+ * Create a Shiki core highlighter instance, with no languages or themes bundled.
9
+ * Wasm and each language and theme must be loaded manually.
10
+ *
11
+ * @see http://shiki.style/guide/install#fine-grained-bundle
12
+ */
13
+ declare function getHighlighterCore(options?: HighlighterCoreOptions): Promise<HighlighterCore>;
14
+
15
+ type GetHighlighterFactory<L extends string, T extends string> = (options?: BundledHighlighterOptions<L, T>) => Promise<HighlighterGeneric<L, T>>;
16
+ /**
17
+ * Create a `getHighlighter` function with bundled themes and languages.
18
+ *
19
+ * @param bundledLanguages
20
+ * @param bundledThemes
21
+ * @param loadWasm
22
+ */
23
+ declare function createdBundledHighlighter<BundledLangs extends string, BundledThemes extends string>(bundledLanguages: Record<BundledLangs, LanguageInput>, bundledThemes: Record<BundledThemes, ThemeInput>, loadWasm: HighlighterCoreOptions['loadWasm']): GetHighlighterFactory<BundledLangs, BundledThemes>;
24
+ interface ShorthandsBundle<L extends string, T extends string> {
25
+ /**
26
+ * Shorthand for `codeToHtml` with auto-loaded theme and language.
27
+ * A singleton highlighter it maintained internally.
28
+ *
29
+ * Differences from `highlighter.codeToHtml()`, this function is async.
30
+ */
31
+ codeToHtml(code: string, options: CodeToHastOptions<L, T>): Promise<string>;
32
+ /**
33
+ * Shorthand for `codeToHtml` with auto-loaded theme and language.
34
+ * A singleton highlighter it maintained internally.
35
+ *
36
+ * Differences from `highlighter.codeToHtml()`, this function is async.
37
+ */
38
+ codeToHast(code: string, options: CodeToHastOptions<L, T>): Promise<Root>;
39
+ /**
40
+ * Shorthand for `codeToThemedTokens` with auto-loaded theme and language.
41
+ * A singleton highlighter it maintained internally.
42
+ *
43
+ * Differences from `highlighter.codeToThemedTokens()`, this function is async.
44
+ */
45
+ codeToThemedTokens(code: string, options: RequireKeys<CodeToThemedTokensOptions<L, T>, 'theme' | 'lang'>): Promise<ThemedToken[][]>;
46
+ /**
47
+ * Shorthand for `codeToTokensWithThemes` with auto-loaded theme and language.
48
+ * A singleton highlighter it maintained internally.
49
+ *
50
+ * Differences from `highlighter.codeToTokensWithThemes()`, this function is async.
51
+ */
52
+ codeToTokensWithThemes(code: string, options: RequireKeys<CodeToTokensWithThemesOptions<L, T>, 'themes' | 'lang'>): Promise<ThemedTokenWithVariants[][]>;
53
+ /**
54
+ * Get internal singleton highlighter.
55
+ *
56
+ * @internal
57
+ */
58
+ getSingletonHighlighter(): Promise<HighlighterGeneric<L, T>>;
59
+ }
60
+ declare function createSingletonShorthands<L extends string, T extends string>(getHighlighter: GetHighlighterFactory<L, T>): ShorthandsBundle<L, T>;
61
+
62
+ declare function toArray<T>(x: MaybeArray<T>): T[];
63
+ /**
64
+ * Slipt a string into lines, each line preserves the line ending.
65
+ */
66
+ declare function splitLines(str: string): [code: string, offset: number][];
67
+ /**
68
+ * Check if the language is plaintext that is ignored by Shiki.
69
+ *
70
+ * Hard-coded plain text languages: `plaintext`, `txt`, `text`, `plain`.
71
+ */
72
+ declare function isPlainLang(lang: string | null | undefined): boolean;
73
+ /**
74
+ * Check if the language is specially handled or bypassed by Shiki.
75
+ *
76
+ * Hard-coded languages: `ansi` and plaintexts like `plaintext`, `txt`, `text`, `plain`.
77
+ */
78
+ declare function isSpecialLang(lang: string): boolean;
79
+ /**
80
+ * Check if the theme is specially handled or bypassed by Shiki.
81
+ *
82
+ * Hard-coded themes: `none`.
83
+ */
84
+ declare function isNoneTheme(theme: string | ThemeInput | null | undefined): theme is 'none';
85
+ /**
86
+ * Check if the theme is specially handled or bypassed by Shiki.
87
+ *
88
+ * Hard-coded themes: `none`.
89
+ */
90
+ declare function isSpecialTheme(theme: string | ThemeInput | null | undefined): theme is SpecialTheme;
91
+ /**
92
+ * Utility to append class to a hast node
93
+ *
94
+ * If the `property.class` is a string, it will be splitted by space and converted to an array.
95
+ */
96
+ declare function addClassToHast(node: Element, className: string | string[]): void;
97
+ /**
98
+ * Split a token into multiple tokens by given offsets.
99
+ *
100
+ * The offsets are relative to the token, and should be sorted.
101
+ */
102
+ declare function splitToken<T extends Pick<ThemedToken, 'content' | 'offset'>>(token: T, offsets: number[]): T[];
103
+ declare function applyColorReplacements(color: string, replacements?: Record<string, string>): string;
104
+ /**
105
+ * @deprecated Use `isPlainLang` instead.
106
+ */
107
+ declare const isPlaintext: typeof isPlainLang;
108
+
109
+ /**
110
+ * Set the default wasm loader for `loadWasm`.
111
+ * @internal
112
+ */
113
+ declare function setDefaultWasmLoader(_loader: LoadWasmOptions): void;
114
+ /**
115
+ * Get the minimal shiki context for rendering.
116
+ */
117
+ declare function getShikiInternal(options?: HighlighterCoreOptions): Promise<ShikiInternal>;
118
+
119
+ declare function codeToThemedTokens(internal: ShikiInternal, code: string, options?: CodeToThemedTokensOptions): ThemedToken[][];
120
+ declare function tokenizeWithTheme(code: string, grammar: IGrammar, theme: ThemeRegistrationResolved, colorMap: string[], options: TokenizeWithThemeOptions): ThemedToken[][];
121
+
122
+ declare function tokenizeAnsiWithTheme(theme: ThemeRegistrationResolved, fileContents: string, options?: TokenizeWithThemeOptions): ThemedToken[][];
123
+
124
+ declare function codeToHast(internal: ShikiInternal, code: string, options: CodeToHastOptions, transformerContext?: ShikiTransformerContextCommon): Root;
125
+
126
+ type FormatSmartOptions = {
127
+ /**
128
+ * Prefer named character references (`&amp;`) where possible.
129
+ */
130
+ useNamedReferences?: boolean | undefined
131
+ /**
132
+ * Prefer the shortest possible reference, if that results in less bytes.
133
+ * **Note**: `useNamedReferences` can be omitted when using `useShortestReferences`.
134
+ */
135
+ useShortestReferences?: boolean | undefined
136
+ /**
137
+ * Whether to omit semicolons when possible.
138
+ * **Note**: This creates what HTML calls “parse errors” but is otherwise still valid HTML — don’t use this except when building a minifier.
139
+ * Omitting semicolons is possible for certain named and numeric references in some cases.
140
+ */
141
+ omitOptionalSemicolons?: boolean | undefined
142
+ /**
143
+ * Create character references which don’t fail in attributes.
144
+ * **Note**: `attribute` only applies when operating dangerously with
145
+ * `omitOptionalSemicolons: true`.
146
+ */
147
+ attribute?: boolean | undefined
148
+ }
149
+
150
+ type CoreOptions = {
151
+ /**
152
+ * Whether to only escape the given subset of characters.
153
+ */
154
+ subset?: string[] | undefined
155
+ /**
156
+ * Whether to only escape possibly dangerous characters.
157
+ * Those characters are `"`, `&`, `'`, `<`, `>`, and `` ` ``.
158
+ */
159
+ escapeOnly?: boolean | undefined
160
+ }
161
+
162
+ type Options$2 = CoreOptions &
163
+ FormatSmartOptions
164
+
165
+ type Options$1 = Options$2
166
+
167
+ /**
168
+ * Serialize hast as HTML.
169
+ *
170
+ * @param {Array<RootContent> | Nodes} tree
171
+ * Tree to serialize.
172
+ * @param {Options | null | undefined} [options]
173
+ * Configuration (optional).
174
+ * @returns {string}
175
+ * Serialized HTML.
176
+ */
177
+ declare function toHtml(tree: Array<RootContent> | Nodes, options?: Options | null | undefined): string;
178
+ type Nodes = Nodes$1;
179
+ type RootContent = RootContent$1;
180
+ type StringifyEntitiesOptions = Options$1;
181
+ type CharacterReferences = Omit<StringifyEntitiesOptions, 'attribute' | 'escapeOnly' | 'subset'>;
182
+ /**
183
+ * Configuration.
184
+ */
185
+ type Options = {
186
+ /**
187
+ * Do not encode some characters which cause XSS vulnerabilities in older
188
+ * browsers (default: `false`).
189
+ *
190
+ * > ⚠️ **Danger**: only set this if you completely trust the content.
191
+ */
192
+ allowDangerousCharacters?: boolean | null | undefined;
193
+ /**
194
+ * Allow `raw` nodes and insert them as raw HTML (default: `false`).
195
+ *
196
+ * When `false`, `Raw` nodes are encoded.
197
+ *
198
+ * > ⚠️ **Danger**: only set this if you completely trust the content.
199
+ */
200
+ allowDangerousHtml?: boolean | null | undefined;
201
+ /**
202
+ * Do not encode characters which cause parse errors (even though they work),
203
+ * to save bytes (default: `false`).
204
+ *
205
+ * Not used in the SVG space.
206
+ *
207
+ * > 👉 **Note**: intentionally creates parse errors in markup (how parse
208
+ * > errors are handled is well defined, so this works but isn’t pretty).
209
+ */
210
+ allowParseErrors?: boolean | null | undefined;
211
+ /**
212
+ * Use “bogus comments” instead of comments to save byes: `<?charlie>`
213
+ * instead of `<!--charlie-->` (default: `false`).
214
+ *
215
+ * > 👉 **Note**: intentionally creates parse errors in markup (how parse
216
+ * > errors are handled is well defined, so this works but isn’t pretty).
217
+ */
218
+ bogusComments?: boolean | null | undefined;
219
+ /**
220
+ * Configure how to serialize character references (optional).
221
+ */
222
+ characterReferences?: CharacterReferences | null | undefined;
223
+ /**
224
+ * Close SVG elements without any content with slash (`/`) on the opening tag
225
+ * instead of an end tag: `<circle />` instead of `<circle></circle>`
226
+ * (default: `false`).
227
+ *
228
+ * See `tightSelfClosing` to control whether a space is used before the
229
+ * slash.
230
+ *
231
+ * Not used in the HTML space.
232
+ */
233
+ closeEmptyElements?: boolean | null | undefined;
234
+ /**
235
+ * Close self-closing nodes with an extra slash (`/`): `<img />` instead of
236
+ * `<img>` (default: `false`).
237
+ *
238
+ * See `tightSelfClosing` to control whether a space is used before the
239
+ * slash.
240
+ *
241
+ * Not used in the SVG space.
242
+ */
243
+ closeSelfClosing?: boolean | null | undefined;
244
+ /**
245
+ * Collapse empty attributes: get `class` instead of `class=""` (default:
246
+ * `false`).
247
+ *
248
+ * Not used in the SVG space.
249
+ *
250
+ * > 👉 **Note**: boolean attributes (such as `hidden`) are always collapsed.
251
+ */
252
+ collapseEmptyAttributes?: boolean | null | undefined;
253
+ /**
254
+ * Omit optional opening and closing tags (default: `false`).
255
+ *
256
+ * For example, in `<ol><li>one</li><li>two</li></ol>`, both `</li>` closing
257
+ * tags can be omitted.
258
+ * The first because it’s followed by another `li`, the last because it’s
259
+ * followed by nothing.
260
+ *
261
+ * Not used in the SVG space.
262
+ */
263
+ omitOptionalTags?: boolean | null | undefined;
264
+ /**
265
+ * Leave attributes unquoted if that results in less bytes (default: `false`).
266
+ *
267
+ * Not used in the SVG space.
268
+ */
269
+ preferUnquoted?: boolean | null | undefined;
270
+ /**
271
+ * Preferred quote to use (default: `'"'`).
272
+ */
273
+ quote?: Quote | null | undefined;
274
+ /**
275
+ * Use the other quote if that results in less bytes (default: `false`).
276
+ */
277
+ quoteSmart?: boolean | null | undefined;
278
+ /**
279
+ * When an `<svg>` element is found in the HTML space, this package already
280
+ * automatically switches to and from the SVG space when entering and exiting
281
+ * it (default: `'html'`).
282
+ *
283
+ * > 👉 **Note**: hast is not XML.
284
+ * > It supports SVG as embedded in HTML.
285
+ * > It does not support the features available in XML.
286
+ * > Passing SVG might break but fragments of modern SVG should be fine.
287
+ * > Use [`xast`][xast] if you need to support SVG as XML.
288
+ */
289
+ space?: Space | null | undefined;
290
+ /**
291
+ * Join attributes together, without whitespace, if possible: get
292
+ * `class="a b"title="c d"` instead of `class="a b" title="c d"` to save
293
+ * bytes (default: `false`).
294
+ *
295
+ * Not used in the SVG space.
296
+ *
297
+ * > 👉 **Note**: intentionally creates parse errors in markup (how parse
298
+ * > errors are handled is well defined, so this works but isn’t pretty).
299
+ */
300
+ tightAttributes?: boolean | null | undefined;
301
+ /**
302
+ * Join known comma-separated attribute values with just a comma (`,`),
303
+ * instead of padding them on the right as well (`,␠`, where `␠` represents a
304
+ * space) (default: `false`).
305
+ */
306
+ tightCommaSeparatedLists?: boolean | null | undefined;
307
+ /**
308
+ * Drop unneeded spaces in doctypes: `<!doctypehtml>` instead of
309
+ * `<!doctype html>` to save bytes (default: `false`).
310
+ *
311
+ * > 👉 **Note**: intentionally creates parse errors in markup (how parse
312
+ * > errors are handled is well defined, so this works but isn’t pretty).
313
+ */
314
+ tightDoctype?: boolean | null | undefined;
315
+ /**
316
+ * Do not use an extra space when closing self-closing elements: `<img/>`
317
+ * instead of `<img />` (default: `false`).
318
+ *
319
+ * > 👉 **Note**: only used if `closeSelfClosing: true` or
320
+ * > `closeEmptyElements: true`.
321
+ */
322
+ tightSelfClosing?: boolean | null | undefined;
323
+ /**
324
+ * Use a `<!DOCTYPE…` instead of `<!doctype…` (default: `false`).
325
+ *
326
+ * Useless except for XHTML.
327
+ */
328
+ upperDoctype?: boolean | null | undefined;
329
+ /**
330
+ * Tag names of elements to serialize without closing tag (default: `html-void-elements`).
331
+ *
332
+ * Not used in the SVG space.
333
+ *
334
+ * > 👉 **Note**: It’s highly unlikely that you want to pass this, because
335
+ * > hast is not for XML, and HTML will not add more void elements.
336
+ */
337
+ voids?: ReadonlyArray<string> | null | undefined;
338
+ };
339
+ /**
340
+ * HTML quotes for attribute values.
341
+ */
342
+ type Quote = '"' | "'";
343
+ /**
344
+ * Namespace.
345
+ */
346
+ type Space = 'html' | 'svg';
347
+
348
+ /**
349
+ * Get highlighted code in HTML.
350
+ */
351
+ declare function codeToHtml(internal: ShikiInternal, code: string, options: CodeToHastOptions): string;
352
+
353
+ /**
354
+ * Get tokens with multiple themes
355
+ */
356
+ declare function codeToTokensWithThemes(internal: ShikiInternal, code: string, options: CodeToTokensWithThemesOptions): ThemedTokenWithVariants[][];
357
+
358
+ /**
359
+ * Normalize a textmate theme to shiki theme
360
+ */
361
+ declare function normalizeTheme(rawTheme: ThemeRegistrationAny): ThemeRegistrationResolved;
362
+
363
+ export { BundledHighlighterOptions, CodeToHastOptions, CodeToThemedTokensOptions, CodeToTokensWithThemesOptions, type GetHighlighterFactory, IGrammar as Grammar, type HighlighterCore, HighlighterCoreOptions, HighlighterGeneric, IGrammar, LanguageInput, MaybeArray, RequireKeys, ShikiInternal, ShikiTransformerContextCommon, type ShorthandsBundle, SpecialTheme, ThemeInput, ThemeRegistrationAny, ThemeRegistrationResolved, ThemedToken, ThemedTokenWithVariants, TokenizeWithThemeOptions, addClassToHast, applyColorReplacements, codeToHast, codeToHtml, codeToThemedTokens, codeToTokensWithThemes, createSingletonShorthands, createdBundledHighlighter, getHighlighterCore, getShikiInternal, toHtml as hastToHtml, isNoneTheme, isPlainLang, isPlaintext, isSpecialLang, isSpecialTheme, normalizeTheme, setDefaultWasmLoader, splitLines, splitToken, toArray, tokenizeAnsiWithTheme, tokenizeWithTheme };