mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-07 04:08:43 +00:00
* 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.
25 lines
881 B
JavaScript
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);
|
|
});
|
|
}
|