Skip to content

Commit

Permalink
fix: component is not able to use a custom theme anymore (#5952)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
JerryWu1234 and natemoo-re authored Jan 25, 2023
1 parent 883e0cc commit aedf23f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/ten-icons-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Astro <Code> component is not able to use a custom theme anymore
3 changes: 1 addition & 2 deletions packages/astro/components/Code.astro
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ const highlighter = await getHighlighter({
langs: typeof lang !== 'string' ? [lang] : undefined,
});
const _html = highlighter.codeToHtml(code, {
lang: typeof lang === 'string' ? lang : lang.id,
theme,
lang: typeof lang === 'string' ? lang : lang.id
});
const html = repairShikiTheme(_html);
---
Expand Down
5 changes: 4 additions & 1 deletion packages/astro/components/Shiki.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ function stringify(opts) {
*/
async function resolveHighlighter(opts) {
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]());
}


let resolvedLanguages;
if (opts.langs) {
resolvedLanguages = opts.langs;
Expand Down

0 comments on commit aedf23f

Please sign in to comment.