From 67e406c539381043ccf842481c391a8358e0dfd2 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Tue, 1 Aug 2017 12:37:13 +0200
Subject: [PATCH 1/6] [main] typeset: add promise-based API Resolves #297
---
lib/main.js | 15 ++++++++++++++-
test/base-typeset-promise.js | 22 ++++++++++++++++++++++
2 files changed, 36 insertions(+), 1 deletion(-)
create mode 100644 test/base-typeset-promise.js
diff --git a/lib/main.js b/lib/main.js
index 54955baf..41b19c6c 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -825,7 +825,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;
@@ -841,6 +843,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)
diff --git a/test/base-typeset-promise.js b/test/base-typeset-promise.js
new file mode 100644
index 00000000..ae67b2bd
--- /dev/null
+++ b/test/base-typeset-promise.js
@@ -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'));
+});
From 429e91aab05818c821ea47d65aa2fc4d2c7b0a5f Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Tue, 15 Aug 2017 16:56:33 +0200
Subject: [PATCH 2/6] [main] CommonHTML: add warning for unknown char Fixes
#350
---
lib/main.js | 4 ++++
test/base-warnings.js | 11 +++++++++++
2 files changed, 15 insertions(+)
create mode 100644 test/base-warnings.js
diff --git a/lib/main.js b/lib/main.js
index 41b19c6c..7f9f9a10 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -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]);
});
diff --git a/test/base-warnings.js b/test/base-warnings.js
new file mode 100644
index 00000000..cd61cd73
--- /dev/null
+++ b/test/base-warnings.js
@@ -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:'呵', html:true})
+ .catch(errors => t.ok(errors, 'CommonHTML output reports error'));
+ mjAPI.typeset({math:'呵', svg:true})
+ .catch(errors => t.ok(errors, 'SVG output reports error'));
+});
From e027c229c43885476c68305b8bd07b0c81ed5707 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Tue, 15 Aug 2017 17:20:51 +0200
Subject: [PATCH 3/6] [test] base-warnings: change unicode reference
---
test/base-warnings.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/test/base-warnings.js b/test/base-warnings.js
index cd61cd73..e4e7130a 100644
--- a/test/base-warnings.js
+++ b/test/base-warnings.js
@@ -4,8 +4,8 @@ mjAPI.config({undefinedCharError: true});
tape('basic test: check warnings', function (t) {
t.plan(2);
- mjAPI.typeset({math:'呵', html:true})
+ mjAPI.typeset({math:'\u5475', html:true})
.catch(errors => t.ok(errors, 'CommonHTML output reports error'));
- mjAPI.typeset({math:'呵', svg:true})
+ mjAPI.typeset({math:'\u5475', svg:true})
.catch(errors => t.ok(errors, 'SVG output reports error'));
});
From fc93f8850af9410e96e80ce490ff55c1725e3624 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Wed, 16 Aug 2017 15:59:53 +0200
Subject: [PATCH 4/6] [travis] update encrypted deploy key Fixes #349
---
.travis.yml | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index b87ea02c..6bf85d30 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -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: manager@mathjax.org
api_key:
- secure: Fd/yFRRrLDjleB7QnV/Juncg7dJP193IYOWZaJJFohSfPC3TylhJjUb2bD2fcBUbzM9bLPvhz+XJbWS2YXRGzCWABtyjpZTjO9oEkYBmEuNdVnD9b1j+BCWEEyXfBGF0/WBePRtn8XWQLTPbEJXP9Z2HKOUJJlq4cjTLZ7MHZLw=
+ secure: aJ/ZDGLods2x/Iss0bNgZ3xNHR7K8kkjEZ9jMAjTNxRlgC1oTbmjnPVVwybznUoIf8e13vpEyLHVNCZFWiE1rHwsguJCa1FoANKjpw51o/B811DZ65Nvj0qFuSi9UrHUwuVcnVCp2Qn2XEschCgT9yVWmiOmstq3557qg2iUJ1o=
on:
tags: true
From 3f811c787eddcf460e05ea3a77f14838f2bc094e Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Wed, 23 Aug 2017 08:50:36 +0200
Subject: [PATCH 5/6] [package.json] bump version
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 94de7ce7..1615b1af 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "mathjax-node",
- "version": "1.1.1",
+ "version": "1.2.0-beta.0",
"description": "API's for calling MathJax from node.js",
"keywords": [
"MathJax",
From 17016a62293cf55b229b68cbd73d689909ea79ff Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Wed, 23 Aug 2017 09:02:53 +0200
Subject: [PATCH 6/6] [package.json] bump version
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 1615b1af..2c0281d1 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "mathjax-node",
- "version": "1.2.0-beta.0",
+ "version": "1.2.0",
"description": "API's for calling MathJax from node.js",
"keywords": [
"MathJax",