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
# Available values: none | ams | all
tags: none
# Available values: overflow | scroll | scale | truncate | linebreak
display_overflow: scroll
katex:
enable: false

View File

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

View File

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