From c05f865f8b1ae5ad1ea889af32615d246b7cc8bf Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Tue, 2 May 2017 22:16:06 +0200
Subject: [PATCH 1/2] [main] pass input data to output Resolves #303
---
lib/main.js | 10 +++++-----
test/pass_data.js | 16 ++++++++++++++++
2 files changed, 21 insertions(+), 5 deletions(-)
create mode 100644 test/pass_data.js
diff --git a/lib/main.js b/lib/main.js
index 55b1c51f..75db34df 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -85,7 +85,7 @@ var timer; // used to reset MathJax if it runs too lon
var document, window, content, html; // the DOM elements
var queue = []; // queue of typesetting requests of the form [data,callback]
-var data, callback; // the current queue item
+var data, callback, originalData; // the current queue item
var errors = []; // errors collected durring the typesetting
var ID = 0; // id for this SVG element
@@ -648,7 +648,7 @@ function GetSVG(result) {
// Start typesetting the queued expressions
//
function StartQueue() {
- data = callback = null; // clear existing equation, if any
+ data = callback = originalData = null; // clear existing equation, if any
errors = []; // clear any errors
if (!queue.length) return; // return if nothing to do
@@ -660,7 +660,7 @@ function StartQueue() {
// and set the content with the proper script type
//
var item = queue.shift();
- data = item[0]; callback = item[1];
+ data = item[0]; callback = item[1]; originalData = item[2];
content.innerHTML = "";
MathJax.HTML.addElement(content,"script",{type: "math/"+TYPES[data.format]},[data.math]);
html.setAttribute("xmlns:"+data.xmlns,"http://www.w3.org/1998/Math/MathML");
@@ -775,7 +775,7 @@ function ReturnResult(result) {
state.ID = ID;
}
serverState = STATE.READY;
- callback(result, data);
+ callback(result, originalData);
if (serverState === STATE.READY) StartQueue();
}
@@ -836,7 +836,7 @@ exports.typeset = function (data,callback) {
}}
if (data.state) {options.state = data.state}
if (!TYPES[options.format]) {ReportError("Unknown format: "+options.format,callback); return}
- queue.push([options,callback]);
+ queue.push([options,callback,Object.assign({},data)]);
if (serverState == STATE.STOPPED) {RestartMathJax()}
if (serverState == STATE.READY) StartQueue();
}
diff --git a/test/pass_data.js b/test/pass_data.js
new file mode 100644
index 00000000..d30b1808
--- /dev/null
+++ b/test/pass_data.js
@@ -0,0 +1,16 @@
+var tape = require('tape');
+var mjAPI = require("../lib/main.js");
+
+tape('Passing data along', function(t) {
+ t.plan(1);
+ mjAPI.start();
+ var tex = 'x';
+ mjAPI.typeset({
+ math: tex,
+ format: "TeX",
+ css: true,
+ something: 'expected',
+ }, function(data, input) {
+ t.equal(input.something, 'expected', 'Data was passed along to output');
+ });
+});
From f51563f78bcd5f27f73579ff04533ead6dfa4d35 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Thu, 4 May 2017 08:25:11 +0200
Subject: [PATCH 2/2] [package.json] bump version
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 0a9769f6..8283b2ce 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "mathjax-node",
- "version": "1.0.3",
+ "version": "1.1.0",
"description": "API's for calling MathJax from node.js",
"keywords": [
"MathJax",