@shikijs/core 2.3.2 → 2.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.
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { CreatedBundledHighlighterOptions, CreateHighlighterFactory, LanguageInput, ThemeInput, HighlighterCoreOptions, CodeToHastOptions, CodeToTokensOptions, TokensResult, RequireKeys, CodeToTokensBaseOptions, ThemedToken, CodeToTokensWithThemesOptions, ThemedTokenWithVariants, BundledHighlighterOptions, HighlighterGeneric, GrammarState, HighlighterCore, ShikiInternal, RegexEngine, LoadWasmOptions, ShikiTransformerContextCommon, CodeToHastRenderOptions, ShikiTransformerContextSource, ThemeRegistrationResolved, TokenizeWithThemeOptions, Grammar, ThemeRegistrationAny, ThemeRegistration, ShikiTransformer, MaybeArray, PlainTextLanguage, SpecialLanguage, SpecialTheme, MaybeGetter, TokenStyles, Position } from '@shikijs/types';
1
+ import { CreatedBundledHighlighterOptions, CreateHighlighterFactory, LanguageInput, ThemeInput, HighlighterCoreOptions, CodeToHastOptions, CodeToTokensOptions, TokensResult, RequireKeys, CodeToTokensBaseOptions, ThemedToken, CodeToTokensWithThemesOptions, ThemedTokenWithVariants, BundledHighlighterOptions, HighlighterGeneric, GrammarState, Awaitable, HighlighterCore, ShikiInternal, RegexEngine, LoadWasmOptions, ShikiTransformerContextCommon, CodeToHastRenderOptions, ShikiTransformerContextSource, ThemeRegistrationResolved, TokenizeWithThemeOptions, Grammar, ThemeRegistrationAny, ThemeRegistration, ShikiTransformer, MaybeArray, PlainTextLanguage, SpecialLanguage, SpecialTheme, MaybeGetter, TokenStyles, Position } from '@shikijs/types';
2
2
  export * from '@shikijs/types';
3
3
  import { Root, Element } from 'hast';
4
4
  import { JavaScriptRegexEngineOptions } from '@shikijs/engine-javascript';
@@ -79,7 +79,13 @@ interface ShorthandsBundle<L extends string, T extends string> {
79
79
  getLastGrammarState: ((element: ThemedToken[][] | Root) => GrammarState) | ((code: string, options: CodeToTokensBaseOptions<L, T>) => Promise<GrammarState>);
80
80
  }
81
81
  declare function makeSingletonHighlighter<L extends string, T extends string>(createHighlighter: CreateHighlighterFactory<L, T>): (options?: Partial<BundledHighlighterOptions<L, T>>) => Promise<HighlighterGeneric<L, T>>;
82
- declare function createSingletonShorthands<L extends string, T extends string>(createHighlighter: CreateHighlighterFactory<L, T>): ShorthandsBundle<L, T>;
82
+ interface CreateSingletonShorthandsOptions<L extends string, T extends string> {
83
+ /**
84
+ * A custom function to guess embedded languages to be loaded.
85
+ */
86
+ guessEmbeddedLanguages?: (code: string, lang: string | undefined, highlighter: HighlighterGeneric<L, T>) => Awaitable<string[] | undefined>;
87
+ }
88
+ declare function createSingletonShorthands<L extends string, T extends string>(createHighlighter: CreateHighlighterFactory<L, T>, config?: CreateSingletonShorthandsOptions<L, T>): ShorthandsBundle<L, T>;
83
89
 
84
90
  /**
85
91
  * Create a Shiki core highlighter instance, with no languages or themes bundled.
@@ -292,4 +298,4 @@ declare function enableDeprecationWarnings(emitDeprecation?: DeprecationTarget |
292
298
  */
293
299
  declare function warnDeprecated(message: string, version?: DeprecationTarget): void;
294
300
 
