remark-docx
Version:
remark plugin to compile markdown to docx (Microsoft Word, Office Open XML).
48 lines (47 loc) • 1.36 kB
JavaScript
import { n as e } from "../../utils-BBifD5si.js";
import { browserSvgToPng as t } from "../image/index.js";
import { Paragraph as n } from "docx";
import { visit as r } from "unist-util-visit";
import i from "mermaid";
import { imageSize as a } from "image-size";
//#region src/plugins/mermaid/index.ts
var o = async (e) => {
let t = document.createElement("div");
t.style.visibility = "hidden", document.body.appendChild(t);
try {
return (await i.render("mermaid", e, t)).svg;
} finally {
document.body.removeChild(t);
}
}, s = () => {
let i = o;
return async ({ root: o, images: s }) => {
let c = [];
return r(o, "code", ({ lang: n, value: r }) => {
n === "mermaid" && (s.has(r) || (s.set(r, null), c.push((async () => {
try {
let e = await i(r), n = new TextEncoder().encode(e), { width: o, height: c } = a(n), l = await t({
buffer: n.buffer,
width: o,
height: c
});
s.set(r, {
type: "svg",
width: o,
height: c,
data: n.buffer,
fallback: l
});
} catch (t) {
e(String(t));
}
})())));
}), await Promise.all(c), { code: ({ lang: e, value: t }, r) => e !== "mermaid" || r.images.get(t) == null ? null : new n({ children: r.render([{
type: "image",
url: t
}]) }) };
};
};
//#endregion
export { s as mermaidPlugin };
//# sourceMappingURL=index.js.map