Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!result.mml) result.mml = result.mmlNode.outerHTML;
if (!speechConfig.speech) speechConfig.speech = 'deep';
// add semantic tree
if (speechConfig.semantic) {
result.streeJson = sre.toJson(result.mml);
const xml = sre.toSemantic(result.mml).toString();
result.streeXml = speechConfig.minSTree ? xml : sre.pprintXML(xml);
}
// return if no speakText is requested
if (!speechConfig.speakText) {
callback(result, input);
return
}
// enrich output
sre.setupEngine(speechConfig);
result.speakText = sre.toSpeech(result.mml);
if (result.svgNode) {
result.svgNode.querySelector('title').innerHTML = result.speakText;
// update serialization
// HACK add lost xlink namespaces TODO file jsdom bug
if (result.svg) result.svg = result.svgNode.outerHTML
.replace(/><([^/])/g, ">\n<$1")
.replace(/(<\/[a-z]*>)(?=<\/)/g, "$1\n")
.replace(/(<(?:use|image) [^>]*)(href=)/g, ' $1xlink:$2');
}
if (result.htmlNode) {
result.htmlNode.firstChild.setAttribute("aria-label", result.speakText);
// update serialization
if (result.html) result.html = result.htmlNode.outerHTML;
}
if (result.mmlNode) {
result.mmlNode.setAttribute("alttext", result.speakText);
const preprocessor = function (data, callback) {
// setup SRE
const speechConfig = {
semantics: true,
domain: data.speakRuleset || 'mathspeak',
style: data.speakStyle || 'default',
semantic: data.semantic,
minSTree: data.minSTree,
speakText: true,
speech: 'deep'
};
if (data.speakText === false) speechConfig.speakText = false
sre.setupEngine(speechConfig);
// if MathML, enrich and continue
if (data.format === "MathML") {
data.speakText = sre.toSpeech(data.math);
data.math = sre.toEnriched(data.math).toString();
data.math = data.math.replace(/alttext="(.*?)"/,'alttext="' + data.speakText + '"');
callback(data);
} else {
// convert to MathML, enrich and continue
const newdata = {
math: data.math,
format: data.format,
mml: true
};
mathjax.typeset(newdata, function (result) {
if (result.error) throw result.error;
data.speakText = sre.toSpeech(result.mml);
data.math = sre.toEnriched(result.mml).toString();
data.math = data.math.replace(/alttext="(.*?)"/,'alttext="' + data.speakText + '"');
data.format = 'MathML';
mathjax.typeset(newdata, function (result) {
if (result.error) throw result.error;
data.speakText = sre.toSpeech(result.mml);
data.math = sre.toEnriched(result.mml).toString();
data.math = data.math.replace(/alttext="(.*?)"/,'alttext="' + data.speakText + '"');
data.format = 'MathML';
callback(data);
});
}