Skip to content
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

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

Merged
merged 4 commits into from
Jan 14, 2023
Merged
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
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