295
- export { type CssVariablesThemeOptions, type ShorthandsBundle, addClassToHast, applyColorReplacements, codeToHast, codeToHtml, codeToTokens, codeToTokensBase, codeToTokensWithThemes, createCssVariablesTheme, createHighlighterCore, createHighlighterCoreSync, createJavaScriptRegexEngine, createOnigurumaEngine, createPositionConverter, createShikiInternal, createShikiInternalSync, createSingletonShorthands, createWasmOnigEngine, createdBundledHighlighter, defaultJavaScriptRegexConstructor, enableDeprecationWarnings, getHighlighterCore, getShikiInternal, getSingletonHighlighterCore, getTokenStyleObject, isNoneTheme, isPlainLang, isSpecialLang, isSpecialTheme, loadWasm, makeSingletonHighlighter, makeSingletonHighlighterCore, normalizeGetter, normalizeTheme, resolveColorReplacements, splitLines, splitToken, splitTokens, stringifyTokenStyle, toArray, tokenizeAnsiWithTheme, tokenizeWithTheme, tokensToHast, transformerDecorations, warnDeprecated };
301
+ export { type CreateSingletonShorthandsOptions, type CssVariablesThemeOptions, type ShorthandsBundle, addClassToHast, applyColorReplacements, codeToHast, codeToHtml, codeToTokens, codeToTokensBase, codeToTokensWithThemes, createCssVariablesTheme, createHighlighterCore, createHighlighterCoreSync, createJavaScriptRegexEngine, createOnigurumaEngine, createPositionConverter, createShikiInternal, createShikiInternalSync, createSingletonShorthands, createWasmOnigEngine, createdBundledHighlighter, defaultJavaScriptRegexConstructor, enableDeprecationWarnings, getHighlighterCore, getShikiInternal, getSingletonHighlighterCore, getTokenStyleObject, isNoneTheme, isPlainLang, isSpecialLang, isSpecialTheme, loadWasm, makeSingletonHighlighter, makeSingletonHighlighterCore, normalizeGetter, normalizeTheme, resolveColorReplacements, splitLines, splitToken, splitTokens, stringifyTokenStyle, toArray, tokenizeAnsiWithTheme, tokenizeWithTheme, tokensToHast, transformerDecorations, warnDeprecated };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CreatedBundledHighlighterOptions, CreateHighlighterFactory, LanguageInput, ThemeInput, HighlighterCoreOptions, CodeToHastOptions, CodeToTokensOptions, TokensResult, RequireKeys, CodeToTokensBaseOptions, ThemedToken, CodeToTokensWithThemesOptions, ThemedTokenWithVariants, BundledHighlighterOptions, HighlighterGeneric, GrammarState, HighlighterCore, ShikiInternal, RegexEngine, LoadWasmOptions, ShikiTransformerContextCommon, CodeToHastRenderOptions, ShikiTransformerContextSource, ThemeRegistrationResolved, TokenizeWithThemeOptions, Grammar, ThemeRegistrationAny, ThemeRegistration, ShikiTransformer, MaybeArray, PlainTextLanguage, SpecialLanguage, SpecialTheme, MaybeGetter, TokenStyles, Position } from '@shikijs/types';
1
+ import { CreatedBundledHighlighterOptions, CreateHighlighterFactory, LanguageInput, ThemeInput, HighlighterCoreOptions, CodeToHastOptions, CodeToTokensOptions, TokensResult, RequireKeys, CodeToTokensBaseOptions, ThemedToken, CodeToTokensWithThemesOptions, ThemedTokenWithVariants, BundledHighlighterOptions, HighlighterGeneric, GrammarState, Awaitable, HighlighterCore, ShikiInternal, RegexEngine, LoadWasmOptions, ShikiTransformerContextCommon, CodeToHastRenderOptions, ShikiTransformerContextSource, ThemeRegistrationResolved, TokenizeWithThemeOptions, Grammar, ThemeRegistrationAny, ThemeRegistration, ShikiTransformer, MaybeArray, PlainTextLanguage, SpecialLanguage, SpecialTheme, MaybeGetter, TokenStyles, Position } from '@shikijs/types';
2
2
  export * from '@shikijs/types';
