mirror of
https://github.com/Fechin/reference.git
synced 2026-11-21 05:24:10 +03:00
Added KaTeX plugin
This commit is contained in:
1 parent
a38d306325
commit
c8b9917b11
1 file changed
+22
@@ -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>
|
||||
<% } %>
|
||||
Reference in new issue
Block a user