Skip to content

Commit fa4d045

Browse files
authored
Merge pull request #353 from mathjax/develop
v1.2.0 release
2 parents 41eb7bf + 17016a6 commit fa4d045

File tree

5 files changed

+60
-10
lines changed

5 files changed

+60
-10
lines changed

.travis.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
language: node_js
22
node_js:
3-
- '4'
4-
- '5'
5-
- '6'
6-
- '7'
7-
- stable
3+
- '4'
4+
- '5'
5+
- '6'
6+
- '7'
7+
- stable
88
sudo: false
99
script:
10-
- npm install
11-
- npm test
10+
- npm install
11+
- npm test
1212
deploy:
1313
provider: npm
1414
1515
api_key:
16-
secure: Fd/yFRRrLDjleB7QnV/Juncg7dJP193IYOWZaJJFohSfPC3TylhJjUb2bD2fcBUbzM9bLPvhz+XJbWS2YXRGzCWABtyjpZTjO9oEkYBmEuNdVnD9b1j+BCWEEyXfBGF0/WBePRtn8XWQLTPbEJXP9Z2HKOUJJlq4cjTLZ7MHZLw=
16+
secure: aJ/ZDGLods2x/Iss0bNgZ3xNHR7K8kkjEZ9jMAjTNxRlgC1oTbmjnPVVwybznUoIf8e13vpEyLHVNCZFWiE1rHwsguJCa1FoANKjpw51o/B811DZ65Nvj0qFuSi9UrHUwuVcnVCp2Qn2XEschCgT9yVWmiOmstq3557qg2iUJ1o=
1717
on:
1818
tags: true

lib/main.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ function ConfigureMathJax() {
195195
AddError("SVG - Unknown character: U+"+message[1].toString(16).toUpperCase()+
196196
" in "+(message[2].fonts||["unknown"]).join(","),!undefinedChar);
197197
});
198+
MathJax.Hub.Register.MessageHook("CommonHTML Jax - unknown char",function (message) {
199+
AddError("CHTML - Unknown character: U+"+message[1].toString(16).toUpperCase()+
200+
" in "+(message[2].fonts||["unknown"]).join(","),!undefinedChar);
201+
});
198202
MathJax.Hub.Register.MessageHook("MathML Jax - unknown node type",function (message) {
199203
AddError("MathML - Unknown node type: "+message[1]);
200204
});
@@ -825,7 +829,9 @@ function RestartMathJax() {
825829
// %%% cache results?
826830
// %%% check types and values of parameters
827831
//
828-
exports.typeset = function (data,callback) {
832+
833+
// callback API for compatibility with MathJax
834+
var cbTypeset = function (data, callback) {
829835
if (!callback || typeof(callback) !== "function") {
830836
if (displayErrors) console.error("Missing callback");
831837
return;
@@ -841,6 +847,17 @@ exports.typeset = function (data,callback) {
841847
if (serverState == STATE.READY) StartQueue();
842848
}
843849

850+
// main API, callback and promise compatible
851+
exports.typeset = function (data, callback) {
852+
if (callback) cbTypeset(data, callback);
853+
else return new Promise(function (resolve, reject) {
854+
cbTypeset(data, function (output, input) {
855+
if (output.errors) reject(output.errors);
856+
else resolve(output, input);
857+
});
858+
});
859+
};
860+
844861
//
845862
// Manually start MathJax (this is done automatically
846863
// when the first typeset() call is made)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mathjax-node",
3-
"version": "1.1.1",
3+
"version": "1.2.0",
44
"description": "API's for calling MathJax from node.js",
55
"keywords": [
66
"MathJax",

test/base-typeset-promise.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
var tape = require('tape');
2+
var mjAPI = require("../lib/main.js");
3+
4+
tape('basic test: check typeset promise API', function (t) {
5+
t.plan(2);
6+
7+
var tex = '';
8+
mjAPI.start();
9+
10+
// promise resolved
11+
mjAPI.typeset({
12+
math: tex,
13+
format: "TeX",
14+
mml: true
15+
}).then((result) => t.ok(result.mml, 'Typset promise resolved on success'));
16+
17+
mjAPI.typeset({
18+
math: tex,
19+
format: "MathML",
20+
mml: true
21+
}).catch((error) => t.ok(error, 'Typeset promise rejected on error'));
22+
});

test/base-warnings.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var tape = require('tape');
2+
var mjAPI = require("../lib/main.js");
3+
mjAPI.config({undefinedCharError: true});
4+
5+
tape('basic test: check warnings', function (t) {
6+
t.plan(2);
7+
mjAPI.typeset({math:'\u5475', html:true})
8+
.catch(errors => t.ok(errors, 'CommonHTML output reports error'));
9+
mjAPI.typeset({math:'\u5475', svg:true})
10+
.catch(errors => t.ok(errors, 'SVG output reports error'));
11+
});

0 commit comments

Comments
 (0)