fix(plugin-shikiji): 非 twoslash 代码块 添加 v-pre 指令

This commit is contained in:
pengzhanbo 2024-02-25 02:34:45 +08:00
parent ff18a9b267
commit ef64ada12f

View File

@ -24,6 +24,7 @@ import { defaultHoverInfoProcessor, transformerTwoslash } from './rendererTransf
const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz', 10)
const cache = new LRUCache<string, string>(64)
const vueRE = /-vue$/
const RE_ESCAPE = /\[\\\!code/g
const mustacheRE = /\{\{.*?\}\}/g
@ -91,6 +92,7 @@ export async function highlight(
return (str: string, lang: string, attrs: string) => {
lang = lang || defaultLang
const vPre = vueRE.test(lang) ? '' : 'v-pre'
const key = str + lang + attrs
@ -150,6 +152,15 @@ export async function highlight(
},
}))
}
else {
inlineTransformers.push({
name: 'vuepress:v-pre',
pre(node) {
if (vPre)
node.properties['v-pre'] = ''
},
})
}
if (
(whitespace && attributes.whitespace !== false)