Skip to content

Commit 8844326

Browse files
authoredApr 19, 2018
Merge branch 'develop' into 401
2 parents 35e2680 + 1dad5e5 commit 8844326

28 files changed

+410
-283
lines changed
 

‎lib/main.js

+19-6
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ var STATE = {
7474
STOPPED: 1, // no DOM or MathJax available
7575
STARTED: 2, // DOM loaded, MathJax starting up
7676
READY: 3, // MathJax initialized and ready to process math
77-
BUSY: 4 // MathJax currently processing math
77+
BUSY: 4, // MathJax currently processing math
78+
RESTART: 5, // start() called while MathJax is starting up
7879
};
7980

8081
//
@@ -519,11 +520,15 @@ function ConfigureMathJax() {
519520
MathJax.Hub.Register.StartupHook("End",function () {
520521
if (MathJax.OutputJax.SVG.resetGlyphs) MathJax.OutputJax.SVG.resetGlyphs(true);
521522
MathJax.ElementJax.mml.ID = 0;
522-
serverState = STATE.READY;
523-
MathJax.Hub.Queue(
523+
if (serverState === STATE.RESTART) {
524+
setTimeout(RestartMathJax, 100);
525+
} else {
526+
serverState = STATE.READY;
527+
MathJax.Hub.Queue(
524528
function () {sErrors = errors},
525529
StartQueue
526530
);
531+
}
527532
});
528533
}
529534
};
@@ -947,9 +952,17 @@ exports.typeset = function (data, callback) {
947952

948953
//
949954
// Manually start MathJax (this is done automatically
950-
// when the first typeset() call is made)
951-
//
952-
exports.start = function () {RestartMathJax()}
955+
// when the first typeset() call is made), but delay
956+
// restart if we are already starting up (prevents
957+
// multiple calls to start() from causing confusion).
958+
//
959+
exports.start = function () {
960+
if (serverState === STATE.STARTED) {
961+
serverState = STATE.RESTART;
962+
} else if (serverState !== STATE.ABORT) {
963+
RestartMathJax();
964+
}
965+
}
953966

954967
//
955968
// Configure MathJax and the API

‎test/base-config-fonturl.js

+28-14
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,41 @@ tape('basic configuration: check fontURL', function (t) {
66
t.plan(2);
77

88
var tex = 'a';
9+
910
mjAPI.typeset({
1011
math: tex,
1112
format: "TeX",
12-
css: true
13+
css: true,
14+
htmlNode: true
1315
}, function (result, data) {
14-
t.ok(result.css.indexOf('https://cdnjs.cloudflare.com/ajax/libs/mathjax/' + mjVersion + '/fonts/HTML-CSS') > -1, 'Default fontURL');
15-
});
16-
// reconfigure
17-
mjAPI.typeset({
18-
math: ''
19-
}, function () {
16+
var mjVersion = result.htmlNode.ownerDocument.defaultView.MathJax.version;
17+
var URL = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/' + mjVersion + '/fonts/HTML-CSS';
18+
t.ok(result.css.indexOf(URL) > -1, 'Default fontURL');
19+
20+
//
21+
// reconfigure
22+
//
2023
mjAPI.config({
2124
fontURL: 'https://example.com'
2225
});
2326
mjAPI.start();
24-
})
25-
mjAPI.typeset({
26-
math: tex,
27-
format: "TeX",
28-
css: true,
29-
}, function (result, data) {
30-
t.ok(result.css.indexOf('https://example.com') > -1, 'Configuring fontURL');
27+
28+
//
29+
// Next test
30+
//
31+
32+
mjAPI.typeset({
33+
math: 'a',
34+
format: "TeX",
35+
css: true,
36+
}, function (result, data) {
37+
t.ok(result.css.indexOf('https://example.com') > -1, 'Configuring fontURL');
38+
//
39+
// reconfigure
40+
//
41+
mjAPI.config({fontURL: ''});
42+
mjAPI.start();
43+
});
44+
3145
});
3246
});

‎test/base-mathjax.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ var tape = require('tape');
22
var mjAPI = require("../lib/main.js");
33

44
tape('basic test: check MathJax core', function(t) {
5-
t.plan(2);
5+
t.plan(2);
66

7-
var tex = '';
8-
mjAPI.start();
7+
var tex = '';
8+
9+
mjAPI.typeset({
10+
math: tex,
11+
format: "TeX",
12+
mml: true
13+
}, function(result,data) {
14+
t.ok(result.mml, 'MathJax core seems ok');
15+
t.ok(data.format, 'MathJax input preserved');
16+
});
917

10-
mjAPI.typeset({
11-
math: tex,
12-
format: "TeX",
13-
mml: true
14-
}, function(result,data) {
15-
t.ok(result.mml, 'MathJax core seems ok');
16-
t.ok(data.format, 'MathJax input preserved');
17-
});
1818
});

‎test/base-typeset-promise.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,33 @@ var mjAPI = require("../lib/main.js");
44
tape('basic test: check typeset promise API', function (t) {
55
t.plan(2);
66

7-
var tex = '';
87
mjAPI.config({displayErrors: false});
9-
mjAPI.start();
108

9+
var tex = '';
10+
11+
//
1112
// promise resolved
13+
//
1214
mjAPI.typeset({
1315
math: tex,
1416
format: "TeX",
1517
mml: true
1618
}).then((result) => t.ok(result.mml, 'Typset promise resolved on success'));
1719

20+
//
21+
// promise frejected
22+
//
1823
mjAPI.typeset({
1924
math: tex,
2025
format: "MathML",
2126
mml: true
2227
}).catch((error) => t.ok(error, 'Typeset promise rejected on error'));
28+
29+
//
30+
// reset configuration
31+
//
32+
mjAPI.typeset({math: '', format: 'TeX', mml: true}, () => {
33+
mjAPI.config({displayErrors: true});
34+
});
35+
2336
});

‎test/base-warnings.js

+10
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,19 @@ mjAPI.config({undefinedCharError: true});
44

55
tape('basic test: check warnings', function (t) {
66
t.plan(2);
7+
78
mjAPI.config({displayErrors: false});
9+
810
mjAPI.typeset({math:'\u5475', html:true})
911
.catch(errors => t.ok(errors, 'CommonHTML output reports error'));
1012
mjAPI.typeset({math:'\u5475', svg:true})
1113
.catch(errors => t.ok(errors, 'SVG output reports error'));
14+
15+
//
16+
// reset configuration
17+
//
18+
mjAPI.typeset({math: '', format: 'TeX', mml: true}, () => {
19+
mjAPI.config({displayErrors: true});
20+
});
21+
1222
});

‎test/config-third-party-extensions.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,28 @@ const path = require('path');
44

55
tape('Configuring third party extensions', function(t) {
66
t.plan(1);
7-
var tex = '\\test';
7+
88
mjAPI.config( {
99
extensions: '[test]/test.js',
1010
paths: {
1111
'test': path.join(__dirname,'assets/')
1212
}
1313
});
1414
mjAPI.start();
15+
16+
var tex = '\\test';
17+
1518
mjAPI.typeset({
1619
math: tex,
1720
format: "TeX",
1821
mmlNode: true
1922
}, function(data) {
2023
t.notOk(data.errors, 'No error loading the extension');
24+
//
25+
// reset configuration
26+
//
27+
mjAPI.config({extensions: '', paths: {}});
28+
mjAPI.start();
2129
});
30+
2231
});

‎test/css.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ var mjAPI = require("../lib/main.js");
33

44
tape('CSS output', function(t) {
55
t.plan(3);
6-
mjAPI.start();
7-
var tex = 'x';
6+
87
mjAPI.typeset({
98
math: tex,
109
format: "TeX",
1110
css: true
1211
}, function(data) {
1312
t.ok(data.css, 'css output while no other output');
1413
});
14+
15+
var tex = 'x';
16+
1517
mjAPI.typeset({
1618
math: tex,
1719
format: "TeX",
@@ -21,4 +23,5 @@ tape('CSS output', function(t) {
2123
t.ok(data.css, 'css output created alongside SVG output');
2224
t.ok(data.svg, 'svg output is created');
2325
});
26+
2427
});

‎test/issue104.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ var JSDOM = require('jsdom').JSDOM;
55
tape('the SVG width should match the default', function(t) {
66
t.plan(1);
77

8-
mjAPI.start();
98
var tex = 'a \\\\ b';
109
var expected = '100ex';
1110

@@ -20,4 +19,5 @@ tape('the SVG width should match the default', function(t) {
2019
var width = element.getAttribute('width');
2120
t.equal(width, expected);
2221
});
22+
2323
});

‎test/issue175.js

+26-22
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,31 @@ var mjAPI = require("../lib/main.js");
33
var JSDOM = require('jsdom').JSDOM;
44

55
tape('color extension should be reset', function(t) {
6-
t.plan(3);
7-
mjAPI.config({displayErrors: false});
8-
mjAPI.start();
9-
var tex = '\\colorbox{green}{x}';
10-
var tex2 = '\\color{red}{x}x';
6+
t.plan(3);
7+
8+
mjAPI.config({displayErrors: false});
9+
10+
var tex = '\\colorbox{green}{x}';
11+
var tex2 = '\\color{red}{x}x';
12+
13+
mjAPI.typeset({
14+
math: tex,
15+
format: "TeX",
16+
mml: true
17+
}, function(data) {
18+
t.ok(data.errors, 'Color extension disabled');
19+
});
20+
21+
mjAPI.typeset({
22+
math: tex2,
23+
format: "TeX",
24+
mml: true
25+
}, function(data) {
26+
var document = new JSDOM(data.mml).window.document;
27+
var mstyle = document.querySelector('mstyle');
28+
t.ok(document.querySelectorAll('mi')[0].parentNode === mstyle, 'Color macro behaves correctly (1 of 2)');
29+
t.notOk(document.querySelectorAll('mi')[1].parentNode === mstyle, 'Color macro behaves correctly (2 of 2)');
30+
mjAPI.config({displayErrors: true}); // reset configuration
31+
});
1132

12-
mjAPI.typeset({
13-
math: tex,
14-
format: "TeX",
15-
mml: true
16-
}, function(data) {
17-
t.ok(data.errors, 'Color extension disabled');
18-
});
19-
mjAPI.typeset({
20-
math: tex2,
21-
format: "TeX",
22-
mml: true
23-
}, function(data) {
24-
var document = new JSDOM(data.mml).window.document;
25-
var mstyle = document.querySelector('mstyle');
26-
t.ok(document.querySelectorAll('mi')[0].parentNode === mstyle, 'Color macro behaves correctly (1 of 2)');
27-
t.notOk(document.querySelectorAll('mi')[1].parentNode === mstyle, 'Color macro behaves correctly (2 of 2)');
28-
});
2933
});

0 commit comments

Comments
 (0)