fix theme...
This commit is contained in:
18
themes/anzhiyu/layout/includes/third-party/math/index.pug
vendored
Normal file
18
themes/anzhiyu/layout/includes/third-party/math/index.pug
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
if theme.mathjax && theme.mathjax.enable
|
||||
if theme.mathjax.per_page
|
||||
if is_post() || is_page()
|
||||
include ./mathjax.pug
|
||||
else
|
||||
if page.mathjax
|
||||
include ./mathjax.pug
|
||||
|
||||
if theme.katex && theme.katex.enable
|
||||
if theme.katex.per_page
|
||||
if is_post() || is_page()
|
||||
include ./katex.pug
|
||||
else
|
||||
if page.katex
|
||||
include ./katex.pug
|
||||
|
||||
if theme.mermaid.enable
|
||||
include ./mermaid.pug
|
||||
9
themes/anzhiyu/layout/includes/third-party/math/katex.pug
vendored
Normal file
9
themes/anzhiyu/layout/includes/third-party/math/katex.pug
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
link(rel="stylesheet" type="text/css" href=url_for(theme.asset.katex))
|
||||
script(src=url_for(theme.asset.katex_copytex))
|
||||
script.
|
||||
(() => {
|
||||
document.querySelectorAll('#article-container span.katex-display').forEach(item => {
|
||||
anzhiyu.wrap(item, 'div', { class: 'katex-wrap'})
|
||||
})
|
||||
})()
|
||||
|
||||
38
themes/anzhiyu/layout/includes/third-party/math/mathjax.pug
vendored
Normal file
38
themes/anzhiyu/layout/includes/third-party/math/mathjax.pug
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
//- Mathjax 3
|
||||
script.
|
||||
if (!window.MathJax) {
|
||||
window.MathJax = {
|
||||
tex: {
|
||||
inlineMath: [['$', '$'], ['\\(', '\\)']],
|
||||
tags: 'ams'
|
||||
},
|
||||
chtml: {
|
||||
scale: 1.1
|
||||
},
|
||||
options: {
|
||||
renderActions: {
|
||||
findScript: [10, doc => {
|
||||
for (const node of document.querySelectorAll('script[type^="math/tex"]')) {
|
||||
const display = !!node.type.match(/; *mode=display/)
|
||||
const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display)
|
||||
const text = document.createTextNode('')
|
||||
node.parentNode.replaceChild(text, node)
|
||||
math.start = {node: text, delim: '', n: 0}
|
||||
math.end = {node: text, delim: '', n: 0}
|
||||
doc.math.push(math)
|
||||
}
|
||||
}, '']
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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.startup.document.state(0)
|
||||
MathJax.texReset()
|
||||
MathJax.typesetPromise()
|
||||
}
|
||||
38
themes/anzhiyu/layout/includes/third-party/math/mermaid.pug
vendored
Normal file
38
themes/anzhiyu/layout/includes/third-party/math/mermaid.pug
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
script.
|
||||
(() => {
|
||||
const $mermaid = document.querySelectorAll('#article-container .mermaid-wrap')
|
||||
if ($mermaid.length === 0) return
|
||||
const runMermaid = () => {
|
||||
window.loadMermaid = true
|
||||
const theme = document.documentElement.getAttribute('data-theme') === 'dark' ? '!{theme.mermaid.theme.dark}' : '!{theme.mermaid.theme.light}'
|
||||
|
||||
Array.from($mermaid).forEach((item, index) => {
|
||||
const mermaidSrc = item.firstElementChild
|
||||
const mermaidThemeConfig = '%%{init:{ \'theme\':\'' + theme + '\'}}%%\n'
|
||||
const mermaidID = 'mermaid-' + index
|
||||
const mermaidDefinition = mermaidThemeConfig + mermaidSrc.textContent
|
||||
|
||||
const renderFn = mermaid.render(mermaidID, mermaidDefinition)
|
||||
|
||||
const renderV10 = () => {
|
||||
renderFn.then(({svg}) => {
|
||||
mermaidSrc.insertAdjacentHTML('afterend', svg)
|
||||
})
|
||||
}
|
||||
|
||||
const renderV9 = svg => {
|
||||
mermaidSrc.insertAdjacentHTML('afterend', svg)
|
||||
}
|
||||
|
||||
typeof renderFn === 'string' ? renderV9(renderFn) : renderV10()
|
||||
})
|
||||
}
|
||||
|
||||
const loadMermaid = () => {
|
||||
window.loadMermaid ? runMermaid() : getScript('!{url_for(theme.asset.mermaid)}').then(runMermaid)
|
||||
}
|
||||
|
||||
anzhiyu.addGlobalFn('themeChange', runMermaid, 'mermaid')
|
||||
|
||||
window.pjax ? loadMermaid() : document.addEventListener('DOMContentLoaded', loadMermaid)
|
||||
})()
|
||||
Reference in New Issue
Block a user