Files
KaTeX/contrib/mathtex-script-type/mathtex-script-type.js
William J. Bowman 2fbb2b0128 Added MathJax compatibility script (#680)
* Added MathJax compatibility script

* Removed make integrity, which release.sh handles

* Renamed scripts

* Use katex.render (and options) instead of manually string munging

* Rewrote code based on feedback

* Renamed file correctly

* Extended README with an example of usage

* Removed CDN paths in place of an abstract path

* Revert "Removed CDN paths in place of an abstract path"

This reverts commit 857f8de2e449d9ac5a3d8eab5104dac561c533c4.

* Replace versions with `...`, with note to avoid confusing users

* Revert some `...` replacements to files that do exist.
2017-08-27 18:17:42 -04:00

25 lines
881 B
JavaScript

/* global katex */
{
let scripts = document.body.getElementsByTagName("script");
scripts = Array.prototype.slice.call(scripts);
scripts.forEach(function(script) {
if (!script.type || !script.type.match(/math\/tex/i)) {
return -1;
}
const display =
(script.type.match(/mode\s*=\s*display(;|\s|\n|$)/) != null);
const katexElement = document.createElement(display ? "div" : "span");
katexElement.setAttribute("class",
display ? "equation" : "inline-equation");
try {
katex.render(script.text, katexElement, {displayMode: display});
} catch (err) {
//console.error(err); linter doesn't like this
katexElement.textContent = script.text;
}
script.parentNode.replaceChild(katexElement, script);
});
}