解决 katex pjax问题

This commit is contained in:
1152958806@qq.com 2023-10-08 14:13:51 +08:00
parent 11bc32f724
commit 630e285b77
1 changed files with 22 additions and 0 deletions

View File

@ -15,6 +15,28 @@
<link th:if="${#strings.equals(theme.config.comments.use, 'Waline') <link th:if="${#strings.equals(theme.config.comments.use, 'Waline')
&& not #strings.isEmpty(theme.config.comments.walines.serverURL)}" && not #strings.isEmpty(theme.config.comments.walines.serverURL)}"
rel="stylesheet" th:href="${not #strings.isEmpty(theme.config.comments.walines.walinesCss) ? theme.config.comments.walines.walinesCss : 'https://cdn.cbd.int/@waline/client@2.15.7/dist/waline.css' }"> rel="stylesheet" th:href="${not #strings.isEmpty(theme.config.comments.walines.walinesCss) ? theme.config.comments.walines.walinesCss : 'https://cdn.cbd.int/@waline/client@2.15.7/dist/waline.css' }">
<!-- 解决 katex pjax问题 -->
<th:block th:if="${pluginFinder.available('plugin-katex')}">
<script defer="" src="/plugins/plugin-katex/assets/static/katex.min.js"></script>
<script>
document.addEventListener("pjax:complete", function () {
if (GLOBAL_CONFIG.htmlType == 'post' || GLOBAL_CONFIG.htmlType == 'page') {
const postBody = document.body
const renderMath = (selector, displayMode) => {
const els = postBody.querySelectorAll(selector)
els.forEach((el) => {
katex.render(el.innerText, el, { displayMode })
})
}
if (postBody) {
renderMath("[math-inline],.math-inline,.katex--inline", false);
renderMath("[math-display],.math-display,.katex--display", true);
}
}
});
</script>
</th:block>
</head> </head>
<body> <body>