Skip to content

Handle invalid language #126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/highlighter/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,15 @@ export async function highlight({
await highlighter.loadTheme(theme as IShikiTheme)
}
if (missingLang(highlighter, lang)) {
await highlighter.loadLanguage(lang as Lang)
try {
await highlighter.loadLanguage(lang as Lang)
} catch (e) {
console.warn(
"[Code Hike warning]",
`${lang} is not a valid language, no syntax highlighting will be applied.`
)
return highlight({ code, lang: "text", theme })
}
}

const tokenizedLines = highlighter.codeToThemedTokens(
Expand Down
8 changes: 8 additions & 0 deletions packages/playground/content/simple-code.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ function lorem(ipsum, dolor = 1) {
}
```

```mermaid
graph LR
Start1(Start)
--Bot 启动--> check1[检查群内的非 Authing 用户]
--> addUser[添加 Authing 用户并消息提醒绑定手机号]
--> End1(End)
```

```js
function lorem(ipsum, dolor = 1) {}
```
Expand Down