Skip to content

Commit

Permalink
feat(build): don't hard fail on unknown languages in fences (#1750)
Browse files Browse the repository at this point in the history
Co-authored-by: Divyansh Singh <[email protected]>
  • Loading branch information
clark-cui and brc-dd authored Jan 14, 2023
1 parent 3b890e8 commit 1ae0596
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/node/markdown/plugins/highlight.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { customAlphabet } from 'nanoid'
import c from 'picocolors'
import type { HtmlRendererOptions, IThemeRegistration } from 'shiki'
import {
addClass,
Expand All @@ -10,7 +12,6 @@ import {
type Processor
} from 'shiki-processor'
import type { ThemeOptions } from '../markdown'
import { customAlphabet } from 'nanoid'

const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz', 10)

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

const langLoaded = highlighter.getLoadedLanguages().includes(lang as any)
if (!langLoaded) {
console.warn(
c.yellow(
`The language '${lang}' is not loaded, falling back to '${
defaultLang || 'txt'
}' for syntax highlighting.`
)
)
lang = defaultLang
}

const lineOptions = attrsToLines(attrs)
const cleanup = (str: string) =>
str
Expand Down

0 comments on commit 1ae0596

Please sign in to comment.