mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-08-10 20:48:42 +08:00
- wordcount/min2read/totalcount built-in helpers (replaces hexo-wordcount) - cloudTags random sort support - waline lightbox via MutationObserver - subtitle: seq guard prevents stale API response race - newest-comments: escapeHtml XSS fix, unified fetchAndRender with cache fallback - katex: try/catch asset load, encrypt re-render - chartjs: destroy charts on pjax, fix theme property check - mathjax: DOMContentLoaded instead of load - mermaid: clean stale error elements - medium-zoom: single instance, detach on pjax - getScrollPercent: WeakMap cache with resize invalidation - overflowPaddingR: avoid stale DOM refs - readmode: dedupe button, pjax cleanup - hexo-blog-decrypt: null-guard translateFn and encryptFn - tw_cn: expand skipped translate tags - localStorage: try/catch setItem - cdn.js: fix [lib|dist]* character class regex bug - findArchivesTitle: support custom archive_dir - shuoshuoFN: guard moment.tz when timezone empty - umami: no-store cache, error handling, path param - artalk: vote config option - bump version 5.7.1.260810
83 lines
2.8 KiB
Plaintext
83 lines
2.8 KiB
Plaintext
//- Mathjax 4/5
|
|
- const { tags, enableMenu } = theme.math.mathjax
|
|
script.
|
|
(() => {
|
|
const changeScriptToMath = article => {
|
|
article.querySelectorAll('script[type^="math/tex"]').forEach(el => {
|
|
const display = /mode=display/.test(el.type)
|
|
const node = document.createElement(display ? 'div' : 'span')
|
|
node.textContent = display
|
|
? `$$${el.textContent}$$`
|
|
: `$${el.textContent}$`
|
|
el.parentNode.replaceChild(node, el)
|
|
})
|
|
}
|
|
|
|
const loadMathjax = () => {
|
|
const article = document.getElementById('article-container')
|
|
if (!article || article.querySelector('.hbe-container')) return
|
|
changeScriptToMath(article)
|
|
|
|
if (!window.MathJax) {
|
|
window.MathJax = {
|
|
loader: {
|
|
load: [
|
|
// Four font extension packages (optional)
|
|
//- '[tex]/bbm',
|
|
//- '[tex]/bboldx',
|
|
//- '[tex]/dsfont',
|
|
'[tex]/mhchem',
|
|
'ui/lazy'
|
|
],
|
|
paths: {
|
|
'mathjax-newcm': '[mathjax]/../@mathjax/mathjax-newcm-font',
|
|
|
|
//- // Four font extension packages (optional)
|
|
//- 'mathjax-bbm-extension': '[mathjax]/../@mathjax/mathjax-bbm-font-extension',
|
|
//- 'mathjax-bboldx-extension': '[mathjax]/../@mathjax/mathjax-bboldx-font-extension',
|
|
//- 'mathjax-dsfont-extension': '[mathjax]/../@mathjax/mathjax-dsfont-font-extension',
|
|
'mathjax-mhchem-extension': '[mathjax]/../@mathjax/mathjax-mhchem-font-extension'
|
|
}
|
|
},
|
|
output: {
|
|
font: 'mathjax-newcm',
|
|
},
|
|
tex: {
|
|
inlineMath: [['$', '$'], ['\\(', '\\)']],
|
|
tags: '!{tags}',
|
|
packages: {
|
|
'[+]': [
|
|
'mhchem'
|
|
]
|
|
}
|
|
},
|
|
chtml: {
|
|
scale: 1.1
|
|
},
|
|
options: {
|
|
lazyMargin: '200px',
|
|
enableMenu: !{enableMenu},
|
|
menuOptions: {
|
|
settings: {
|
|
enrich: false // Turn off Braille and voice narration text automatic generation
|
|
}
|
|
},
|
|
}
|
|
}
|
|
|
|
const script = document.createElement('script')
|
|
script.src = '!{url_for(theme.asset.mathjax)}'
|
|
script.id = 'MathJax-script'
|
|
script.async = true
|
|
document.head.appendChild(script)
|
|
} else {
|
|
MathJax.typesetClear()
|
|
MathJax.typesetPromise([ article ])
|
|
}
|
|
}
|
|
|
|
btf.addGlobalFn('encrypt', loadMathjax, 'mathjax')
|
|
if (window.pjax) loadMathjax()
|
|
else if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', loadMathjax)
|
|
else loadMathjax()
|
|
})() |