Skip to content

Commit

Permalink
Add callback to renderAllMath(), show time all rendering took in demo.
Browse files Browse the repository at this point in the history
(this is actually reordered history:
I first wrote a solution to #33 but it seems it slowed things down
=> this will help me measure before and after.)
  • Loading branch information
cben committed Oct 14, 2015
1 parent c862e94 commit 83297ef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 8 additions & 2 deletions demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
</head>
<body>
<h1>attempt at CodeMirror + in-place MathJax</h1>
<a href="https://github.com/cben/CodeMirror-MathJax">Source on github</a>
<a href="https://github.com/cben/CodeMirror-MathJax">Source on github</a> |
<span id="all-done-time">Rendering math...</span>

<form><textarea id="code" autofocus>**To edit formulas, move cursor into them with arrow keys.** Clicking with mouse should work but currently doesn't :-(.

Expand Down Expand Up @@ -134,8 +135,13 @@ <h1>attempt at CodeMirror + in-place MathJax</h1>
repeatedText += text;
}
editor.setValue(repeatedText);
var t0 = new Date().getTime();
CodeMirror.hookMath(editor, MathJax);
editor.renderAllMath();
editor.renderAllMath(function() {
var t1 = new Date().getTime();
var text = " done in " + (t1-t0) + "ms.";
document.getElementById("all-done-time").appendChild(document.createTextNode(text));
});
</script>
</body>
</html>
5 changes: 4 additions & 1 deletion render-math.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,13 @@ CodeMirror.hookMath = function(editor, MathJax) {
})));

// First pass - process whole document.
editor.renderAllMath = logFuncTime(function renderAllMath() {
editor.renderAllMath = logFuncTime(function renderAllMath(callback) {
doc.eachLine(processLine);
MathJax.Hub.Queue(flushMarkTextQueue);
MathJax.Hub.Queue(function() { logf()("-- All math rendered. --"); });
if(callback) {
MathJax.Hub.Queue(callback);
}
})

// Make sure stuff doesn't somehow remain in markTextQueue.
Expand Down

0 comments on commit 83297ef

Please sign in to comment.