@shikijs/core 3.2.1 → 3.3.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
@@ -272,4 +272,5 @@ declare function enableDeprecationWarnings(emitDeprecation?: DeprecationTarget |
272
272
  */
273
273
  declare function warnDeprecated(message: string, version?: DeprecationTarget): void;
274
274
 
275
- export { type CreateSingletonShorthandsOptions, type CssVariablesThemeOptions, type ShorthandsBundle, 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 };
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 };
276
+ export type { CreateSingletonShorthandsOptions, CssVariablesThemeOptions, ShorthandsBundle };
package/dist/index.mjs CHANGED
@@ -187,8 +187,13 @@ function getTokenStyleObject(token) {
187
187
  styles["font-style"] = "italic";
188
188
  if (token.fontStyle & FontStyle.Bold)
189
189
  styles["font-weight"] = "bold";
190
+ const decorations = [];
190
191
  if (token.fontStyle & FontStyle.Underline)
191
- styles["text-decoration"] = "underline";
192
+ decorations.push("underline");
193
+ if (token.fontStyle & FontStyle.Strikethrough)
194
+ decorations.push("line-through");
195
+ if (decorations.length)
196
+ styles["text-decoration"] = decorations.join(" ");
192
197
  }
193
198
  return styles;
194
199
  }
@@ -760,6 +765,8 @@ function tokenizeAnsiWithTheme(theme, fileContents, options) {
760
765
  fontStyle |= FontStyle.Italic;
761
766
  if (token.decorations.has("underline"))
762
767
  fontStyle |= FontStyle.Underline;
768
+ if (token.decorations.has("strikethrough"))
769
+ fontStyle |= FontStyle.Strikethrough;
763
770
  return {
764
771
  content: token.value,
765
772
  offset: line[1],
@@ -1160,12 +1167,16 @@ function codeToHast(internal, code, options, transformerContext = {
1160
1167
  grammarState
1161
1168
  } = codeToTokens(internal, input, options);
1162
1169
  const {
1163
- mergeWhitespaces = true
1170
+ mergeWhitespaces = true,
1171
+ mergeSameStyleTokens = false
1164
1172
  } = options;
1165
1173
  if (mergeWhitespaces === true)
1166
1174
  tokens = mergeWhitespaceTokens(tokens);
1167
1175
  else if (mergeWhitespaces === "never")
1168
1176
  tokens = splitWhitespaceTokens(tokens);
1177
+ if (mergeSameStyleTokens) {
1178
+ tokens = mergeAdjacentStyledTokens(tokens);
1179
+ }
1169
1180
  const contextSource = {
1170
1181
  ...transformerContext,
1171
1182
  get source() {
@@ -1310,8 +1321,8 @@ function mergeWhitespaceTokens(tokens) {
1310
1321
  let carryOnContent = "";
1311
1322
  let firstOffset = 0;
1312
1323
  line.forEach((token, idx) => {
1313
- const isUnderline = token.fontStyle && token.fontStyle & FontStyle.Underline;
1314
- const couldMerge = !isUnderline;
1324
+ const isDecorated = token.fontStyle && (token.fontStyle & FontStyle.Underline || token.fontStyle & FontStyle.Strikethrough);
1325
+ const couldMerge = !isDecorated;
1315
1326
  if (couldMerge && token.content.match(/^\s+$/) && line[idx + 1]) {
1316
1327
  if (!firstOffset)
1317
1328
  firstOffset = token.offset;
@@ -1375,6 +1386,28 @@ function splitWhitespaceTokens(tokens) {
1375
1386
  });
1376
1387
  });
1377
1388
  }
1389
+ function mergeAdjacentStyledTokens(tokens) {
1390
+ return tokens.map((line) => {
1391
+ const newLine = [];
1392
+ for (const token of line) {
1393
+ if (newLine.length === 0) {
1394
+ newLine.push({ ...token });
1395
+ continue;
1396
+ }
1397
+ const prevToken = newLine[newLine.length - 1];
1398
+ const prevStyle = prevToken.htmlStyle || stringifyTokenStyle(getTokenStyleObject(prevToken));
1399
+ const currentStyle = token.htmlStyle || stringifyTokenStyle(getTokenStyleObject(token));
1400
+ const isPrevDecorated = prevToken.fontStyle && (prevToken.fontStyle & FontStyle.Underline || prevToken.fontStyle & FontStyle.Strikethrough);
1401
+ const isDecorated = token.fontStyle && (token.fontStyle & FontStyle.Underline || token.fontStyle & FontStyle.Strikethrough);
1402
+ if (!isPrevDecorated && !isDecorated && prevStyle === currentStyle) {
1403
+ prevToken.content += token.content;
1404
+ } else {
1405
+ newLine.push({ ...token });
1406
+ }
1407
+ }
1408
+ return newLine;
1409
+ });
1410
+ }
1378
1411
 
1379
1412
  const hastToHtml = toHtml;
1380
1413
  function codeToHtml(internal, code, options) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shikijs/core",
3
3
  "type": "module",
4
- "version": "3.2.1",
4
+ "version": "3.3.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.2.1"
42
+ "@shikijs/types": "3.3.0"
43
43
  },
44
44
  "scripts": {
45
45
  "build": "unbuild",