@astrojs/markdown-remark 7.0.0-beta.8 → 7.0.0-beta.9
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.d.ts +1 -1
- package/dist/shiki.js +50 -11
- package/package.json +2 -2
package/dist/shiki.d.ts
CHANGED
|
@@ -40,5 +40,5 @@ export interface ShikiHighlighterHighlightOptions {
|
|
|
40
40
|
*/
|
|
41
41
|
meta?: string;
|
|
42
42
|
}
|
|
43
|
-
export declare function createShikiHighlighter(
|
|
43
|
+
export declare function createShikiHighlighter(options?: CreateShikiHighlighterOptions): Promise<ShikiHighlighter>;
|
|
44
44
|
export type { ThemePresets };
|
package/dist/shiki.js
CHANGED
|
@@ -9,8 +9,48 @@ const cssVariablesTheme = () => _cssVariablesTheme ?? (_cssVariablesTheme = crea
|
|
|
9
9
|
variablePrefix: "--astro-code-"
|
|
10
10
|
}));
|
|
11
11
|
const cachedHighlighters = /* @__PURE__ */ new Map();
|
|
12
|
+
function clearShikiHighlighterCache() {
|
|
13
|
+
cachedHighlighters.clear();
|
|
14
|
+
}
|
|
15
|
+
function createShikiHighlighter(options) {
|
|
16
|
+
const key = getCacheKey(options);
|
|
17
|
+
let highlighterPromise = cachedHighlighters.get(key);
|
|
18
|
+
if (!highlighterPromise) {
|
|
19
|
+
highlighterPromise = createShikiHighlighterInternal(options);
|
|
20
|
+
cachedHighlighters.set(key, highlighterPromise);
|
|
21
|
+
}
|
|
22
|
+
return ensureLanguagesLoaded(highlighterPromise, options?.langs);
|
|
23
|
+
}
|
|
24
|
+
function getCacheKey(options) {
|
|
25
|
+
const keyCache = [];
|
|
26
|
+
const { theme, themes, langAlias } = options ?? {};
|
|
27
|
+
if (theme) {
|
|
28
|
+
keyCache.push(theme);
|
|
29
|
+
}
|
|
30
|
+
if (themes) {
|
|
31
|
+
keyCache.push(Object.entries(themes).sort());
|
|
32
|
+
}
|
|
33
|
+
if (langAlias) {
|
|
34
|
+
keyCache.push(Object.entries(langAlias).sort());
|
|
35
|
+
}
|
|
36
|
+
return keyCache.length > 0 ? JSON.stringify(keyCache) : "";
|
|
37
|
+
}
|
|
38
|
+
async function ensureLanguagesLoaded(promise, langs) {
|
|
39
|
+
const highlighter = await promise;
|
|
40
|
+
if (!langs) {
|
|
41
|
+
return highlighter;
|
|
42
|
+
}
|
|
43
|
+
const loadedLanguages = highlighter.getLoadedLanguages();
|
|
44
|
+
for (const lang of langs) {
|
|
45
|
+
if (typeof lang === "string" && (isSpecialLang(lang) || loadedLanguages.includes(lang))) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
await highlighter.loadLanguage(lang);
|
|
49
|
+
}
|
|
50
|
+
return highlighter;
|
|
51
|
+
}
|
|
12
52
|
let shikiEngine = void 0;
|
|
13
|
-
async function
|
|
53
|
+
async function createShikiHighlighterInternal({
|
|
14
54
|
langs = [],
|
|
15
55
|
theme = "github-dark",
|
|
16
56
|
themes = {},
|
|
@@ -20,20 +60,12 @@ async function createShikiHighlighter({
|
|
|
20
60
|
if (shikiEngine === void 0) {
|
|
21
61
|
shikiEngine = await loadShikiEngine();
|
|
22
62
|
}
|
|
23
|
-
const
|
|
63
|
+
const highlighter = await createHighlighter({
|
|
24
64
|
langs: ["plaintext", ...langs],
|
|
25
65
|
langAlias,
|
|
26
66
|
themes: Object.values(themes).length ? Object.values(themes) : [theme],
|
|
27
67
|
engine: shikiEngine
|
|
28
|
-
};
|
|
29
|
-
const key = JSON.stringify(highlighterOptions, Object.keys(highlighterOptions).sort());
|
|
30
|
-
let highlighter;
|
|
31
|
-
if (cachedHighlighters.has(key)) {
|
|
32
|
-
highlighter = cachedHighlighters.get(key);
|
|
33
|
-
} else {
|
|
34
|
-
highlighter = await createHighlighter(highlighterOptions);
|
|
35
|
-
cachedHighlighters.set(key, highlighter);
|
|
36
|
-
}
|
|
68
|
+
});
|
|
37
69
|
async function highlight(code, lang = "plaintext", options, to) {
|
|
38
70
|
const resolvedLang = langAlias[lang] ?? lang;
|
|
39
71
|
const loadedLanguages = highlighter.getLoadedLanguages();
|
|
@@ -113,6 +145,12 @@ async function createShikiHighlighter({
|
|
|
113
145
|
},
|
|
114
146
|
codeToHtml(code, lang, options = {}) {
|
|
115
147
|
return highlight(code, lang, options, "html");
|
|
148
|
+
},
|
|
149
|
+
loadLanguage(...newLangs) {
|
|
150
|
+
return highlighter.loadLanguage(...newLangs);
|
|
151
|
+
},
|
|
152
|
+
getLoadedLanguages() {
|
|
153
|
+
return highlighter.getLoadedLanguages();
|
|
116
154
|
}
|
|
117
155
|
};
|
|
118
156
|
}
|
|
@@ -120,5 +158,6 @@ function normalizePropAsString(value) {
|
|
|
120
158
|
return Array.isArray(value) ? value.join(" ") : value;
|
|
121
159
|
}
|
|
122
160
|
export {
|
|
161
|
+
clearShikiHighlighterCache,
|
|
123
162
|
createShikiHighlighter
|
|
124
163
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/markdown-remark",
|
|
3
|
-
"version": "7.0.0-beta.
|
|
3
|
+
"version": "7.0.0-beta.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "withastro",
|
|
6
6
|
"license": "MIT",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"remark-parse": "^11.0.0",
|
|
42
42
|
"remark-rehype": "^11.1.2",
|
|
43
43
|
"remark-smartypants": "^3.0.2",
|
|
44
|
-
"shiki": "^
|
|
44
|
+
"shiki": "^4.0.0",
|
|
45
45
|
"smol-toml": "^1.6.0",
|
|
46
46
|
"unified": "^11.0.5",
|
|
47
47
|
"unist-util-remove-position": "^5.0.0",
|