Skip to content

Commit afc611d

Browse files
jeferson-sbbrc-dd
andauthored
fix(theme,a11y): handle overflow on long mathematical equation and make tables focusable (#3932) (closes #3914)
Co-authored-by: Divyansh Singh <[email protected]>
1 parent b2fa932 commit afc611d

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

Diff for: src/client/theme-default/styles/base.css

+1-2
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,7 @@ vite-error-overlay {
242242
}
243243

244244
mjx-container {
245-
display: inline-block;
246-
margin: auto 2px -2px;
245+
overflow-x: auto;
247246
}
248247

249248
mjx-container > svg {

Diff for: src/node/markdown/markdown.ts

+11
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ export const createMarkdownRenderer = async (
231231
)
232232
.use(lineNumberPlugin, options.lineNumbers)
233233

234+
md.renderer.rules.table_open = function (tokens, idx, options, env, self) {
235+
return '<table tabindex="0">\n'
236+
}
237+
234238
if (options.gfmAlerts !== false) {
235239
md.use(gitHubAlertsPlugin)
236240
}
@@ -287,6 +291,13 @@ export const createMarkdownRenderer = async (
287291
md.use(mathPlugin.default ?? mathPlugin, {
288292
...(typeof options.math === 'boolean' ? {} : options.math)
289293
})
294+
const orig = md.renderer.rules.math_block!
295+
md.renderer.rules.math_block = (tokens, idx, options, env, self) => {
296+
return orig(tokens, idx, options, env, self).replace(
297+
/^<mjx-container /,
298+
'<mjx-container tabindex="0" '
299+
)
300+
}
290301
} catch (error) {
291302
throw new Error(
292303
'You need to install `markdown-it-mathjax3` to use math support.'

Diff for: src/node/plugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export async function createVitePressPlugin(
8787

8888
if (markdown?.math) {
8989
isCustomElement = (tag) => {
90-
if (['mjx-container', 'mjx-assistive-mml'].includes(tag)) {
90+
if (tag.startsWith('mjx-')) {
9191
return true
9292
}
9393
return userCustomElementChecker?.(tag) ?? false

0 commit comments

Comments
 (0)