From ae0961813199e7afb06d027c6af4e64c65c07782 Mon Sep 17 00:00:00 2001 From: jerryc127 Date: Thu, 12 Nov 2026 15:58:02 +0800 Subject: [PATCH] fix(mathjax): cover all block containers for inline formula overflow Once mjx-container is forced to display: inline, its own max-width and overflow-x no longer apply to a non-replaced inline box, so the formula width escapes to the document. The previous rule only covered p and li. - cover headings (h1-h6) too, otherwise a long inline formula in a heading widens the page (measured 395px of horizontal page scroll at a 420px viewport) - li becomes a scroll container, which clips its outside-positioned ::marker, so switch those items to list-style-position: inside - fall back to the previous inline-grid when :has() is unsupported, since the container rules are then dropped while display: inline still applies, which is worse than before --- source/css/_layout/third-party.styl | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/source/css/_layout/third-party.styl b/source/css/_layout/third-party.styl index 0ba00cc..901b3fc 100644 --- a/source/css/_layout/third-party.styl +++ b/source/css/_layout/third-party.styl @@ -288,17 +288,35 @@ if hexo-config('math.use') display: block !important min-width: auto !important - // MathJax 4 会把一条行内公式拆成多个 + , - // 只有内联排版能保留段间距和每段自己的 vertical-align, - // 用 nowrap 保证它不换行,超长时交给外层段落横向滚动 + // MathJax 4 splits an inline formula into several + . + // Inline layout keeps the line spacing and each part's vertical-align, + // and nowrap keeps these parts on one line. &:not([display]) display: inline !important white-space: nowrap - // 行内公式过长时让所在段落/列表项横向滚动,而不是撑破页面 - #article-container :is(p, li):has(mjx-container:not([display])) + // Let the block-level parent scroll instead of overflowing the page. + // p / li alone is not enough: headings and note bodies overflow too, + // because max-width no longer applies once mjx-container is inline. + #article-container :is(p, h1, h2, h3, h4, h5, h6):has(mjx-container:not([display])) overflow-x: auto + // A scrolling li clips its outside-positioned ::marker. + #article-container li:has(mjx-container:not([display])) + overflow-x: auto + list-style-position: inside + + // Without :has() the rules above are dropped while inline still applies. + // Fall back to the previous inline-grid rather than an unclipped inline. + @css { + @supports not selector(:has(a)) { + mjx-container:not([display]) { + display: inline-grid !important; + white-space: normal; + } + } + } + mjx-assistive-mml right: 0 bottom: 0