mini-shiki 4.0.1 → 4.1.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/shiki.js +18 -11
- package/package.json +5 -5
package/dist/shiki.js
CHANGED
|
@@ -79,9 +79,10 @@ function isSpecialTheme(theme) {
|
|
|
79
79
|
* // => [['hello\n', 0], ['world', 6]]
|
|
80
80
|
* ```
|
|
81
81
|
*/
|
|
82
|
+
const RE_NEWLINE = /(\r?\n)/g;
|
|
82
83
|
function splitLines(code, preserveEnding = false) {
|
|
83
84
|
if (code.length === 0) return [["", 0]];
|
|
84
|
-
const parts = code.split(
|
|
85
|
+
const parts = code.split(RE_NEWLINE);
|
|
85
86
|
let index = 0;
|
|
86
87
|
const lines = [];
|
|
87
88
|
for (let i = 0; i < parts.length; i += 2) {
|
|
@@ -195,7 +196,7 @@ function normalizeTheme(rawTheme) {
|
|
|
195
196
|
* Resolve
|
|
196
197
|
*/
|
|
197
198
|
async function resolveLangs(langs) {
|
|
198
|
-
return
|
|
199
|
+
return [...new Set((await Promise.all(langs.filter((l) => !isSpecialLang(l)).map(async (lang) => await normalizeGetter(lang).then((r) => Array.isArray(r) ? r : [r])))).flat())];
|
|
199
200
|
}
|
|
200
201
|
async function resolveThemes(themes) {
|
|
201
202
|
return (await Promise.all(themes.map(async (theme) => isSpecialTheme(theme) ? null : normalizeTheme(await normalizeGetter(theme))))).filter((i) => !!i);
|
|
@@ -206,13 +207,17 @@ function resolveLangAlias(name, alias) {
|
|
|
206
207
|
const resolved = new Set([name]);
|
|
207
208
|
while (alias[name]) {
|
|
208
209
|
name = alias[name];
|
|
209
|
-
if (resolved.has(name)) throw new ShikiError(`Circular alias \`${
|
|
210
|
+
if (resolved.has(name)) throw new ShikiError(`Circular alias \`${[...resolved].join(" -> ")} -> ${name}\``);
|
|
210
211
|
resolved.add(name);
|
|
211
212
|
}
|
|
212
213
|
}
|
|
213
214
|
return name;
|
|
214
215
|
}
|
|
215
216
|
var Registry$1 = class extends Registry {
|
|
217
|
+
_resolver;
|
|
218
|
+
_themes;
|
|
219
|
+
_langs;
|
|
220
|
+
_alias;
|
|
216
221
|
_resolvedThemes = /* @__PURE__ */ new Map();
|
|
217
222
|
_resolvedGrammars = /* @__PURE__ */ new Map();
|
|
218
223
|
_langMap = /* @__PURE__ */ new Map();
|
|
@@ -291,7 +296,7 @@ var Registry$1 = class extends Registry {
|
|
|
291
296
|
}
|
|
292
297
|
loadLanguages(langs) {
|
|
293
298
|
for (const lang of langs) this.resolveEmbeddedLanguages(lang);
|
|
294
|
-
const langsGraphArray =
|
|
299
|
+
const langsGraphArray = [...this._langGraph.entries()];
|
|
295
300
|
const missingLangs = langsGraphArray.filter(([_, lang]) => !lang);
|
|
296
301
|
if (missingLangs.length) {
|
|
297
302
|
const dependents = langsGraphArray.filter(([_, lang]) => {
|
|
@@ -553,6 +558,8 @@ function getGrammarStack(state, theme) {
|
|
|
553
558
|
if (!(state instanceof GrammarState)) throw new ShikiError("Invalid grammar state");
|
|
554
559
|
return state.getInternalStack(theme);
|
|
555
560
|
}
|
|
561
|
+
const RE_COMMA = /,/;
|
|
562
|
+
const RE_SPACE = / /;
|
|
556
563
|
/**
|
|
557
564
|
* Code to tokens, with a simple theme.
|
|
558
565
|
*/
|
|
@@ -633,7 +640,7 @@ function _tokenizeWithTheme(code, grammar, theme, colorMap, options) {
|
|
|
633
640
|
let selectors;
|
|
634
641
|
switch (typeof setting.scope) {
|
|
635
642
|
case "string":
|
|
636
|
-
selectors = setting.scope.split(
|
|
643
|
+
selectors = setting.scope.split(RE_COMMA).map((scope) => scope.trim());
|
|
637
644
|
break;
|
|
638
645
|
case "object":
|
|
639
646
|
selectors = setting.scope;
|
|
@@ -642,7 +649,7 @@ function _tokenizeWithTheme(code, grammar, theme, colorMap, options) {
|
|
|
642
649
|
}
|
|
643
650
|
themeSettingsSelectors.push({
|
|
644
651
|
settings: setting,
|
|
645
|
-
selectors: selectors.map((selector) => selector.split(
|
|
652
|
+
selectors: selectors.map((selector) => selector.split(RE_SPACE))
|
|
646
653
|
});
|
|
647
654
|
}
|
|
648
655
|
token.explanation = [];
|
|
@@ -687,7 +694,7 @@ function matchesOne(selector, scope) {
|
|
|
687
694
|
return selector === scope || scope.substring(0, selector.length) === selector && scope[selector.length] === ".";
|
|
688
695
|
}
|
|
689
696
|
function matches(selectors, scope, parentScopes) {
|
|
690
|
-
if (!matchesOne(selectors
|
|
697
|
+
if (!matchesOne(selectors.at(-1), scope)) return false;
|
|
691
698
|
let selectorParentIndex = selectors.length - 2;
|
|
692
699
|
let parentIndex = parentScopes.length - 1;
|
|
693
700
|
while (selectorParentIndex >= 0 && parentIndex >= 0) {
|
|
@@ -708,13 +715,13 @@ function explainThemeScope(themeSettingsSelectors, scope, parentScopes) {
|
|
|
708
715
|
/**
|
|
709
716
|
* Get tokens with multiple themes
|
|
710
717
|
*/
|
|
711
|
-
function codeToTokensWithThemes(primitive, code, options) {
|
|
718
|
+
function codeToTokensWithThemes(primitive, code, options, codeToTokensBaseFn = codeToTokensBase) {
|
|
712
719
|
const themes = Object.entries(options.themes).filter((i) => i[1]).map((i) => ({
|
|
713
720
|
color: i[0],
|
|
714
721
|
theme: i[1]
|
|
715
722
|
}));
|
|
716
723
|
const themedTokens = themes.map((t) => {
|
|
717
|
-
const tokens$1 =
|
|
724
|
+
const tokens$1 = codeToTokensBaseFn(primitive, code, {
|
|
718
725
|
...options,
|
|
719
726
|
theme: t.theme
|
|
720
727
|
});
|
|
@@ -790,7 +797,7 @@ function alignThemesTokenization(...themes) {
|
|
|
790
797
|
}
|
|
791
798
|
|
|
792
799
|
//#endregion
|
|
793
|
-
//#region node_modules/shiki/dist/langs-bundle-full-
|
|
800
|
+
//#region node_modules/shiki/dist/langs-bundle-full-YTHnHqaM.mjs
|
|
794
801
|
const bundledLanguagesInfo = [
|
|
795
802
|
{
|
|
796
803
|
"id": "abap",
|
|
@@ -1514,7 +1521,7 @@ const bundledLanguagesInfo = [
|
|
|
1514
1521
|
},
|
|
1515
1522
|
{
|
|
1516
1523
|
"id": "nextflow-groovy",
|
|
1517
|
-
"name": "
|
|
1524
|
+
"name": "Nextflow Groovy",
|
|
1518
1525
|
"import": () => import("@shikijs/langs/nextflow-groovy")
|
|
1519
1526
|
},
|
|
1520
1527
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mini-shiki",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": "git+https://github.com/un-ts/mini-shiki.git",
|
|
6
6
|
"homepage": "https://github.com/un-ts/mini-shiki#readme",
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
"static"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@shikijs/engine-oniguruma": "^4.0
|
|
25
|
-
"@shikijs/langs": "^4.0
|
|
26
|
-
"@shikijs/themes": "^4.0
|
|
27
|
-
"@shikijs/types": "^4.0
|
|
24
|
+
"@shikijs/engine-oniguruma": "^4.1.0",
|
|
25
|
+
"@shikijs/langs": "^4.1.0",
|
|
26
|
+
"@shikijs/themes": "^4.1.0",
|
|
27
|
+
"@shikijs/types": "^4.1.0",
|
|
28
28
|
"@shikijs/vscode-textmate": "^10.0.2"
|
|
29
29
|
}
|
|
30
30
|
}
|