Added KaTeX plugin

This commit is contained in:
fechin committed 2023-01-03 18:22:27 +08:00
1 parent a38d306325
commit c8b9917b11
1 file changed
+22
+22
View File
@@ -13,4 +13,26 @@
}
});
</script>
<% } %>
<% if (is_post() && page.plugins != undefined && page.plugins.includes("katex") ){ %>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/katex.min.css" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/katex.min.js" crossorigin="anonymous"></script>
<script>
const render = function (text, el) {
// Do stuff if text starts with `latex`
var renderedKatex = katex.renderToString(
text.replace('KaTeX:', ''),
{ throwOnError: false }
);
// Populate katex and additional markup for formatting
el.outerHTML = `<span class="katex-wrap">${renderedKatex}</span>`;
}
document.querySelectorAll('code').forEach(function (el) {
if (el.textContent.startsWith('KaTeX:') || el.classList.contains("language-KaTeX")) {
render(el.textContent, el)
}
})
</script>
<% } %>