@shikijs/core 3.15.0 → 3.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 CHANGED
@@ -1,4 +1,4 @@
1
- import { CreatedBundledHighlighterOptions, CreateHighlighterFactory, CodeToHastOptions, CodeToTokensOptions, TokensResult, RequireKeys, CodeToTokensBaseOptions, ThemedToken, CodeToTokensWithThemesOptions, ThemedTokenWithVariants, BundledHighlighterOptions, HighlighterGeneric, GrammarState, Awaitable, HighlighterCoreOptions, HighlighterCore, ShikiInternal, ShikiTransformerContextCommon, CodeToHastRenderOptions, ShikiTransformerContextSource, ThemeRegistrationResolved, TokenizeWithThemeOptions, Grammar, ThemeRegistrationAny, ThemeRegistration, ShikiTransformer, MaybeArray, MaybeGetter, PlainTextLanguage, SpecialLanguage, ThemeInput, SpecialTheme, Position, CodeOptionsMultipleThemes, TokenStyles } from '@shikijs/types';
1
+ import { CreateBundledHighlighterOptions, CreateHighlighterFactory, CodeToHastOptions, CodeToTokensOptions, TokensResult, RequireKeys, CodeToTokensBaseOptions, ThemedToken, CodeToTokensWithThemesOptions, ThemedTokenWithVariants, BundledHighlighterOptions, HighlighterGeneric, GrammarState, Awaitable, HighlighterCoreOptions, HighlighterCore, ShikiInternal, ShikiTransformerContextCommon, CodeToHastRenderOptions, ShikiTransformerContextSource, ThemeRegistrationResolved, TokenizeWithThemeOptions, Grammar, ThemeRegistrationAny, ThemeRegistration, ShikiTransformer, MaybeArray, MaybeGetter, PlainTextLanguage, SpecialLanguage, ThemeInput, SpecialTheme, Position, CodeOptionsMultipleThemes, TokenStyles } from '@shikijs/types';
2
2
  export * from '@shikijs/types';
3
3
  import { Root, Element } from 'hast';
4
4
  import { toHtml } from 'hast-util-to-html';
@@ -8,7 +8,7 @@ import { toHtml } from 'hast-util-to-html';
8
8
  *
9
9
  * @example
