summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Florian Lefebvre <contact@florian-lefebvre.dev> 2023-11-28 19:14:22 +0100
committerGravatar GitHub <noreply@github.com> 2023-11-28 12:14:22 -0600
commit0dc99c9a28fcb6b46db49eefac6afa415875edcb (patch)
tree1f9e36cf1eb4b70c3b396f8d023524ca719a6ff6
parentd0d5ff78c9f81bea8678cde443d0f822465fbb4d (diff)
downloadastro-0dc99c9a28fcb6b46db49eefac6afa415875edcb.tar.gz
astro-0dc99c9a28fcb6b46db49eefac6afa415875edcb.tar.zst
astro-0dc99c9a28fcb6b46db49eefac6afa415875edcb.zip
feat(astro): use plaintext lang if lang does not exist (#9193)
Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
-rw-r--r--.changeset/dull-deers-accept.md5
-rw-r--r--packages/astro/components/Code.astro9
2 files changed, 13 insertions, 1 deletions
diff --git a/.changeset/dull-deers-accept.md b/.changeset/dull-deers-accept.md
new file mode 100644
index 000000000..d39b599bb
--- /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 506a3ed3c..3203d9ff5 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,