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

feat(astro): use plaintext lang if lang does not exist (#9193)

Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
This commit is contained in:
Florian Lefebvre 2023-11-28 19:14:22 +01:00 committed by GitHub
parent d0d5ff78c9
commit 0dc99c9a28
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Prevents the Code component from crashing if the lang isn't supported by falling back to `plaintext`.

View file

@ -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,