Skip to content

Commit 3ce2cd3

Browse files
committed
Generalises Postprocessor.
1 parent f1a3bb9 commit 3ce2cd3

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

bin/mjsre.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const argv = require("yargs")
2525
.options({
2626
speech: {
2727
boolean: true,
28-
default: mj.options.speak,
28+
default: mj.options.speakText,
2929
describe: "include speech text"
3030
},
3131
sre: {
@@ -93,6 +93,14 @@ const argv = require("yargs")
9393
})
9494
.argv;
9595

96+
const formats = {
97+
'commonhtml': 'html',
98+
'mathml': 'mml',
99+
'chtml': 'html'
100+
};
101+
102+
argv.output = formats[argv.output] || argv.output;
103+
96104
if (argv.font === "STIX") argv.font = "STIX-Web";
97105
if (argv.format === "TeX") argv.format = (argv.inline ? "inline-TeX" : "TeX");
98106

@@ -109,14 +117,6 @@ const mjconf = {
109117
extensions: argv.extensions
110118
};
111119

112-
const outputFormats = {
113-
'commonhtml': 'html',
114-
'mathml': 'mml',
115-
'chtml': 'html'
116-
};
117-
118-
argv.output = outputFormats[argv.output] || argv.output;
119-
120120
const mjinput = {
121121
math: argv._[0],
122122
format: argv.format,

lib/main.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const sre = require('speech-rule-engine');
2222

2323

2424
const optionsDefault = {
25-
speak: true,
25+
speakText: true,
2626
speakRules: "mathspeak",
2727
speakStyle: "default",
2828
format: "TeX",
@@ -52,8 +52,7 @@ const sreconfig = function(data) {
5252
style: data.speakStyle || 'default',
5353
// TODO: What does that do?
5454
minSTree: data.minSTree,
55-
semantic: data.semantic,
56-
speakText: true
55+
semantic: data.semantic
5756
};
5857
if (data.sre) {
5958
for (let i = 0, key; key = data.sre[i]; i++) {
@@ -82,11 +81,12 @@ const main = function (data, callback) {
8281
data.mml = true;
8382

8483
mathjax.typeset(data, function (result, input) {
85-
postprocessor(speechConfig, result, input, callback);
84+
postprocessor(data, result, input, callback);
8685
})
8786
};
8887

89-
const postprocessor = function (speechConfig, result, input, callback) {
88+
const postprocessor = function (data, result, input, callback) {
89+
let speechConfig = sreconfig(data);
9090
if (result.error) throw result.error;
9191
if (!result.mml && !result.mmlNode) throw new Error('No MathML found. Please check the mathjax-node configuration');
9292
if (!result.svgNode && !result.htmlNode && !result.mmlNode) throw new Error('No suitable output found. Either svgNode, htmlNode or mmlNode are required.');
@@ -99,7 +99,7 @@ const postprocessor = function (speechConfig, result, input, callback) {
9999
result.streeXml = speechConfig.minSTree ? xml : sre.pprintXML(xml);
100100
}
101101
// return if no speakText is requested
102-
if (!speechConfig.speakText) {
102+
if (!data.speakText) {
103103
callback(result, input);
104104
return
105105
}

0 commit comments

Comments
 (0)