|
|
|
@ -88,7 +88,7 @@ export async function highlight(
|
|
|
|
|
|
|
|
|
|
if (lang) {
|
|
|
|
|
const langLoaded = highlighter.getLoadedLanguages().includes(lang as any)
|
|
|
|
|
if (!langLoaded) {
|
|
|
|
|
if (!langLoaded && lang !== 'ansi') {
|
|
|
|
|
console.warn(
|
|
|
|
|
c.yellow(
|
|
|
|
|
`The language '${lang}' is not loaded, falling back to '${
|
|
|
|
@ -127,42 +127,28 @@ export async function highlight(
|
|
|
|
|
return s
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hasSingleTheme) {
|
|
|
|
|
str = removeMustache(str)
|
|
|
|
|
|
|
|
|
|
const codeToHtml = (theme: IThemeRegistration) => {
|
|
|
|
|
return cleanup(
|
|
|
|
|
restoreMustache(
|
|
|
|
|
highlighter.codeToHtml(removeMustache(str), {
|
|
|
|
|
lang,
|
|
|
|
|
lineOptions,
|
|
|
|
|
theme: getThemeName(theme)
|
|
|
|
|
})
|
|
|
|
|
lang === 'ansi'
|
|
|
|
|
? highlighter.ansiToHtml(str, {
|
|
|
|
|
lineOptions,
|
|
|
|
|
theme: getThemeName(theme)
|
|
|
|
|
})
|
|
|
|
|
: highlighter.codeToHtml(str, {
|
|
|
|
|
lang,
|
|
|
|
|
lineOptions,
|
|
|
|
|
theme: getThemeName(theme)
|
|
|
|
|
})
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const dark = addClass(
|
|
|
|
|
cleanup(
|
|
|
|
|
highlighter.codeToHtml(str, {
|
|
|
|
|
lang,
|
|
|
|
|
lineOptions,
|
|
|
|
|
theme: getThemeName(theme.dark)
|
|
|
|
|
})
|
|
|
|
|
),
|
|
|
|
|
'vp-code-dark',
|
|
|
|
|
'pre'
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const light = addClass(
|
|
|
|
|
cleanup(
|
|
|
|
|
highlighter.codeToHtml(str, {
|
|
|
|
|
lang,
|
|
|
|
|
lineOptions,
|
|
|
|
|
theme: getThemeName(theme.light)
|
|
|
|
|
})
|
|
|
|
|
),
|
|
|
|
|
'vp-code-light',
|
|
|
|
|
'pre'
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if (hasSingleTheme) return codeToHtml(theme)
|
|
|
|
|
const dark = addClass(codeToHtml(theme.dark), 'vp-code-dark', 'pre')
|
|
|
|
|
const light = addClass(codeToHtml(theme.light), 'vp-code-light', 'pre')
|
|
|
|
|
return dark + light
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|