fix: use v-pre for mathjax instead of isCustomElement

pull/4747/head
Divyansh Singh 4 months ago
parent 26cb685adf
commit c9b89282f3

@ -329,12 +329,17 @@ export async function createMarkdownRenderer(
md.use(mathPlugin.default ?? mathPlugin, {
...(typeof options.math === 'boolean' ? {} : options.math)
})
const orig = md.renderer.rules.math_block!
md.renderer.rules.math_block = (tokens, idx, options, env, self) => {
return orig(tokens, idx, options, env, self).replace(
/^<mjx-container /,
'<mjx-container tabindex="0" '
)
const origMathInline = md.renderer.rules.math_inline!
md.renderer.rules.math_inline = function (...args) {
return origMathInline
.apply(this, args)
.replace(/^<mjx-container /, '<mjx-container v-pre ')
}
const origMathBlock = md.renderer.rules.math_block!
md.renderer.rules.math_block = function (...args) {
return origMathBlock
.apply(this, args)
.replace(/^<mjx-container /, '<mjx-container v-pre tabindex="0" ')
}
} catch (error) {
throw new Error(

@ -85,31 +85,12 @@ export async function createVitePressPlugin(
} = siteConfig
let markdownToVue: Awaited<ReturnType<typeof createMarkdownToVueRenderFn>>
const userCustomElementChecker =
userVuePluginOptions?.template?.compilerOptions?.isCustomElement
let isCustomElement = userCustomElementChecker
if (markdown?.math) {
isCustomElement = (tag) => {
if (tag.startsWith('mjx-')) {
return true
}
return userCustomElementChecker?.(tag) ?? false
}
}
// lazy require plugin-vue to respect NODE_ENV in @vue/compiler-x
const vuePlugin = await import('@vitejs/plugin-vue').then((r) =>
r.default({
include: /\.(?:vue|md)$/,
...userVuePluginOptions,
template: {
...userVuePluginOptions?.template,
compilerOptions: {
...userVuePluginOptions?.template?.compilerOptions,
isCustomElement
}
}
...userVuePluginOptions
})
)

Loading…
Cancel
Save