diff --git a/.changeset/dull-deers-accept.md b/.changeset/dull-deers-accept.md new file mode 100644 index 000000000000..d39b599bb017 --- /dev/null +++ b/.changeset/dull-deers-accept.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Prevents the Code component from crashing if the lang isn't supported by falling back to `plaintext`. diff --git a/packages/astro/components/Code.astro b/packages/astro/components/Code.astro index 506a3ed3c0d1..3203d9ff5284 100644 --- a/packages/astro/components/Code.astro +++ b/packages/astro/components/Code.astro @@ -10,6 +10,7 @@ import type { ThemeRegistration, ThemeRegistrationRaw, } from 'shikiji'; +import { bundledLanguages } from 'shikiji/langs'; import { getCachedHighlighter } from '../dist/core/shiki.js'; interface Props { @@ -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,