Skip to content

Commit

Permalink
fix: fallback unknown code language
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed May 21, 2024
1 parent d924b0d commit 9b374cc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/shiki/shiki.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 || {
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/ShikiRemark.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down

0 comments on commit 9b374cc

Please sign in to comment.