Update custom.js

Updated previewAjax() and sendPreview() functions to use katex parameter instead of mathjax. 

Replaced MathJax.Hub.Queue() call with KaTeXrenderMathInElement() for live preview rendering.
This commit is contained in:
Groupr 2025-11-11 04:12:51 +00:00
parent ca93bd16ae
commit b07a2ebe88

View file

@ -2,7 +2,7 @@
// previewTimer must live outside the functions.
var previewTimer = null;
function previewAjax(textarea, div, show_raw = false, mathjax = false){
function previewAjax(textarea, div, show_raw = false, katex = false){
// set div to raw textarea while waiting for remote Markdown rendering.
if (show_raw) {
// bust HTML tags like <script> to prevent running evil code.
@ -14,12 +14,12 @@ function previewAjax(textarea, div, show_raw = false, mathjax = false){
clearTimeout(previewTimer);
}
previewTimer = setTimeout(
function() { sendPreview( textarea, div, mathjax ); },
function() { sendPreview( textarea, div, katex ); },
800
);
}
function sendPreview(textarea, div, mathjax=false){
function sendPreview(textarea, div, katex=false){
$.ajaxSetup ({
cache: false
});
@ -29,10 +29,17 @@ function sendPreview(textarea, div, mathjax=false){
$( '#' + div ).load( url, params );
if (mathjax) {
if (katex) {
setTimeout(function(){
// hack: block MathJax rerender for 50ms, give div chance to load.
MathJax.Hub.Queue(["Typeset",MathJax.Hub,div]);
// Give div chance to load before rendering math
if (typeof renderMathInElement !== 'undefined') {
renderMathInElement(document.getElementById(div), {
delimiters: [
{left: '$$', right: '$$', display: true},
{left: '$', right: '$', display: false}
]
});
}
}, 100);
}
}