Configure MathJax overflow handling (#986)

This commit is contained in:
Mimi 2026-08-05 11:07:25 +08:00 committed by GitHub
parent c0232764b3
commit abd6a790ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 5 deletions

View File

@ -572,6 +572,8 @@ math:
enable: false enable: false
# Available values: none | ams | all # Available values: none | ams | all
tags: none tags: none
# Available values: overflow | scroll | scale | truncate | linebreak
display_overflow: scroll
katex: katex:
enable: false enable: false

View File

@ -1,5 +1,5 @@
if (hexo-config('math.mathjax.enable')) { if (hexo-config('math.mathjax.enable')) {
mjx-container[jax='CHTML'][display='true'], .has-jax { .has-jax {
overflow: auto hidden; overflow: auto hidden;
} }

View File

@ -4,6 +4,12 @@ document.addEventListener('page:loaded', () => {
if (!CONFIG.enableMath) return; if (!CONFIG.enableMath) return;
if (typeof MathJax === 'undefined') { if (typeof MathJax === 'undefined') {
const output = {
displayOverflow: CONFIG.mathjax.display_overflow
};
if (CONFIG.mathjax.font_path) {
output.fontPath = CONFIG.mathjax.font_path;
}
window.MathJax = { window.MathJax = {
tex: { tex: {
inlineMath: { '[+]': [['$', '$']] }, inlineMath: { '[+]': [['$', '$']] },
@ -12,7 +18,7 @@ document.addEventListener('page:loaded', () => {
options: { options: {
renderActions: { renderActions: {
insertedScript: [200, () => { insertedScript: [200, () => {
document.querySelectorAll('mjx-container').forEach(node => { document.querySelectorAll('mjx-container:not([display])').forEach(node => {
const target = node.parentNode; const target = node.parentNode;
if (target.nodeName.toLowerCase() === 'li') { if (target.nodeName.toLowerCase() === 'li') {
target.parentNode.classList.add('has-jax'); target.parentNode.classList.add('has-jax');
@ -21,9 +27,7 @@ document.addEventListener('page:loaded', () => {
}, '', false] }, '', false]
} }
}, },
output: CONFIG.mathjax.font_path ? { output
fontPath: CONFIG.mathjax.font_path
} : {}
}; };
NexT.utils.getScript(CONFIG.mathjax.js, { NexT.utils.getScript(CONFIG.mathjax.js, {
attributes: { attributes: {