remark-docx
Version:
remark plugin to compile markdown to docx (Microsoft Word, Office Open XML).
75 lines (74 loc) • 2.56 kB
JavaScript
import { Paragraph as e, XmlAttributeComponent as t, XmlComponent as n } from "docx";
import { mml2omml as r } from "mathml2omml";
import { XMLParser as i } from "fast-xml-parser";
import { mathjax as a } from "@mathjax/src/js/mathjax.js";
import { TeX as o } from "@mathjax/src/js/input/tex.js";
import { SerializedMmlVisitor as s } from "@mathjax/src/js/core/MmlTree/SerializedMmlVisitor.js";
import { STATE as c } from "@mathjax/src/js/core/MathItem.js";
import { liteAdaptor as l } from "@mathjax/src/js/adaptors/liteAdaptor.js";
import { RegisterHTMLHandler as u } from "@mathjax/src/js/handlers/html.js";
import { Loader as d } from "@mathjax/src/js/components/loader.js";
import "@mathjax/src/components/js/input/tex/extensions/noerrors/noerrors.js";
import "@mathjax/src/components/js/input/tex/extensions/ams/ams.js";
import "@mathjax/src/components/js/input/tex/extensions/boldsymbol/boldsymbol.js";
import "@mathjax/src/components/js/input/tex/extensions/newcommand/newcommand.js";
import "@mathjax/src/components/js/input/tex/extensions/textmacros/textmacros.js";
import "@mathjax/src/components/js/input/tex/extensions/unicode/unicode.js";
//#region src/plugins/latex/index.ts
var f = class extends t {}, p = class extends n {
constructor(e, t, n) {
if (super(e), n) {
let e = {};
for (let [t, r] of Object.entries(n)) t.startsWith("m:") && (e[t] = r);
this.root.push(new f(e));
}
t.length && this.root.push(...t);
}
}, m = (e) => "#text" in e, h = (e) => {
let t = e[":@"], n = "", r;
for (let t of Object.keys(e)) if (t !== ":@") {
n = t, r = e[t];
break;
}
if (n.startsWith("m:")) {
let e = [];
for (let t of r ?? []) if (m(t)) {
let n = t["#text"];
e.push(String(n));
} else {
let n = h(t);
n && e.push(n);
}
return new p(n, e, t);
}
return null;
}, g = () => {
u(l());
let t = [
"[tex]/noerrors",
"[tex]/ams",
"[tex]/newcommand",
"[tex]/boldsymbol",
"[tex]/textmacros",
"[tex]/unicode"
], n = ["base"].concat(t.map((e) => e.slice(6)));
d.preLoaded(...t);
let f = new o({ packages: n }), p = a.document("", { InputJax: f }), m = new s(), g = new i({
ignoreAttributes: !1,
preserveOrder: !0,
attributeNamePrefix: ""
}), _ = (e) => {
let t = p.convert(e, { end: c.CONVERT }), n = r(m.visitTree(t));
return h(g.parse(n)[0]);
};
return async () => ({
math: ({ value: t }) => {
let n = _(t);
return n ? new e({ children: [n] }) : null;
},
inlineMath: ({ value: e }) => _(e)
});
};
//#endregion
export { g as latexPlugin };
//# sourceMappingURL=index.js.map