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, { md.use(mathPlugin.default ?? mathPlugin, {
...(typeof options.math === 'boolean' ? {} : options.math) ...(typeof options.math === 'boolean' ? {} : options.math)
}) })
const orig = md.renderer.rules.math_block! const origMathInline = md.renderer.rules.math_inline!
md.renderer.rules.math_block = (tokens, idx, options, env, self) => { md.renderer.rules.math_inline = function (...args) {
return orig(tokens, idx, options, env, self).replace( return origMathInline
/^<mjx-container /, .apply(this, args)
'<mjx-container tabindex="0" ' .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) { } catch (error) {
throw new Error( throw new Error(

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

Loading…
Cancel
Save