10
10
  * ```ts
11
- * const createHighlighter = createdBundledHighlighter({
11
+ * const createHighlighter = createBundledHighlighter({
12
12
  * langs: {
13
13
  * typescript: () => import('@shikijs/langs/typescript'),
14
14
  * // ...
@@ -23,7 +23,7 @@ import { toHtml } from 'hast-util-to-html';
23
23
  *
24
24
  * @param options
25
25
  */
26
- declare function createdBundledHighlighter<BundledLangs extends string, BundledThemes extends string>(options: CreatedBundledHighlighterOptions<BundledLangs, BundledThemes>): CreateHighlighterFactory<BundledLangs, BundledThemes>;
26
+ declare function createBundledHighlighter<BundledLangs extends string, BundledThemes extends string>(options: CreateBundledHighlighterOptions<BundledLangs, BundledThemes>): CreateHighlighterFactory<BundledLangs, BundledThemes>;
27
27
  interface ShorthandsBundle<L extends string, T extends string> {
28
28
  /**
29
29
  * Shorthand for `codeToHtml` with auto-loaded theme and language.
@@ -78,6 +78,10 @@ interface CreateSingletonShorthandsOptions<L extends string, T extends string> {
78
78
  guessEmbeddedLanguages?: (code: string, lang: string | undefined, highlighter: HighlighterGeneric<L, T>) => Awaitable<string[] | undefined>;
79
79
  }
80
80
  declare function createSingletonShorthands<L extends string, T extends string>(createHighlighter: CreateHighlighterFactory<L, T>, config?: CreateSingletonShorthandsOptions<L, T>): ShorthandsBundle<L, T>;
81
+ /**
82
+ * @deprecated Use `createBundledHighlighter` instead.
83
+ */
84
+ declare const createdBundledHighlighter: typeof createBundledHighlighter;
81
85
 
82
86
  /**
83
87
  * Create a Shiki core highlighter instance, with no languages or themes bundled.
@@ -272,5 +276,5 @@ declare function enableDeprecationWarnings(emitDeprecation?: DeprecationTarget |
272
276
  */
273
277
  declare function warnDeprecated(message: string, version?: DeprecationTarget): void;
274
278
 
275
- 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 };
279
+ export { addClassToHast, applyColorReplacements, codeToHast, codeToHtml, codeToTokens, codeToTokensBase, codeToTokensWithThemes, createBundledHighlighter, 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 };
276
280
  export type { CreateSingletonShorthandsOptions, CssVariablesThemeOptions, ShorthandsBundle };
package/dist/index.mjs CHANGED
@@ -1386,6 +1386,8 @@ function tokensToHast(tokens, options, transformerContext, grammarState = getLas
1386
1386
  lineNode = transformer?.line?.call(context, lineNode, idx + 1) || lineNode;
1387
1387
  lineNodes.push(lineNode);
1388
1388
  lines.push(lineNode);
1389
+ } else if (structure === "inline") {
1390
+ lineNodes.push(lineNode);
1389
1391
  }
1390
1392
  });
1391
1393
  if (structure === "classic") {
@@ -1395,6 +1397,45 @@ function tokensToHast(tokens, options, transformerContext, grammarState = getLas
1395
1397
  for (const transformer of transformers)
1396
1398
  preNode = transformer?.pre?.call(context, preNode) || preNode;
1397
1399
  root.children.push(preNode);
1400
+ } else if (structure === "inline") {
1401
+ const syntheticLines = [];
1402
+ let currentLine = {
1403
+ type: "element",
1404
+ tagName: "span",
1405
+ properties: { class: "line" },
1406
+ children: []
1407
+ };
1408
+ for (const child of root.children) {
1409
+ if (child.type === "element" && child.tagName === "br") {
1410
+ syntheticLines.push(currentLine);
1411
+ currentLine = {
1412
+ type: "element",
1413
+ tagName: "span",
1414
+ properties: { class: "line" },
1415
+ children: []
1416
+ };
1417
+ } else if (child.type === "element" || child.type === "text") {
1418
+ currentLine.children.push(child);
1419
+ }
1420
+ }
1421
+ syntheticLines.push(currentLine);
1422
+ const syntheticCode = {
1423
+ type: "element",
1424
+ tagName: "code",
1425
+ properties: {},
1426
+ children: syntheticLines
1427
+ };
1428
+ let transformedCode = syntheticCode;
1429
+ for (const transformer of transformers)
1430
+ transformedCode = transformer?.code?.call(context, transformedCode) || transformedCode;
1431
+ root.children = [];
1432
+ for (let i = 0; i < transformedCode.children.length; i++) {
1433
+ if (i > 0)
1434
+ root.children.push({ type: "element", tagName: "br", properties: {}, children: [] });
1435
+ const line = transformedCode.children[i];
1436
+ if (line.type === "element")
1437
+ root.children.push(...line.children);
1438
+ }
1398
1439
  }
1399
1440
  let result = root;
1400
1441
  for (const transformer of transformers)
@@ -1769,8 +1810,9 @@ class Registry extends Registry$1 {
1769
1810
  resolveEmbeddedLanguages(lang) {
1770
1811
  this._langMap.set(lang.name, lang);
1771
1812
  this._langGraph.set(lang.name, lang);
1772
- if (lang.embeddedLangs) {
1773
- for (const embeddedLang of lang.embeddedLangs)
1813
+ const embedded = lang.embeddedLanguages ?? lang.embeddedLangs;
1814
+ if (embedded) {
1815
+ for (const embeddedLang of embedded)
1774
1816
  this._langGraph.set(embeddedLang, this._langMap.get(embeddedLang));
1775
1817
  }
1776
1818
  }
@@ -1991,7 +2033,7 @@ function makeSingletonHighlighterCore(createHighlighter) {
1991
2033
  }
1992
2034
  const getSingletonHighlighterCore = /* @__PURE__ */ makeSingletonHighlighterCore(createHighlighterCore);
1993
2035
 
1994
- function createdBundledHighlighter(options) {
2036
+ function createBundledHighlighter(options) {
1995
2037
  const bundledLanguages = options.langs;
1996
2038
  const bundledThemes = options.themes;
1997
2039
  const engine = options.engine;
@@ -2117,6 +2159,7 @@ function createSingletonShorthands(createHighlighter, config) {
2117
2159
  }
2118
2160
  };
2119
2161
  }
2162
+ const createdBundledHighlighter = createBundledHighlighter;
2120
2163
 
2121
2164
  function createCssVariablesTheme(options = {}) {
2122
2165
  const {
@@ -2353,4 +2396,4 @@ function createCssVariablesTheme(options = {}) {
2353
2396
  return theme;
2354
2397
  }
2355
2398
 
2356
- 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 };
2399
+ export { addClassToHast, applyColorReplacements, codeToHast, codeToHtml, codeToTokens, codeToTokensBase, codeToTokensWithThemes, createBundledHighlighter, 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 };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shikijs/core",
3
3
  "type": "module",
4
- "version": "3.15.0",
4
+ "version": "3.17.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.15.0"
42
+ "@shikijs/types": "3.17.0"
43
43
  },
44
44
  "scripts": {
45
45
  "build": "unbuild",