mathpix-markdown-it
Version:
Mathpix-markdown-it is an open source implementation of the mathpix-markdown spec written in Typescript. It relies on the following open source libraries: MathJax v3 (to render math with SVGs), markdown-it (for standard Markdown parsing)
55 lines • 1.8 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.addAriaToMathHTML = exports.getSpeech = void 0;
/**
* TODO: Add a handler to reader output "softmax" as a word instead of "s o f t m a x"
* */
var getSpeech = function (sre, mml) {
try {
return sre.toSpeech(mml);
}
catch (err) {
console.error('ERROR=>[getSpeech]=>' + err);
return '';
}
};
exports.getSpeech = getSpeech;
var addAriaToMathHTML = function (sre, html) {
try {
var doc = new DOMParser().parseFromString(html, "text/html");
var mathEls = doc
? doc.querySelectorAll('mjx-container')
: null;
if (!mathEls || !mathEls.length) {
return html;
}
for (var i = 0; i < mathEls.length; i++) {
var elMath = mathEls[i];
var elMml = elMath
? elMath.querySelector('mjx-assistive-mml')
: null;
if (!elMml) {
continue;
}
var speech = (0, exports.getSpeech)(sre, elMml.innerHTML);
elMml.setAttribute('aria-hidden', "true");
if (!speech) {
continue;
}
elMath.setAttribute('aria-label', speech);
elMath.setAttribute('role', "math");
elMath.setAttribute('tabindex', '0');
var elSpeech = doc.createElement('speech');
elSpeech.innerHTML = speech;
elSpeech.style.display = "none";
elMath.parentElement.appendChild(elSpeech);
}
return doc.body.innerHTML;
}
catch (err) {
console.error('ERROR=>[addAriaToMathHTML]=>' + err);
return html;
}
};
exports.addAriaToMathHTML = addAriaToMathHTML;
//# sourceMappingURL=index.js.map