remark-docx
Version:
remark plugin to compile markdown to docx (Microsoft Word, Office Open XML).
62 lines (61 loc) • 1.6 kB
JavaScript
import { n as e } from "../../utils-BBifD5si.js";
import { Paragraph as t, TextRun as n } from "docx";
import { createHighlighter as r } from "shiki";
import { visit as i } from "unist-util-visit";
//#region src/plugins/shiki/index.ts
var a = (e) => {
if (e.length === 4) {
let t = e[1], n = e[2], r = e[3];
return e[0] + t + t + n + n + r + r;
}
return e.length === 9 ? e.slice(0, 7) : e;
}, o = ({ theme: o }) => {
let s, c = /* @__PURE__ */ new Set(), l = /* @__PURE__ */ new Set();
return async ({ root: u }) => {
let d = [];
return i(u, "code", ({ lang: e }) => {
e && (c.has(e) || (c.add(e), d.push(e)));
}), s ||= await r({
themes: [o],
langs: []
}), await Promise.all(d.map(async (t) => {
try {
await s.loadLanguage(t);
} catch (n) {
l.add(t), e(String(n));
}
})), { code: ({ value: e, lang: r }) => {
if (!r || l.has(r)) return null;
let i = s.codeToTokens(e, {
lang: r,
theme: o
}), { bg: c, fg: u } = i;
return u &&= a(u), c &&= a(c), i.tokens.map((e) => new t({
shading: {
type: "clear",
color: "auto",
fill: c
},
children: e.map(({ content: e, bgColor: t, color: r, fontStyle: i }) => (r &&= a(r), t &&= a(t), new n({
text: e,
color: r ?? u,
shading: t ? {
type: "clear",
color: "auto",
fill: t
} : void 0,
bold: i === 2,
italics: i === 1,
underline: i === 4 ? {
type: "single",
color: u
} : void 0,
strike: i === 8
})))
}));
} };
};
};
//#endregion
export { o as shikiPlugin };
//# sourceMappingURL=index.js.map