Skip to content

Commit 1ae0596

Browse files
clark-cuibrc-dd
andauthored
feat(build): don't hard fail on unknown languages in fences (#1750)
Co-authored-by: Divyansh Singh <40380293+brc-dd@users.noreply.github.com>
1 parent 3b890e8 commit 1ae0596

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/node/markdown/plugins/highlight.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { customAlphabet } from 'nanoid'
2+
import c from 'picocolors'
13
import type { HtmlRendererOptions, IThemeRegistration } from 'shiki'
24
import {
35
addClass,
@@ -10,7 +12,6 @@ import {
1012
type Processor
1113
} from 'shiki-processor'
1214
import type { ThemeOptions } from '../markdown'
13-
import { customAlphabet } from 'nanoid'
1415

1516
const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz', 10)
1617

@@ -85,6 +86,18 @@ export async function highlight(
8586
lang =
8687
lang.replace(lineNoRE, '').replace(vueRE, '').toLowerCase() || defaultLang
8788

89+
const langLoaded = highlighter.getLoadedLanguages().includes(lang as any)
90+
if (!langLoaded) {
91+
console.warn(
92+
c.yellow(
93+
`The language '${lang}' is not loaded, falling back to '${
94+
defaultLang || 'txt'
95+
}' for syntax highlighting.`
96+
)
97+
)
98+
lang = defaultLang
99+
}
100+
88101
const lineOptions = attrsToLines(attrs)
89102
const cleanup = (str: string) =>
90103
str

0 commit comments

Comments
 (0)