@shikijs/core 3.17.1 → 3.18.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.
Files changed (2) hide show
  1. package/dist/index.mjs +26 -15
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -889,15 +889,15 @@ function dimColor(color) {
889
889
 
890
890
  function codeToTokensBase(internal, code, options = {}) {
891
891
  const {
892
- lang = "text",
893
892
  theme: themeName = internal.getLoadedThemes()[0]
894
893
  } = options;
894
+ const lang = internal.resolveLangAlias(options.lang || "text");
895
895
  if (isPlainLang(lang) || isNoneTheme(themeName))
896
896
  return splitLines(code).map((line) => [{ content: line[0], offset: line[1] }]);
897
897
  const { theme, colorMap } = internal.setTheme(themeName);
898
898
  if (lang === "ansi")
899
899
  return tokenizeAnsiWithTheme(theme, code, options);
900
- const _grammar = internal.getLanguage(lang);
900
+ const _grammar = internal.getLanguage(options.lang || "text");
901
901
  if (options.grammarState) {
902
902
  if (options.grammarState.lang !== _grammar.name) {
903
903
  throw new ShikiError$1(`Grammar state language "${options.grammarState.lang}" does not match highlight language "${_grammar.name}"`);
@@ -1474,12 +1474,12 @@ function mergeWhitespaceTokens(tokens) {
1474
1474
  return tokens.map((line) => {
1475
1475
  const newLine = [];
1476
1476
  let carryOnContent = "";
1477
- let firstOffset = 0;
1477
+ let firstOffset;
1478
1478
  line.forEach((token, idx) => {
1479
1479
  const isDecorated = token.fontStyle && (token.fontStyle & FontStyle.Underline || token.fontStyle & FontStyle.Strikethrough);
1480
1480
  const couldMerge = !isDecorated;
1481
1481
  if (couldMerge && token.content.match(/^\s+$/) && line[idx + 1]) {
1482
- if (!firstOffset)
1482
+ if (firstOffset === void 0)
1483
1483
  firstOffset = token.offset;
1484
1484
  carryOnContent += token.content;
1485
1485
  } else {
@@ -1499,7 +1499,7 @@ function mergeWhitespaceTokens(tokens) {
1499
1499
  token
1500
1500
  );
1501
1501
  }
1502
- firstOffset = 0;
1502
+ firstOffset = void 0;
1503
1503
  carryOnContent = "";
1504
1504
  } else {
1505
1505
  newLine.push(token);
@@ -1711,6 +1711,21 @@ class ShikiError extends Error {
1711
1711
  }
1712
1712
  }
1713
1713
 
1714
+ function resolveLangAlias(name, alias) {
1715
+ if (!alias)
1716
+ return name;
1717
+ if (alias[name]) {
1718
+ const resolved = /* @__PURE__ */ new Set([name]);
1719
+ while (alias[name]) {
1720
+ name = alias[name];
1721
+ if (resolved.has(name))
1722
+ throw new ShikiError(`Circular alias \`${Array.from(resolved).join(" -> ")} -> ${name}\``);
1723
+ resolved.add(name);
1724
+ }
1725
+ }
1726
+ return name;
1727
+ }
1728
+
1714
1729
  class Registry extends Registry$1 {
1715
1730
  constructor(_resolver, _themes, _langs, _alias = {}) {
1716
1731
  super(_resolver);
@@ -1761,15 +1776,7 @@ class Registry extends Registry$1 {
1761
1776
  this._syncRegistry.setTheme(textmateTheme);
1762
1777
  }
1763
1778
  getGrammar(name) {
1764
- if (this._alias[name]) {
1765
- const resolved = /* @__PURE__ */ new Set([name]);
1766
- while (this._alias[name]) {
1767
- name = this._alias[name];
1768
- if (resolved.has(name))
1769
- throw new ShikiError(`Circular alias \`${Array.from(resolved).join(" -> ")} -> ${name}\``);
1770
- resolved.add(name);
1771
- }
1772
- }
1779
+ name = resolveLangAlias(name, this._alias);
1773
1780
  return this._resolvedGrammars.get(name);
1774
1781
  }
1775
1782
  loadLanguage(lang) {
@@ -1905,6 +1912,9 @@ function createShikiInternalSync(options) {
1905
1912
  const resolver = new Resolver(options.engine, langs);
1906
1913
  const _registry = new Registry(resolver, themes, langs, options.langAlias);
1907
1914
  let _lastTheme;
1915
+ function resolveLangAlias$1(name) {
1916
+ return resolveLangAlias(name, options.langAlias);
1917
+ }
1908
1918
  function getLanguage(name) {
1909
1919
  ensureNotDisposed();
1910
1920
  const _lang = _registry.getGrammar(typeof name === "string" ? name : name.name);
@@ -1976,6 +1986,7 @@ function createShikiInternalSync(options) {
1976
1986
  getLanguage,
1977
1987
  getLoadedThemes,
1978
1988
  getLoadedLanguages,
1989
+ resolveLangAlias: resolveLangAlias$1,
1979
1990
  loadLanguage,
1980
1991
  loadLanguageSync,
1981
1992
  loadTheme,
@@ -2066,9 +2077,9 @@ function createBundledHighlighter(options) {
2066
2077
  async function createHighlighter(options2) {
2067
2078
  function resolveLang(lang) {
2068
2079
  if (typeof lang === "string") {
2080
+ lang = options2.langAlias?.[lang] || lang;
2069
2081
  if (isSpecialLang(lang))
2070
2082
  return [];
2071
- lang = options2.langAlias?.[lang] || lang;
2072
2083
  const bundle = bundledLanguages[lang];
2073
2084
  if (!bundle)
2074
2085
  throw new ShikiError$1(`Language \`${lang}\` is not included in this bundle. You may want to load it from external source.`);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shikijs/core",
3
3
  "type": "module",
4
- "version": "3.17.1",
4
+ "version": "3.18.0",
5
5
  "description": "Core of Shiki",
6
6
  "author": "Pine Wu <octref@gmail.com>; Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -39,7 +39,7 @@
39
39
  "@shikijs/vscode-textmate": "^10.0.2",
40
40
  "@types/hast": "^3.0.4",
41
41
  "hast-util-to-html": "^9.0.5",
42
- "@shikijs/types": "3.17.1"
42
+ "@shikijs/types": "3.18.0"
43
43
  },
44
44
  "scripts": {
45
45
  "build": "unbuild",