@shikijs/core 3.2.2 → 3.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.mjs +27 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1167,12 +1167,16 @@ function codeToHast(internal, code, options, transformerContext = {
|
|
|
1167
1167
|
grammarState
|
|
1168
1168
|
} = codeToTokens(internal, input, options);
|
|
1169
1169
|
const {
|
|
1170
|
-
mergeWhitespaces = true
|
|
1170
|
+
mergeWhitespaces = true,
|
|
1171
|
+
mergeSameStyleTokens = false
|
|
1171
1172
|
} = options;
|
|
1172
1173
|
if (mergeWhitespaces === true)
|
|
1173
1174
|
tokens = mergeWhitespaceTokens(tokens);
|
|
1174
1175
|
else if (mergeWhitespaces === "never")
|
|
1175
1176
|
tokens = splitWhitespaceTokens(tokens);
|
|
1177
|
+
if (mergeSameStyleTokens) {
|
|
1178
|
+
tokens = mergeAdjacentStyledTokens(tokens);
|
|
1179
|
+
}
|
|
1176
1180
|
const contextSource = {
|
|
1177
1181
|
...transformerContext,
|
|
1178
1182
|
get source() {
|
|
@@ -1382,6 +1386,28 @@ function splitWhitespaceTokens(tokens) {
|
|
|
1382
1386
|
});
|
|
1383
1387
|
});
|
|
1384
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
|
+
}
|
|
1385
1411
|
|
|
1386
1412
|
const hastToHtml = toHtml;
|
|
1387
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.
|
|
4
|
+
"version": "3.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",
|
|
@@ -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.
|
|
42
|
+
"@shikijs/types": "3.4.0"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"build": "unbuild",
|