Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const postprocessor = function (speechConfig, result, input, callback) {
if (result.error) throw result.error;
if (!result.mml && !result.mmlNode) throw new Error('No MathML found. Please check the mathjax-node configuration');
if (!result.svgNode && !result.htmlNode && !result.mmlNode) throw new Error('No suitable output found. Either svgNode, htmlNode or mmlNode are required.');
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