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:
parent
d0d5ff78c9
commit
0dc99c9a28
2 changed files with 13 additions and 1 deletions
5
.changeset/dull-deers-accept.md
Normal file
5
.changeset/dull-deers-accept.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Prevents the Code component from crashing if the lang isn't supported by falling back to `plaintext`.
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Reference in a new issue