mirror of
https://github.com/withastro/astro.git
synced 2025-01-27 22:19:04 -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,
|
ThemeRegistration,
|
||||||
ThemeRegistrationRaw,
|
ThemeRegistrationRaw,
|
||||||
} from 'shikiji';
|
} from 'shikiji';
|
||||||
|
import { bundledLanguages } from 'shikiji/langs';
|
||||||
import { getCachedHighlighter } from '../dist/core/shiki.js';
|
import { getCachedHighlighter } from '../dist/core/shiki.js';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
@ -92,7 +93,13 @@ if (typeof lang === 'object') {
|
||||||
}
|
}
|
||||||
|
|
||||||
const highlighter = await getCachedHighlighter({
|
const highlighter = await getCachedHighlighter({
|
||||||
langs: [lang],
|
langs: [
|
||||||
|
typeof lang === 'string'
|
||||||
|
? Object.keys(bundledLanguages).includes(lang)
|
||||||
|
? lang
|
||||||
|
: 'plaintext'
|
||||||
|
: lang,
|
||||||
|
],
|
||||||
theme,
|
theme,
|
||||||
experimentalThemes,
|
experimentalThemes,
|
||||||
wrap,
|
wrap,
|
||||||
|
|
Loading…
Add table
Reference in a new issue