on-codemerge
Version:
A WYSIWYG editor for on-codemerge is a user-friendly interface that allows users to edit and view their code in real time, exactly as it will appear in the final product
27 lines (26 loc) • 1.06 kB
JavaScript
import { m } from "../../../../_virtual/mathjax.mjs";
import { t as i } from "../../../../_virtual/tex.mjs";
import { s as g } from "../../../../_virtual/svg.mjs";
import { l as h } from "../../../../_virtual/liteAdaptor.mjs";
import { h as l } from "../../../../_virtual/html.mjs";
const o = h.liteAdaptor();
l.RegisterHTMLHandler(o);
const p = new i.TeX({ packages: ["base", "ams"] }), d = new g.SVG({ fontCache: "local" }), x = m.mathjax.document("", { InputJax: p, OutputJax: d });
class I {
async renderMath(a, e) {
const t = new Image();
try {
const r = x.convert(a, { display: !0 }), s = o.outerHTML(r).match(/<svg[^>]*>[\s\S]*<\/svg>/);
if (!s)
throw new Error("Invalid SVG structure");
const n = s[0], c = encodeURIComponent(n);
t.className = "svg-img", t.src = `data:image/svg+xml;charset=utf-8,${c}`, t.width = e.width, t.height = e.height;
} catch (r) {
console.error("MathJax rendering error:", r), t.alt = "Invalid math expression";
}
return t;
}
}
export {
I as MathRenderer
};