0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-20 22:12:38 -05:00

fix: component is not able to use a custom theme anymore (#5952)

* Astro <Code> component is not able to use a custom theme anymore

* Astro <Code> component is not able to use a custom theme anymore

* Astro <Code> component is not able to use a custom theme anymore

Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
This commit is contained in:
wulinsheng123 2023-01-26 07:21:15 +08:00 committed by GitHub
parent 883e0cc299
commit aedf23f858
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 3 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Astro <Code> component is not able to use a custom theme anymore

View file

@ -57,8 +57,7 @@ const highlighter = await getHighlighter({
langs: typeof lang !== 'string' ? [lang] : undefined, langs: typeof lang !== 'string' ? [lang] : undefined,
}); });
const _html = highlighter.codeToHtml(code, { const _html = highlighter.codeToHtml(code, {
lang: typeof lang === 'string' ? lang : lang.id, lang: typeof lang === 'string' ? lang : lang.id
theme,
}); });
const html = repairShikiTheme(_html); const html = repairShikiTheme(_html);
--- ---

View file

@ -19,10 +19,13 @@ function stringify(opts) {
*/ */
async function resolveHighlighter(opts) { async function resolveHighlighter(opts) {
const resolvedThemes = []; const resolvedThemes = [];
if (opts.theme && opts.theme in themes) { if (Object.keys(opts.theme).length) {
resolvedThemes.push(opts.theme);
} else if (opts.theme && opts.theme in themes) {
resolvedThemes.push(await themes[opts.theme]()); resolvedThemes.push(await themes[opts.theme]());
} }
let resolvedLanguages; let resolvedLanguages;
if (opts.langs) { if (opts.langs) {
resolvedLanguages = opts.langs; resolvedLanguages = opts.langs;