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:
parent
ca93bd16ae
commit
b07a2ebe88
1 changed files with 13 additions and 6 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue