Skip to content

Commit

Permalink
Merge branch 'main' into fix/upgrade-error
Browse files Browse the repository at this point in the history
  • Loading branch information
natemoo-re authored Nov 28, 2023
2 parents 390e7ca + 0dc99c9 commit 8553c6f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/dull-deers-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Prevents the Code component from crashing if the lang isn't supported by falling back to `plaintext`.
9 changes: 8 additions & 1 deletion packages/astro/components/Code.astro
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
ThemeRegistration,
ThemeRegistrationRaw,
} from 'shikiji';
import { bundledLanguages } from 'shikiji/langs';
import { getCachedHighlighter } from '../dist/core/shiki.js';
interface Props {
Expand Down Expand Up @@ -92,7 +93,13 @@ if (typeof lang === 'object') {
}
const highlighter = await getCachedHighlighter({
langs: [lang],
langs: [
typeof lang === 'string'
? Object.keys(bundledLanguages).includes(lang)
? lang
: 'plaintext'
: lang,
],
theme,
experimentalThemes,
wrap,
Expand Down

0 comments on commit 8553c6f

Please sign in to comment.