Skip to content

Commit 846fec0

Browse files
authored
Merge pull request #126 from code-hike/handle-invalid-language
Handle invalid language
2 parents 9111a23 + 19a4397 commit 846fec0

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

packages/highlighter/src/index.tsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,15 @@ export async function highlight({
4747
await highlighter.loadTheme(theme as IShikiTheme)
4848
}
4949
if (missingLang(highlighter, lang)) {
50-
await highlighter.loadLanguage(lang as Lang)
50+
try {
51+
await highlighter.loadLanguage(lang as Lang)
52+
} catch (e) {
53+
console.warn(
54+
"[Code Hike warning]",
55+
`${lang} is not a valid language, no syntax highlighting will be applied.`
56+
)
57+
return highlight({ code, lang: "text", theme })
58+
}
5159
}
5260

5361
const tokenizedLines = highlighter.codeToThemedTokens(

packages/playground/content/simple-code.mdx

+8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ function lorem(ipsum, dolor = 1) {
66
}
77
```
88

9+
```mermaid
10+
graph LR
11+
Start1(Start)
12+
--Bot 启动--> check1[检查群内的非 Authing 用户]
13+
--> addUser[添加 Authing 用户并消息提醒绑定手机号]
14+
--> End1(End)
15+
```
16+
917
```js
1018
function lorem(ipsum, dolor = 1) {}
1119
```

0 commit comments

Comments
 (0)