Skip to content

Commit c9b8928

Browse files
committed
fix: use v-pre for mathjax instead of isCustomElement
1 parent 26cb685 commit c9b8928

File tree

2 files changed

+12
-26
lines changed

2 files changed

+12
-26
lines changed

src/node/markdown/markdown.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -329,12 +329,17 @@ export async function createMarkdownRenderer(
329329
md.use(mathPlugin.default ?? mathPlugin, {
330330
...(typeof options.math === 'boolean' ? {} : options.math)
331331
})
332-
const orig = md.renderer.rules.math_block!
333-
md.renderer.rules.math_block = (tokens, idx, options, env, self) => {
334-
return orig(tokens, idx, options, env, self).replace(
335-
/^<mjx-container /,
336-
'<mjx-container tabindex="0" '
337-
)
332+
const origMathInline = md.renderer.rules.math_inline!
333+
md.renderer.rules.math_inline = function (...args) {
334+
return origMathInline
335+
.apply(this, args)
336+
.replace(/^<mjx-container /, '<mjx-container v-pre ')
337+
}
338+
const origMathBlock = md.renderer.rules.math_block!
339+
md.renderer.rules.math_block = function (...args) {
340+
return origMathBlock
341+
.apply(this, args)
342+
.replace(/^<mjx-container /, '<mjx-container v-pre tabindex="0" ')
338343
}
339344
} catch (error) {
340345
throw new Error(

src/node/plugin.ts

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -85,31 +85,12 @@ export async function createVitePressPlugin(
8585
} = siteConfig
8686

8787
let markdownToVue: Awaited<ReturnType<typeof createMarkdownToVueRenderFn>>
88-
const userCustomElementChecker =
89-
userVuePluginOptions?.template?.compilerOptions?.isCustomElement
90-
let isCustomElement = userCustomElementChecker
91-
92-
if (markdown?.math) {
93-
isCustomElement = (tag) => {
94-
if (tag.startsWith('mjx-')) {
95-
return true
96-
}
97-
return userCustomElementChecker?.(tag) ?? false
98-
}
99-
}
10088

10189
// lazy require plugin-vue to respect NODE_ENV in @vue/compiler-x
10290
const vuePlugin = await import('@vitejs/plugin-vue').then((r) =>
10391
r.default({
10492
include: /\.(?:vue|md)$/,
105-
...userVuePluginOptions,
106-
template: {
107-
...userVuePluginOptions?.template,
108-
compilerOptions: {
109-
...userVuePluginOptions?.template?.compilerOptions,
110-
isCustomElement
111-
}
112-
}
93+
...userVuePluginOptions
11394
})
11495
)
11596

0 commit comments

Comments
 (0)