Skip to content

Commit

Permalink
fix(theme,a11y): handle overflow on long mathematical equation and ma…
Browse files Browse the repository at this point in the history
…ke tables focusable (#3932) (closes #3914)

Co-authored-by: Divyansh Singh <[email protected]>
  • Loading branch information
jeferson-sb and brc-dd authored Jun 3, 2024
1 parent b2fa932 commit afc611d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/client/theme-default/styles/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,7 @@ vite-error-overlay {
}

mjx-container {
display: inline-block;
margin: auto 2px -2px;
overflow-x: auto;
}

mjx-container > svg {
Expand Down
11 changes: 11 additions & 0 deletions src/node/markdown/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ export const createMarkdownRenderer = async (
)
.use(lineNumberPlugin, options.lineNumbers)

md.renderer.rules.table_open = function (tokens, idx, options, env, self) {
return '<table tabindex="0">\n'
}

if (options.gfmAlerts !== false) {
md.use(gitHubAlertsPlugin)
}
Expand Down Expand Up @@ -287,6 +291,13 @@ export const createMarkdownRenderer = async (
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" '
)
}
} catch (error) {
throw new Error(
'You need to install `markdown-it-mathjax3` to use math support.'
Expand Down
2 changes: 1 addition & 1 deletion src/node/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export async function createVitePressPlugin(

if (markdown?.math) {
isCustomElement = (tag) => {
if (['mjx-container', 'mjx-assistive-mml'].includes(tag)) {
if (tag.startsWith('mjx-')) {
return true
}
return userCustomElementChecker?.(tag) ?? false
Expand Down

0 comments on commit afc611d

Please sign in to comment.