3
3
  import { Root, Element } from 'hast';
4
4
  import { JavaScriptRegexEngineOptions } from '@shikijs/engine-javascript';
@@ -79,7 +79,13 @@ interface ShorthandsBundle<L extends string, T extends string> {
79
79
  getLastGrammarState: ((element: ThemedToken[][] | Root) => GrammarState) | ((code: string, options: CodeToTokensBaseOptions<L, T>) => Promise<GrammarState>);
80
80
  }
81
81
  declare function makeSingletonHighlighter<L extends string, T extends string>(createHighlighter: CreateHighlighterFactory<L, T>): (options?: Partial<BundledHighlighterOptions<L, T>>) => Promise<HighlighterGeneric<L, T>>;
82
- declare function createSingletonShorthands<L extends string, T extends string>(createHighlighter: CreateHighlighterFactory<L, T>): ShorthandsBundle<L, T>;
82
+ interface CreateSingletonShorthandsOptions<L extends string, T extends string> {
83
+ /**
84
+ * A custom function to guess embedded languages to be loaded.
85
+ */
86
+ guessEmbeddedLanguages?: (code: string, lang: string | undefined, highlighter: HighlighterGeneric<L, T>) => Awaitable<string[] | undefined>;
87
+ }
88
+ declare function createSingletonShorthands<L extends string, T extends string>(createHighlighter: CreateHighlighterFactory<L, T>, config?: CreateSingletonShorthandsOptions<L, T>): ShorthandsBundle<L, T>;
83
89
 
84
90
  /**
85
91
  * Create a Shiki core highlighter instance, with no languages or themes bundled.
@@ -292,4 +298,4 @@ declare function enableDeprecationWarnings(emitDeprecation?: DeprecationTarget |
292
298
  */
293
299
  declare function warnDeprecated(message: string, version?: DeprecationTarget): void;
294
300
 
295
- export { type CssVariablesThemeOptions, type ShorthandsBundle, addClassToHast, applyColorReplacements, codeToHast, codeToHtml, codeToTokens, codeToTokensBase, codeToTokensWithThemes, createCssVariablesTheme, createHighlighterCore, createHighlighterCoreSync, createJavaScriptRegexEngine, createOnigurumaEngine, createPositionConverter, createShikiInternal, createShikiInternalSync, createSingletonShorthands, createWasmOnigEngine, createdBundledHighlighter, defaultJavaScriptRegexConstructor, enableDeprecationWarnings, getHighlighterCore, getShikiInternal, getSingletonHighlighterCore, getTokenStyleObject, isNoneTheme, isPlainLang, isSpecialLang, isSpecialTheme, loadWasm, makeSingletonHighlighter, makeSingletonHighlighterCore, normalizeGetter, normalizeTheme, resolveColorReplacements, splitLines, splitToken, splitTokens, stringifyTokenStyle, toArray, tokenizeAnsiWithTheme, tokenizeWithTheme, tokensToHast, transformerDecorations, warnDeprecated };
301
+ export { type CreateSingletonShorthandsOptions, type CssVariablesThemeOptions, type ShorthandsBundle, addClassToHast, applyColorReplacements, codeToHast, codeToHtml, codeToTokens, codeToTokensBase, codeToTokensWithThemes, createCssVariablesTheme, createHighlighterCore, createHighlighterCoreSync, createJavaScriptRegexEngine, createOnigurumaEngine, createPositionConverter, createShikiInternal, createShikiInternalSync, createSingletonShorthands, createWasmOnigEngine, createdBundledHighlighter, defaultJavaScriptRegexConstructor, enableDeprecationWarnings, getHighlighterCore, getShikiInternal, getSingletonHighlighterCore, getTokenStyleObject, isNoneTheme, isPlainLang, isSpecialLang, isSpecialTheme, loadWasm, makeSingletonHighlighter, makeSingletonHighlighterCore, normalizeGetter, normalizeTheme, resolveColorReplacements, splitLines, splitToken, splitTokens, stringifyTokenStyle, toArray, tokenizeAnsiWithTheme, tokenizeWithTheme, tokensToHast, transformerDecorations, warnDeprecated };
package/dist/index.mjs CHANGED
@@ -284,7 +284,7 @@ function transformerDecorations() {
284
284
  };
