fix: fallback unknown code language

This commit is contained in:
DIYgod 2024-05-21 20:12:12 +08:00
parent d924b0d4d1
commit 9b374cc1e4
No known key found for this signature in database
2 changed files with 5 additions and 1 deletions

View File

@ -16,6 +16,10 @@ export const ShikiRender: FC<ShikiCodeProps> = async ({
}) => {
const highlighter = await createHighlighter()
if (!Object.keys(bundledLanguages).includes(language || "")) {
language = "text"
}
const rendered = highlighter.codeToHtml(code, {
lang: language || "text",
themes: codeTheme || {

View File

@ -30,7 +30,7 @@ const pickCodeLanguage = (props: any) => {
? (props.children.props.className as string)
: ""
if (className.includes("language-")) {
if (className?.includes("language-")) {
return className.replace("language-", "")
}
return ""