feat(build): don't hard fail on unknown languages in fences (#1750)

Co-authored-by: Divyansh Singh <40380293+brc-dd@users.noreply.github.com>
pull/1805/head
Clark Cui 2 years ago committed by GitHub
parent 3b890e8177
commit 1ae0596939
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,3 +1,5 @@
import { customAlphabet } from 'nanoid'
import c from 'picocolors'
import type { HtmlRendererOptions, IThemeRegistration } from 'shiki' import type { HtmlRendererOptions, IThemeRegistration } from 'shiki'
import { import {
addClass, addClass,
@ -10,7 +12,6 @@ import {
type Processor type Processor
} from 'shiki-processor' } from 'shiki-processor'
import type { ThemeOptions } from '../markdown' import type { ThemeOptions } from '../markdown'
import { customAlphabet } from 'nanoid'
const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz', 10) const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz', 10)
@ -85,6 +86,18 @@ export async function highlight(
lang = lang =
lang.replace(lineNoRE, '').replace(vueRE, '').toLowerCase() || defaultLang 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 lineOptions = attrsToLines(attrs)
const cleanup = (str: string) => const cleanup = (str: string) =>
str str

Loading…
Cancel
Save