285
285
  } else {
286
286
  const line = converter.lines[p.line];
287
- if (line === undefined)
287
+ if (line === void 0)
288
288
  throw new ShikiError(`Invalid decoration position ${JSON.stringify(p)}. Lines length: ${converter.lines.length}`);
289
289
  if (p.character < 0 || p.character > line.length)
290
290
  throw new ShikiError(`Invalid decoration position ${JSON.stringify(p)}. Line ${p.line} length: ${line.length}`);
@@ -466,52 +466,52 @@ var decorations = {
466
466
  3: "italic",
467
467
  4: "underline",
468
468
  7: "reverse",
469
+ 8: "hidden",
469
470
  9: "strikethrough"
470
471
  };
471
472
 
472
473
  // src/parser.ts
473
474
  function findSequence(value, position) {
474
- const nextEscape = value.indexOf("\x1B[", position);
475
+ const nextEscape = value.indexOf("\x1B", position);
475
476
  if (nextEscape !== -1) {
476
- const nextClose = value.indexOf("m", nextEscape);
477
- return {
478
- sequence: value.substring(nextEscape + 2, nextClose).split(";"),
479
- startPosition: nextEscape,
480
- position: nextClose + 1
481
- };
477
+ if (value[nextEscape + 1] === "[") {
478
+ const nextClose = value.indexOf("m", nextEscape);
479
+ if (nextClose !== -1) {
480
+ return {
481
+ sequence: value.substring(nextEscape + 2, nextClose).split(";"),
482
+ startPosition: nextEscape,
483
+ position: nextClose + 1
484
+ };
485
+ }
486
+ }
482
487
  }
483
488
  return {
484
489
  position: value.length
485
490
  };
486
491
  }
487
- function parseColor(sequence, index) {
488
- let offset = 1;
489
- const colorMode = sequence[index + offset++];
490
- let color;
492
+ function parseColor(sequence) {
493
+ const colorMode = sequence.shift();
491
494
  if (colorMode === "2") {
492
- const rgb = [
493
- sequence[index + offset++],
494
- sequence[index + offset++],
495
- sequence[index + offset]
496
- ].map((x) => Number.parseInt(x));
497
- if (rgb.length === 3 && !rgb.some((x) => Number.isNaN(x))) {
498
- color = {
499
- type: "rgb",
500
- rgb
501
- };
502
- }
495
+ const rgb = sequence.splice(0, 3).map((x) => Number.parseInt(x));
496
+ if (rgb.length !== 3 || rgb.some((x) => Number.isNaN(x)))
497
+ return;
498
+ return {
499
+ type: "rgb",
500
+ rgb
501
+ };
503
502
  } else if (colorMode === "5") {
504
- const colorIndex = Number.parseInt(sequence[index + offset]);
505
- if (!Number.isNaN(colorIndex)) {
506
- color = { type: "table", index: Number(colorIndex) };
503
+ const index = sequence.shift();
504
+ if (index) {
505
+ return { type: "table", index: Number(index) };
507
506
  }
508
507
  }
509
- return [offset, color];
510
508
  }
511
509
  function parseSequence(sequence) {
512
510
  const commands = [];
513
- for (let i = 0; i < sequence.length; i++) {
514
- const code = sequence[i];
511
+ while (sequence.length > 0) {
512
+ const code = sequence.shift();
513
+ if (!code)
514
+ continue;
515
515
  const codeInt = Number.parseInt(code);
516
516
  if (Number.isNaN(codeInt))
517
517
  continue;
@@ -532,6 +532,12 @@ function parseSequence(sequence) {
532
532
  type: "resetDecoration",
533
533
  value: decoration
534
534
  });
535
+ if (decoration === "dim") {
536
+ commands.push({
537
+ type: "resetDecoration",
538
+ value: "bold"
539
+ });
540
+ }
535
541
  }
536
542
  } else if (codeInt <= 37) {
537
543
  commands.push({
@@ -539,14 +545,13 @@ function parseSequence(sequence) {
539
545
  value: { type: "named", name: namedColors[codeInt - 30] }
540
546
  });
541
547
  } else if (codeInt === 38) {
542
- const [offset, color] = parseColor(sequence, i);
548
+ const color = parseColor(sequence);
543
549
  if (color) {
544
550
  commands.push({
545
551
  type: "setForegroundColor",
546
552
  value: color
547
553
  });
548
554
  }
549
- i += offset;
550
555
  } else if (codeInt === 39) {
551
556
  commands.push({
552
557
  type: "resetForegroundColor"
@@ -557,18 +562,27 @@ function parseSequence(sequence) {
557
562
  value: { type: "named", name: namedColors[codeInt - 40] }
558
563
  });
559
564
  } else if (codeInt === 48) {
560
- const [offset, color] = parseColor(sequence, i);
565
+ const color = parseColor(sequence);
561
566
  if (color) {
562
567
  commands.push({
563
568
  type: "setBackgroundColor",
564
569
  value: color
565
570
  });
566
571
  }
567
- i += offset;
568
572
  } else if (codeInt === 49) {
569
573
  commands.push({
570
574
  type: "resetBackgroundColor"
571
575
  });
576
+ } else if (codeInt === 53) {
577
+ commands.push({
578
+ type: "setDecoration",
579
+ value: "overline"
580
+ });
581
+ } else if (codeInt === 55) {
582
+ commands.push({
583
+ type: "resetDecoration",
584
+ value: "overline"
585
+ });
572
586
  } else if (codeInt >= 90 && codeInt <= 97) {
573
587
  commands.push({
574
588
  type: "setForegroundColor",
@@ -722,7 +736,7 @@ function tokenizeAnsiWithTheme(theme, fileContents, options) {
722
736
  bgColor = token.foreground ? colorPalette.value(token.foreground) : theme.fg;
723
737
  } else {
724
738
  color = token.foreground ? colorPalette.value(token.foreground) : theme.fg;
725
- bgColor = token.background ? colorPalette.value(token.background) : undefined;
739
+ bgColor = token.background ? colorPalette.value(token.background) : void 0;
726
740
  }
727
741
  color = applyColorReplacements(color, colorReplacements);
728
742
  bgColor = applyColorReplacements(bgColor, colorReplacements);
@@ -830,8 +844,8 @@ function _tokenizeWithTheme(code, grammar, theme, colorMap, options) {
830
844
  colorMap,
831
845
  {
832
846
  ...options,
833
- grammarState: undefined,
834
- grammarContextCode: undefined
847
+ grammarState: void 0,
848
+ grammarContextCode: void 0
835
849
  }
836
850
  ).stateStack : INITIAL;
837
851
  let actual = [];
@@ -857,7 +871,7 @@ function _tokenizeWithTheme(code, grammar, theme, colorMap, options) {
857
871
  let tokensWithScopes;
858
872
  let tokensWithScopesIndex;
859
873
  if (options.includeExplanation) {
860
- resultWithScopes = grammar.tokenizeLine(line, stateStack);
874
+ resultWithScopes = grammar.tokenizeLine(line, stateStack, tokenizeTimeLimit);
861
875
  tokensWithScopes = resultWithScopes.tokens;
862
876
  tokensWithScopesIndex = 0;
863
877
  }
@@ -1020,7 +1034,7 @@ function codeToTokensWithThemes(internal, code, options) {
1020
1034
  const mergedGrammarState = themedTokens[0].state ? new GrammarState(
1021
1035
  Object.fromEntries(themedTokens.map((s) => [s.theme, s.state?.getInternalStack(s.theme)])),
1022
1036
  themedTokens[0].state.lang
1023
- ) : undefined;
1037
+ ) : void 0;
1024
1038
  if (mergedGrammarState)
1025
1039
  setLastGrammarStateToMap(mergedTokens, mergedGrammarState);
1026
1040
  return mergedTokens;
@@ -1091,7 +1105,7 @@ function codeToTokens(internal, code, options) {
1091
1105
  fg = themes.map((t, idx) => (idx === 0 && defaultColor ? "" : `${cssVariablePrefix + t.color}:`) + (applyColorReplacements(themeRegs[idx].fg, themeColorReplacements[idx]) || "inherit")).join(";");
1092
1106
  bg = themes.map((t, idx) => (idx === 0 && defaultColor ? "" : `${cssVariablePrefix + t.color}-bg:`) + (applyColorReplacements(themeRegs[idx].bg, themeColorReplacements[idx]) || "inherit")).join(";");
1093
1107
  themeName = `shiki-themes ${themeRegs.map((t) => t.name).join(" ")}`;
1094
- rootStyle = defaultColor ? undefined : [fg, bg].join(";");
1108
+ rootStyle = defaultColor ? void 0 : [fg, bg].join(";");
1095
1109
  } else if ("theme" in options) {
1096
1110
  const colorReplacements = resolveColorReplacements(options.theme, options);
1097
1111
  tokens = codeToTokensBase(
@@ -1408,7 +1422,7 @@ function normalizeTheme(rawTheme) {
1408
1422
  theme.settings ||= [];
1409
1423
  let { bg, fg } = theme;
1410
1424
  if (!bg || !fg) {
1411
- const globalSetting = theme.settings ? theme.settings.find((s) => !s.name && !s.scope) : undefined;
1425
+ const globalSetting = theme.settings ? theme.settings.find((s) => !s.name && !s.scope) : void 0;
1412
1426
  if (globalSetting?.settings?.foreground)
1413
1427
  fg = globalSetting.settings.foreground;
1414
1428
  if (globalSetting?.settings?.background)
@@ -1808,6 +1822,8 @@ async function createHighlighterCore(options) {
1808
1822
  codeToTokens: (code, options2) => codeToTokens(internal, code, options2),
1809
1823
  codeToHast: (code, options2) => codeToHast(internal, code, options2),
1810
1824
  codeToHtml: (code, options2) => codeToHtml(internal, code, options2),
1825
+ getBundledLanguages: () => ({}),
1826
+ getBundledThemes: () => ({}),
1811
1827
  ...internal,
1812
1828
  getInternalContext: () => internal
1813
1829
  };
@@ -1821,6 +1837,8 @@ function createHighlighterCoreSync(options) {
1821
1837
  codeToTokens: (code, options2) => codeToTokens(internal, code, options2),
1822
1838
  codeToHast: (code, options2) => codeToHast(internal, code, options2),
1823
1839
  codeToHtml: (code, options2) => codeToHtml(internal, code, options2),
1840
+ getBundledLanguages: () => ({}),
1841
+ getBundledThemes: () => ({}),
1824
1842
  ...internal,
1825
1843
  getInternalContext: () => internal
1826
1844
  };
@@ -1905,6 +1923,12 @@ function createdBundledHighlighter(arg1, arg2, arg3) {
1905
1923
  },
1906
1924
  loadTheme(...themes) {
1907
1925
  return core.loadTheme(...themes.map(resolveTheme));
1926
+ },
1927
+ getBundledLanguages() {
1928
+ return bundledLanguages;
1929
+ },
1930
+ getBundledThemes() {
1931
+ return bundledThemes;
1908
1932
  }
1909
1933
  };
1910
1934
  }
@@ -1931,45 +1955,41 @@ function makeSingletonHighlighter(createHighlighter) {
1931
1955
  }
1932
1956
  return getSingletonHighlighter;
1933
1957
  }
1934
- function createSingletonShorthands(createHighlighter) {
1958
+ function createSingletonShorthands(createHighlighter, config) {
1935
1959
  const getSingletonHighlighter = makeSingletonHighlighter(createHighlighter);
1960
+ async function get(code, options) {
1961
+ const shiki = await getSingletonHighlighter({
1962
+ langs: [options.lang],
1963
+ themes: "theme" in options ? [options.theme] : Object.values(options.themes)
1964
+ });
1965
+ const langs = await config?.guessEmbeddedLanguages?.(code, options.lang, shiki);
1966
+ if (langs) {
1967
+ await shiki.loadLanguage(...langs);
1968
+ }
1969
+ return shiki;
1970
+ }
1936
1971
  return {
1937
1972
  getSingletonHighlighter(options) {
1938
1973
  return getSingletonHighlighter(options);
1939
1974
  },
1940
1975
  async codeToHtml(code, options) {
1941
- const shiki = await getSingletonHighlighter({
1942
- langs: [options.lang],
1943
- themes: "theme" in options ? [options.theme] : Object.values(options.themes)
1944
- });
1976
+ const shiki = await get(code, options);
1945
1977
  return shiki.codeToHtml(code, options);
1946
1978
  },
1947
1979
  async codeToHast(code, options) {
1948
- const shiki = await getSingletonHighlighter({
1949
- langs: [options.lang],
1950
- themes: "theme" in options ? [options.theme] : Object.values(options.themes)
1951
- });
1980
+ const shiki = await get(code, options);
1952
1981
  return shiki.codeToHast(code, options);
1953
1982
  },
1954
1983
  async codeToTokens(code, options) {
1955
- const shiki = await getSingletonHighlighter({
1956
- langs: [options.lang],
1957
- themes: "theme" in options ? [options.theme] : Object.values(options.themes)
1958
- });
1984
+ const shiki = await get(code, options);
1959
1985
  return shiki.codeToTokens(code, options);
1960
1986
  },
1961
1987
  async codeToTokensBase(code, options) {
1962
- const shiki = await getSingletonHighlighter({
1963
- langs: [options.lang],
1964
- themes: [options.theme]
1965
- });
1988
+ const shiki = await get(code, options);
1966
1989
  return shiki.codeToTokensBase(code, options);
1967
1990
  },
1968
1991
  async codeToTokensWithThemes(code, options) {
1969
- const shiki = await getSingletonHighlighter({
1970
- langs: [options.lang],
1971
- themes: Object.values(options.themes).filter(Boolean)
1972
- });
1992
+ const shiki = await get(code, options);
1973
1993
  return shiki.codeToTokensWithThemes(code, options);
1974
1994
  },
1975
1995
  async getLastGrammarState(code, options) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shikijs/core",
3
3
  "type": "module",
4
- "version": "2.3.2",
4
+ "version": "2.4.0",
5
5
  "description": "Core of Shiki",
6
6
  "author": "Pine Wu <octref@gmail.com>; Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -60,12 +60,12 @@
60
60
  "dist"
61
61
  ],
62
62
  "dependencies": {
63
- "@shikijs/vscode-textmate": "^10.0.1",
63
+ "@shikijs/vscode-textmate": "^10.0.2",
64
64
  "@types/hast": "^3.0.4",
65
65
  "hast-util-to-html": "^9.0.4",
66
- "@shikijs/engine-javascript": "2.3.2",
67
- "@shikijs/types": "2.3.2",
68
- "@shikijs/engine-oniguruma": "2.3.2"
66
+ "@shikijs/engine-javascript": "2.4.0",
67
+ "@shikijs/types": "2.4.0",
68
+ "@shikijs/engine-oniguruma": "2.4.0"
69
69
  },
70
70
  "scripts": {
71
71
  "build": "unbuild",