@shikijs/core 3.14.0 → 3.16.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 +75 -11
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -778,17 +778,35 @@ function createColorPalette(namedColorsMap = defaultNamedColorsMap) {
|
|
|
778
778
|
};
|
|
779
779
|
}
|
|
780
780
|
|
|
781
|
+
const defaultAnsiColors = {
|
|
782
|
+
black: "#000000",
|
|
783
|
+
red: "#cd3131",
|
|
784
|
+
green: "#0DBC79",
|
|
785
|
+
yellow: "#E5E510",
|
|
786
|
+
blue: "#2472C8",
|
|
787
|
+
magenta: "#BC3FBC",
|
|
788
|
+
cyan: "#11A8CD",
|
|
789
|
+
white: "#E5E5E5",
|
|
790
|
+
brightBlack: "#666666",
|
|
791
|
+
brightRed: "#F14C4C",
|
|
792
|
+
brightGreen: "#23D18B",
|
|
793
|
+
brightYellow: "#F5F543",
|
|
794
|
+
brightBlue: "#3B8EEA",
|
|
795
|
+
brightMagenta: "#D670D6",
|
|
796
|
+
brightCyan: "#29B8DB",
|
|
797
|
+
brightWhite: "#FFFFFF"
|
|
798
|
+
};
|
|
781
799
|
function tokenizeAnsiWithTheme(theme, fileContents, options) {
|
|
782
800
|
const colorReplacements = resolveColorReplacements(theme, options);
|
|
783
801
|
const lines = splitLines(fileContents);
|
|
784
|
-
const
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
)
|
|
802
|
+
const ansiPalette = Object.fromEntries(
|
|
803
|
+
namedColors.map((name) => {
|
|
804
|
+
const key = `terminal.ansi${name[0].toUpperCase()}${name.substring(1)}`;
|
|
805
|
+
const themeColor = theme.colors?.[key];
|
|
806
|
+
return [name, themeColor || defaultAnsiColors[name]];
|
|
807
|
+
})
|
|
791
808
|
);
|
|
809
|
+
const colorPalette = createColorPalette(ansiPalette);
|
|
792
810
|
const parser = createAnsiSequenceParser();
|
|
793
811
|
return lines.map(
|
|
794
812
|
(line) => parser.parse(line[0]).map((token) => {
|
|
@@ -826,7 +844,7 @@ function tokenizeAnsiWithTheme(theme, fileContents, options) {
|
|
|
826
844
|
);
|
|
827
845
|
}
|
|
828
846
|
function dimColor(color) {
|
|
829
|
-
const hexMatch = color.match(/#([0-9a-f]{3})([0-9a-f]{3})?([0-9a-f]{2})?/);
|
|
847
|
+
const hexMatch = color.match(/#([0-9a-f]{3})([0-9a-f]{3})?([0-9a-f]{2})?/i);
|
|
830
848
|
if (hexMatch) {
|
|
831
849
|
if (hexMatch[3]) {
|
|
832
850
|
const alpha = Math.round(Number.parseInt(hexMatch[3], 16) / 2).toString(16).padStart(2, "0");
|
|
@@ -1368,6 +1386,8 @@ function tokensToHast(tokens, options, transformerContext, grammarState = getLas
|
|
|
1368
1386
|
lineNode = transformer?.line?.call(context, lineNode, idx + 1) || lineNode;
|
|
1369
1387
|
lineNodes.push(lineNode);
|
|
1370
1388
|
lines.push(lineNode);
|
|
1389
|
+
} else if (structure === "inline") {
|
|
1390
|
+
lineNodes.push(lineNode);
|
|
1371
1391
|
}
|
|
1372
1392
|
});
|
|
1373
1393
|
if (structure === "classic") {
|
|
@@ -1377,6 +1397,45 @@ function tokensToHast(tokens, options, transformerContext, grammarState = getLas
|
|
|
1377
1397
|
for (const transformer of transformers)
|
|
1378
1398
|
preNode = transformer?.pre?.call(context, preNode) || preNode;
|
|
1379
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
|
+
}
|
|
1380
1439
|
}
|
|
1381
1440
|
let result = root;
|
|
1382
1441
|
for (const transformer of transformers)
|
|
@@ -2033,10 +2092,15 @@ function makeSingletonHighlighter(createHighlighter) {
|
|
|
2033
2092
|
if (!_shiki) {
|
|
2034
2093
|
_shiki = createHighlighter({
|
|
2035
2094
|
...options,
|
|
2036
|
-
themes:
|
|
2037
|
-
langs:
|
|
2095
|
+
themes: [],
|
|
2096
|
+
langs: []
|
|
2038
2097
|
});
|
|
2039
|
-
|
|
2098
|
+
const s = await _shiki;
|
|
2099
|
+
await Promise.all([
|
|
2100
|
+
s.loadTheme(...options.themes || []),
|
|
2101
|
+
s.loadLanguage(...options.langs || [])
|
|
2102
|
+
]);
|
|
2103
|
+
return s;
|
|
2040
2104
|
} else {
|
|
2041
2105
|
const s = await _shiki;
|
|
2042
2106
|
await Promise.all([
|
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.16.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.16.0"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"build": "unbuild",
|