Skip to content

Commit 87b61b7

Browse files
committed
feat: add MathJax support
1 parent 53e350c commit 87b61b7

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

docs/.vitepress/config.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,22 @@ export default async () => defineConfig({
140140

141141
['script', {}, fs.readFileSync(path.resolve(__dirname, './inlined-scripts/redirectDocsPath.js'), 'utf-8')],
142142
['script', {}, fs.readFileSync(path.resolve(__dirname, './inlined-scripts/restorePreference.js'), 'utf-8')],
143+
144+
// MathJax conf
145+
['script', {}, `
146+
window.MathJax = {
147+
tex: {
148+
inlineMath: [['$', '$'], ['\\\\(', '\\\\)']],
149+
displayMath: [['$$', '$$'], ['\\\\[', '\\\\]']],
150+
processEscapes: true,
151+
processEnvironments: true
152+
},
153+
options: {
154+
skipHtmlTags: ['script', 'noscript', 'style', 'textarea', 'pre']
155+
}
156+
};
157+
`],
158+
['script', { async: '', src: 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js' }, ''],
143159
],
144160

145161
markdown: {

docs/.vitepress/theme/index.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { h } from 'vue'
2+
import { useRoute } from 'vitepress'
23
import Theme from 'vitepress/theme'
4+
import { watch, nextTick } from 'vue'
35
import '../styles/vars.css'
46
import HomePage from '../components/HomePage.vue'
57
import SvgImage from '../components/SvgImage.vue'
@@ -15,7 +17,19 @@ export default {
1517
'doc-after': () => h(Comments),
1618
})
1719
},
18-
enhanceApp({ app }) {
20+
enhanceApp({ app, router }) {
1921
app.component('SvgImage', SvgImage)
2022
},
23+
setup() {
24+
const route = useRoute()
25+
watch(
26+
() => route.path,
27+
() => nextTick(() => {
28+
if (typeof window !== 'undefined' && (window as any).MathJax) {
29+
(window as any).MathJax.typesetPromise()
30+
}
31+
}),
32+
{ immediate: true }
33+
)
34+
}
2135
}

0 commit comments

Comments
 (0)