Skip to content

Commit

Permalink
Merge pull request #353 from mathjax/develop
Browse files Browse the repository at this point in the history
v1.2.0 release
  • Loading branch information
pkra authored Aug 23, 2017
2 parents 41eb7bf + 17016a6 commit fa4d045
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 10 deletions.
16 changes: 8 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
language: node_js
node_js:
- '4'
- '5'
- '6'
- '7'
- stable
- '4'
- '5'
- '6'
- '7'
- stable
sudo: false
script:
- npm install
- npm test
- npm install
- npm test
deploy:
provider: npm
email: [email protected]
api_key:
secure: Fd/yFRRrLDjleB7QnV/Juncg7dJP193IYOWZaJJFohSfPC3TylhJjUb2bD2fcBUbzM9bLPvhz+XJbWS2YXRGzCWABtyjpZTjO9oEkYBmEuNdVnD9b1j+BCWEEyXfBGF0/WBePRtn8XWQLTPbEJXP9Z2HKOUJJlq4cjTLZ7MHZLw=
secure: aJ/ZDGLods2x/Iss0bNgZ3xNHR7K8kkjEZ9jMAjTNxRlgC1oTbmjnPVVwybznUoIf8e13vpEyLHVNCZFWiE1rHwsguJCa1FoANKjpw51o/B811DZ65Nvj0qFuSi9UrHUwuVcnVCp2Qn2XEschCgT9yVWmiOmstq3557qg2iUJ1o=
on:
tags: true
19 changes: 18 additions & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ function ConfigureMathJax() {
AddError("SVG - Unknown character: U+"+message[1].toString(16).toUpperCase()+
" in "+(message[2].fonts||["unknown"]).join(","),!undefinedChar);
});
MathJax.Hub.Register.MessageHook("CommonHTML Jax - unknown char",function (message) {
AddError("CHTML - Unknown character: U+"+message[1].toString(16).toUpperCase()+
" in "+(message[2].fonts||["unknown"]).join(","),!undefinedChar);
});
MathJax.Hub.Register.MessageHook("MathML Jax - unknown node type",function (message) {
AddError("MathML - Unknown node type: "+message[1]);
});
Expand Down Expand Up @@ -825,7 +829,9 @@ function RestartMathJax() {
// %%% cache results?
// %%% check types and values of parameters
//
exports.typeset = function (data,callback) {

// callback API for compatibility with MathJax
var cbTypeset = function (data, callback) {
if (!callback || typeof(callback) !== "function") {
if (displayErrors) console.error("Missing callback");
return;
Expand All @@ -841,6 +847,17 @@ exports.typeset = function (data,callback) {
if (serverState == STATE.READY) StartQueue();
}

// main API, callback and promise compatible
exports.typeset = function (data, callback) {
if (callback) cbTypeset(data, callback);
else return new Promise(function (resolve, reject) {
cbTypeset(data, function (output, input) {
if (output.errors) reject(output.errors);
else resolve(output, input);
});
});
};

//
// Manually start MathJax (this is done automatically
// when the first typeset() call is made)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mathjax-node",
"version": "1.1.1",
"version": "1.2.0",
"description": "API's for calling MathJax from node.js",
"keywords": [
"MathJax",
Expand Down
22 changes: 22 additions & 0 deletions test/base-typeset-promise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var tape = require('tape');
var mjAPI = require("../lib/main.js");

tape('basic test: check typeset promise API', function (t) {
t.plan(2);

var tex = '';
mjAPI.start();

// promise resolved
mjAPI.typeset({
math: tex,
format: "TeX",
mml: true
}).then((result) => t.ok(result.mml, 'Typset promise resolved on success'));

mjAPI.typeset({
math: tex,
format: "MathML",
mml: true
}).catch((error) => t.ok(error, 'Typeset promise rejected on error'));
});
11 changes: 11 additions & 0 deletions test/base-warnings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var tape = require('tape');
var mjAPI = require("../lib/main.js");
mjAPI.config({undefinedCharError: true});

tape('basic test: check warnings', function (t) {
t.plan(2);
mjAPI.typeset({math:'\u5475', html:true})
.catch(errors => t.ok(errors, 'CommonHTML output reports error'));
mjAPI.typeset({math:'\u5475', svg:true})
.catch(errors => t.ok(errors, 'SVG output reports error'));
});

0 comments on commit fa4d045

Please sign in to comment.