astro 1.6.8 → 1.6.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/components/Code.astro +4 -1
- package/components/Shiki.js +48 -6
- package/components/shiki-languages.js +2020 -0
- package/components/shiki-themes.js +33 -0
- package/dist/cli/index.js +3 -2
- package/dist/core/add/index.js +2 -2
- package/dist/core/build/css-asset-name.js +2 -1
- package/dist/core/config/config.d.ts +3 -1
- package/dist/core/config/config.js +16 -49
- package/dist/core/config/settings.js +6 -2
- package/dist/core/config/vite-load.d.ts +17 -0
- package/dist/core/config/vite-load.js +106 -0
- package/dist/core/constants.js +1 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/messages.js +2 -2
- package/package.json +5 -5
package/components/Code.astro
CHANGED
|
@@ -56,7 +56,10 @@ const highlighter = await getHighlighter({
|
|
|
56
56
|
// Load custom lang if passed an object, otherwise load the default
|
|
57
57
|
langs: typeof lang !== 'string' ? [lang] : undefined,
|
|
58
58
|
});
|
|
59
|
-
const _html = highlighter.codeToHtml(code, {
|
|
59
|
+
const _html = highlighter.codeToHtml(code, {
|
|
60
|
+
lang: typeof lang === 'string' ? lang : lang.id,
|
|
61
|
+
theme,
|
|
62
|
+
});
|
|
60
63
|
const html = repairShikiTheme(_html);
|
|
61
64
|
---
|
|
62
65
|
|
package/components/Shiki.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { getHighlighter as getShikiHighlighter } from 'shiki';
|
|
2
|
+
import { themes } from './shiki-themes.js';
|
|
3
|
+
import { languages } from './shiki-languages.js';
|
|
2
4
|
|
|
3
5
|
// Caches Promise<Highligher> for reuse when the same theme and langs are provided
|
|
4
6
|
const _resolvedHighlighters = new Map();
|
|
5
7
|
|
|
8
|
+
/** @type {Promise<any>} */
|
|
9
|
+
let _allLanguages;
|
|
10
|
+
|
|
6
11
|
function stringify(opts) {
|
|
7
12
|
// Always sort keys before stringifying to make sure objects match regardless of parameter ordering
|
|
8
13
|
return JSON.stringify(opts, Object.keys(opts).sort());
|
|
@@ -12,16 +17,36 @@ function stringify(opts) {
|
|
|
12
17
|
* @param {import('shiki').HighlighterOptions} opts
|
|
13
18
|
* @returns {Promise<import('shiki').Highlighter>}
|
|
14
19
|
*/
|
|
15
|
-
|
|
16
|
-
const
|
|
20
|
+
async function resolveHighlighter(opts) {
|
|
21
|
+
const resolvedThemes = [];
|
|
22
|
+
if (opts.theme && opts.theme in themes) {
|
|
23
|
+
resolvedThemes.push(await themes[opts.theme]());
|
|
24
|
+
}
|
|
17
25
|
|
|
18
|
-
|
|
19
|
-
if (
|
|
20
|
-
|
|
26
|
+
let resolvedLanguages;
|
|
27
|
+
if (opts.langs) {
|
|
28
|
+
resolvedLanguages = opts.langs;
|
|
29
|
+
} else {
|
|
30
|
+
if (!_allLanguages) {
|
|
31
|
+
_allLanguages = (await Promise.all(Object.values(languages).map((fn) => fn()))).filter(
|
|
32
|
+
Boolean
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
resolvedLanguages = await _allLanguages;
|
|
21
36
|
}
|
|
22
37
|
|
|
38
|
+
/** @type {import('shiki').HighlighterOptions} */
|
|
39
|
+
const highlighterOptions = {
|
|
40
|
+
...opts,
|
|
41
|
+
themes: resolvedThemes,
|
|
42
|
+
langs: resolvedLanguages,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// Do not pass through the theme as that will attempt to load it, even if it's included in themes
|
|
46
|
+
delete highlighterOptions['theme'];
|
|
47
|
+
|
|
23
48
|
// Start the async getHighlighter call and cache the Promise
|
|
24
|
-
const highlighter = getShikiHighlighter(
|
|
49
|
+
const highlighter = getShikiHighlighter(highlighterOptions).then((hl) => {
|
|
25
50
|
hl.setColorReplacements({
|
|
26
51
|
'#000001': 'var(--astro-code-color-text)',
|
|
27
52
|
'#000002': 'var(--astro-code-color-background)',
|
|
@@ -37,6 +62,23 @@ export function getHighlighter(opts) {
|
|
|
37
62
|
});
|
|
38
63
|
return hl;
|
|
39
64
|
});
|
|
65
|
+
|
|
66
|
+
return highlighter;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @param {import('shiki').HighlighterOptions} opts
|
|
71
|
+
* @returns {Promise<import('shiki').Highlighter>}
|
|
72
|
+
*/
|
|
73
|
+
export function getHighlighter(opts) {
|
|
74
|
+
const key = stringify(opts);
|
|
75
|
+
|
|
76
|
+
// Highlighter has already been requested, reuse the same instance
|
|
77
|
+
if (_resolvedHighlighters.has(key)) {
|
|
78
|
+
return _resolvedHighlighters.get(key);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const highlighter = resolveHighlighter(opts);
|
|
40
82
|
_resolvedHighlighters.set(key, highlighter);
|
|
41
83
|
|
|
42
84
|
return highlighter;
|