remark-docx 0.3.28 → 0.3.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/chunk-CMqjfN_6.cjs +1 -0
- package/lib/index.cjs +2 -600
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.ts +3 -3
- package/lib/index.js +468 -596
- package/lib/index.js.map +1 -1
- package/lib/mdast-util-to-docx.d.ts +2 -2
- package/lib/plugin.d.ts +3 -3
- package/lib/plugins/html/index.cjs +2 -28
- package/lib/plugins/html/index.cjs.map +1 -1
- package/lib/plugins/html/index.d.ts +1 -1
- package/lib/plugins/html/index.js +10 -25
- package/lib/plugins/html/index.js.map +1 -1
- package/lib/plugins/image/index.cjs +2 -129
- package/lib/plugins/image/index.cjs.map +1 -1
- package/lib/plugins/image/index.d.ts +1 -1
- package/lib/plugins/image/index.js +87 -124
- package/lib/plugins/image/index.js.map +1 -1
- package/lib/plugins/latex/index.cjs +2 -123
- package/lib/plugins/latex/index.cjs.map +1 -1
- package/lib/plugins/latex/index.d.ts +1 -7
- package/lib/plugins/latex/index.js +73 -119
- package/lib/plugins/latex/index.js.map +1 -1
- package/lib/plugins/mermaid/index.cjs +2 -77
- package/lib/plugins/mermaid/index.cjs.map +1 -1
- package/lib/plugins/mermaid/index.d.ts +1 -1
- package/lib/plugins/mermaid/index.js +46 -73
- package/lib/plugins/mermaid/index.js.map +1 -1
- package/lib/plugins/shiki/index.cjs +2 -113
- package/lib/plugins/shiki/index.cjs.map +1 -1
- package/lib/plugins/shiki/index.d.ts +2 -2
- package/lib/plugins/shiki/index.js +60 -109
- package/lib/plugins/shiki/index.js.map +1 -1
- package/lib/types.d.ts +3 -3
- package/lib/utils-BBifD5si.js +16 -0
- package/lib/utils-BBifD5si.js.map +1 -0
- package/lib/utils-D_YAYv4R.cjs +2 -0
- package/lib/utils-D_YAYv4R.cjs.map +1 -0
- package/package.json +5 -6
- package/lib/utils-BVB8aSvE.js +0 -25
- package/lib/utils-BVB8aSvE.js.map +0 -1
- package/lib/utils-KFMY7wxz.js +0 -22
- package/lib/utils-KFMY7wxz.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../../src/plugins/shiki/index.ts"],"sourcesContent":["import { Paragraph, TextRun } from \"docx\";\nimport type { RemarkDocxPlugin } from \"../../types\";\nimport {\n createHighlighter,\n type BundledLanguage,\n type BundledTheme,\n} from \"shiki\";\nimport { visit } from \"unist-util-visit\";\nimport type { FontStyle } from \"shiki/textmate\";\nimport { warnOnce } from \"../../utils\";\n\n/**\n * Format to 6 disit hex\n */\nconst formatHex = (str: string): string => {\n // #RGB\n if (str.length === 4) {\n const r = str[1]!;\n const g = str[2]!;\n const b = str[3]!;\n return str[0]! + r + r + g + g + b + b;\n }\n // #RRGGBBAA\n if (str.length === 9) {\n return str.slice(0, 7);\n }\n return str;\n};\n\nexport interface ShikiPluginOptions {\n /**\n * https://shiki.style/themes\n */\n theme: BundledTheme;\n}\n\n/**\n * A plugin to render \"code\" nodes, with syntax highlighting powered by shiki.\n */\nexport const shikiPlugin = ({\n theme,\n}: ShikiPluginOptions): RemarkDocxPlugin => {\n let highlighter: Awaited<ReturnType<typeof createHighlighter>> | undefined;\n const langs = new Set<string>();\n const failedLangs = new Set<string>();\n\n return async ({ root }) => {\n const newLangs: string[] = [];\n\n visit(root, \"code\", ({ lang }) => {\n if (lang) {\n if (!langs.has(lang)) {\n langs.add(lang);\n newLangs.push(lang);\n }\n }\n });\n\n if (!highlighter) {\n highlighter = await createHighlighter({\n themes: [theme],\n langs: [],\n });\n }\n await Promise.all(\n newLangs.map(async (l) => {\n try {\n await highlighter!.loadLanguage(l as BundledLanguage);\n } catch (e) {\n failedLangs.add(l);\n warnOnce(String(e));\n }\n }),\n );\n\n return {\n code: ({ value, lang }) => {\n if (!lang || failedLangs.has(lang)) {\n return null;\n }\n const res = highlighter!.codeToTokens(value, {\n lang: lang as BundledLanguage,\n theme,\n });\n let { bg, fg } = res;\n if (fg) {\n fg = formatHex(fg);\n }\n if (bg) {\n bg = formatHex(bg);\n }\n\n return res.tokens.map((r) => {\n return new Paragraph({\n shading: {\n type: \"clear\",\n color: \"auto\",\n fill: bg,\n },\n children: r.map(({ content, bgColor, color, fontStyle }) => {\n if (color) {\n color = formatHex(color);\n }\n if (bgColor) {\n bgColor = formatHex(bgColor);\n }\n return new TextRun({\n text: content,\n color: color ?? fg,\n shading: bgColor\n ? {\n type: \"clear\",\n color: \"auto\",\n fill: bgColor,\n }\n : undefined,\n bold: fontStyle === (2 satisfies FontStyle.Bold),\n italics: fontStyle === (1 satisfies FontStyle.Italic),\n underline:\n fontStyle === (4 satisfies FontStyle.Underline)\n ? { type: \"single\", color: fg }\n : undefined,\n strike: fontStyle === (8 satisfies FontStyle.Strikethrough),\n });\n }),\n });\n });\n },\n };\n };\n};\n"],"
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../../../src/plugins/shiki/index.ts"],"sourcesContent":["import { Paragraph, TextRun } from \"docx\";\nimport type { RemarkDocxPlugin } from \"../../types\";\nimport {\n createHighlighter,\n type BundledLanguage,\n type BundledTheme,\n} from \"shiki\";\nimport { visit } from \"unist-util-visit\";\nimport type { FontStyle } from \"shiki/textmate\";\nimport { warnOnce } from \"../../utils\";\n\n/**\n * Format to 6 disit hex\n */\nconst formatHex = (str: string): string => {\n // #RGB\n if (str.length === 4) {\n const r = str[1]!;\n const g = str[2]!;\n const b = str[3]!;\n return str[0]! + r + r + g + g + b + b;\n }\n // #RRGGBBAA\n if (str.length === 9) {\n return str.slice(0, 7);\n }\n return str;\n};\n\nexport interface ShikiPluginOptions {\n /**\n * https://shiki.style/themes\n */\n theme: BundledTheme;\n}\n\n/**\n * A plugin to render \"code\" nodes, with syntax highlighting powered by shiki.\n */\nexport const shikiPlugin = ({\n theme,\n}: ShikiPluginOptions): RemarkDocxPlugin => {\n let highlighter: Awaited<ReturnType<typeof createHighlighter>> | undefined;\n const langs = new Set<string>();\n const failedLangs = new Set<string>();\n\n return async ({ root }) => {\n const newLangs: string[] = [];\n\n visit(root, \"code\", ({ lang }) => {\n if (lang) {\n if (!langs.has(lang)) {\n langs.add(lang);\n newLangs.push(lang);\n }\n }\n });\n\n if (!highlighter) {\n highlighter = await createHighlighter({\n themes: [theme],\n langs: [],\n });\n }\n await Promise.all(\n newLangs.map(async (l) => {\n try {\n await highlighter!.loadLanguage(l as BundledLanguage);\n } catch (e) {\n failedLangs.add(l);\n warnOnce(String(e));\n }\n }),\n );\n\n return {\n code: ({ value, lang }) => {\n if (!lang || failedLangs.has(lang)) {\n return null;\n }\n const res = highlighter!.codeToTokens(value, {\n lang: lang as BundledLanguage,\n theme,\n });\n let { bg, fg } = res;\n if (fg) {\n fg = formatHex(fg);\n }\n if (bg) {\n bg = formatHex(bg);\n }\n\n return res.tokens.map((r) => {\n return new Paragraph({\n shading: {\n type: \"clear\",\n color: \"auto\",\n fill: bg,\n },\n children: r.map(({ content, bgColor, color, fontStyle }) => {\n if (color) {\n color = formatHex(color);\n }\n if (bgColor) {\n bgColor = formatHex(bgColor);\n }\n return new TextRun({\n text: content,\n color: color ?? fg,\n shading: bgColor\n ? {\n type: \"clear\",\n color: \"auto\",\n fill: bgColor,\n }\n : undefined,\n bold: fontStyle === (2 satisfies FontStyle.Bold),\n italics: fontStyle === (1 satisfies FontStyle.Italic),\n underline:\n fontStyle === (4 satisfies FontStyle.Underline)\n ? { type: \"single\", color: fg }\n : undefined,\n strike: fontStyle === (8 satisfies FontStyle.Strikethrough),\n });\n }),\n });\n });\n },\n };\n };\n};\n"],"mappings":"sLAcA,IAAM,EAAa,GAAwB,CAEzC,GAAI,EAAI,SAAW,EAAG,CACpB,IAAM,EAAI,EAAI,GACR,EAAI,EAAI,GACR,EAAI,EAAI,GACd,OAAO,EAAI,GAAM,EAAI,EAAI,EAAI,EAAI,EAAI,CACvC,CAKA,OAHI,EAAI,SAAW,EACV,EAAI,MAAM,EAAG,CAAC,EAEhB,CACT,EAYa,GAAe,CAC1B,WAC0C,CAC1C,IAAI,EACE,EAAQ,IAAI,IACZ,EAAc,IAAI,IAExB,OAAO,MAAO,CAAE,UAAW,CACzB,IAAM,EAAqB,CAAC,EA4B5B,OA1BA,EAAA,EAAA,OAAM,EAAM,QAAS,CAAE,UAAW,CAC5B,IACG,EAAM,IAAI,CAAI,IACjB,EAAM,IAAI,CAAI,EACd,EAAS,KAAK,CAAI,GAGxB,CAAC,EAED,AACE,IAAc,MAAA,EAAA,EAAA,mBAAwB,CACpC,OAAQ,CAAC,CAAK,EACd,MAAO,CAAC,CACV,CAAC,EAEH,MAAM,QAAQ,IACZ,EAAS,IAAI,KAAO,IAAM,CACxB,GAAI,CACF,MAAM,EAAa,aAAa,CAAoB,CACtD,OAAS,EAAG,CACV,EAAY,IAAI,CAAC,EACjB,EAAA,EAAS,OAAO,CAAC,CAAC,CACpB,CACF,CAAC,CACH,EAEO,CACL,MAAO,CAAE,QAAO,UAAW,CACzB,GAAI,CAAC,GAAQ,EAAY,IAAI,CAAI,EAC/B,OAAO,KAET,IAAM,EAAM,EAAa,aAAa,EAAO,CACrC,OACN,OACF,CAAC,EACG,CAAE,KAAI,MAAO,EAQjB,MAPA,CACE,IAAK,EAAU,CAAE,EAEnB,AACE,IAAK,EAAU,CAAE,EAGZ,EAAI,OAAO,IAAK,GACd,IAAI,EAAA,UAAU,CACnB,QAAS,CACP,KAAM,QACN,MAAO,OACP,KAAM,CACR,EACA,SAAU,EAAE,KAAK,CAAE,UAAS,UAAS,QAAO,gBAC1C,AACE,IAAQ,EAAU,CAAK,EAEzB,AACE,IAAU,EAAU,CAAO,EAEtB,IAAI,EAAA,QAAQ,CACjB,KAAM,EACN,MAAO,GAAS,EAChB,QAAS,EACL,CACE,KAAM,QACN,MAAO,OACP,KAAM,CACR,EACA,IAAA,GACJ,KAAM,IAAe,EACrB,QAAS,IAAe,EACxB,UACE,IAAe,EACX,CAAE,KAAM,SAAU,MAAO,CAAG,EAC5B,IAAA,GACN,OAAQ,IAAe,CACzB,CAAC,EACF,CACH,CAAC,CACF,CACH,CACF,CACF,CACF"}
|
|
@@ -1,111 +1,62 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
const res = highlighter.codeToTokens(value, {
|
|
61
|
-
lang: lang,
|
|
62
|
-
theme,
|
|
63
|
-
});
|
|
64
|
-
let { bg, fg } = res;
|
|
65
|
-
if (fg) {
|
|
66
|
-
fg = formatHex(fg);
|
|
67
|
-
}
|
|
68
|
-
if (bg) {
|
|
69
|
-
bg = formatHex(bg);
|
|
70
|
-
}
|
|
71
|
-
return res.tokens.map((r) => {
|
|
72
|
-
return new Paragraph({
|
|
73
|
-
shading: {
|
|
74
|
-
type: "clear",
|
|
75
|
-
color: "auto",
|
|
76
|
-
fill: bg,
|
|
77
|
-
},
|
|
78
|
-
children: r.map(({ content, bgColor, color, fontStyle }) => {
|
|
79
|
-
if (color) {
|
|
80
|
-
color = formatHex(color);
|
|
81
|
-
}
|
|
82
|
-
if (bgColor) {
|
|
83
|
-
bgColor = formatHex(bgColor);
|
|
84
|
-
}
|
|
85
|
-
return new TextRun({
|
|
86
|
-
text: content,
|
|
87
|
-
color: color !== null && color !== void 0 ? color : fg,
|
|
88
|
-
shading: bgColor
|
|
89
|
-
? {
|
|
90
|
-
type: "clear",
|
|
91
|
-
color: "auto",
|
|
92
|
-
fill: bgColor,
|
|
93
|
-
}
|
|
94
|
-
: undefined,
|
|
95
|
-
bold: fontStyle === 2,
|
|
96
|
-
italics: fontStyle === 1,
|
|
97
|
-
underline: fontStyle === 4
|
|
98
|
-
? { type: "single", color: fg }
|
|
99
|
-
: undefined,
|
|
100
|
-
strike: fontStyle === 8,
|
|
101
|
-
});
|
|
102
|
-
}),
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
},
|
|
106
|
-
};
|
|
107
|
-
};
|
|
1
|
+
import { n as e } from "../../utils-BBifD5si.js";
|
|
2
|
+
import { Paragraph as t, TextRun as n } from "docx";
|
|
3
|
+
import { createHighlighter as r } from "shiki";
|
|
4
|
+
import { visit as i } from "unist-util-visit";
|
|
5
|
+
//#region src/plugins/shiki/index.ts
|
|
6
|
+
var a = (e) => {
|
|
7
|
+
if (e.length === 4) {
|
|
8
|
+
let t = e[1], n = e[2], r = e[3];
|
|
9
|
+
return e[0] + t + t + n + n + r + r;
|
|
10
|
+
}
|
|
11
|
+
return e.length === 9 ? e.slice(0, 7) : e;
|
|
12
|
+
}, o = ({ theme: o }) => {
|
|
13
|
+
let s, c = /* @__PURE__ */ new Set(), l = /* @__PURE__ */ new Set();
|
|
14
|
+
return async ({ root: u }) => {
|
|
15
|
+
let d = [];
|
|
16
|
+
return i(u, "code", ({ lang: e }) => {
|
|
17
|
+
e && (c.has(e) || (c.add(e), d.push(e)));
|
|
18
|
+
}), s ||= await r({
|
|
19
|
+
themes: [o],
|
|
20
|
+
langs: []
|
|
21
|
+
}), await Promise.all(d.map(async (t) => {
|
|
22
|
+
try {
|
|
23
|
+
await s.loadLanguage(t);
|
|
24
|
+
} catch (n) {
|
|
25
|
+
l.add(t), e(String(n));
|
|
26
|
+
}
|
|
27
|
+
})), { code: ({ value: e, lang: r }) => {
|
|
28
|
+
if (!r || l.has(r)) return null;
|
|
29
|
+
let i = s.codeToTokens(e, {
|
|
30
|
+
lang: r,
|
|
31
|
+
theme: o
|
|
32
|
+
}), { bg: c, fg: u } = i;
|
|
33
|
+
return u &&= a(u), c &&= a(c), i.tokens.map((e) => new t({
|
|
34
|
+
shading: {
|
|
35
|
+
type: "clear",
|
|
36
|
+
color: "auto",
|
|
37
|
+
fill: c
|
|
38
|
+
},
|
|
39
|
+
children: e.map(({ content: e, bgColor: t, color: r, fontStyle: i }) => (r &&= a(r), t &&= a(t), new n({
|
|
40
|
+
text: e,
|
|
41
|
+
color: r ?? u,
|
|
42
|
+
shading: t ? {
|
|
43
|
+
type: "clear",
|
|
44
|
+
color: "auto",
|
|
45
|
+
fill: t
|
|
46
|
+
} : void 0,
|
|
47
|
+
bold: i === 2,
|
|
48
|
+
italics: i === 1,
|
|
49
|
+
underline: i === 4 ? {
|
|
50
|
+
type: "single",
|
|
51
|
+
color: u
|
|
52
|
+
} : void 0,
|
|
53
|
+
strike: i === 8
|
|
54
|
+
})))
|
|
55
|
+
}));
|
|
56
|
+
} };
|
|
57
|
+
};
|
|
108
58
|
};
|
|
59
|
+
//#endregion
|
|
60
|
+
export { o as shikiPlugin };
|
|
109
61
|
|
|
110
|
-
|
|
111
|
-
//# sourceMappingURL=index.js.map
|
|
62
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/plugins/shiki/index.ts"],"sourcesContent":["import { Paragraph, TextRun } from \"docx\";\nimport type { RemarkDocxPlugin } from \"../../types\";\nimport {\n createHighlighter,\n type BundledLanguage,\n type BundledTheme,\n} from \"shiki\";\nimport { visit } from \"unist-util-visit\";\nimport type { FontStyle } from \"shiki/textmate\";\nimport { warnOnce } from \"../../utils\";\n\n/**\n * Format to 6 disit hex\n */\nconst formatHex = (str: string): string => {\n // #RGB\n if (str.length === 4) {\n const r = str[1]!;\n const g = str[2]!;\n const b = str[3]!;\n return str[0]! + r + r + g + g + b + b;\n }\n // #RRGGBBAA\n if (str.length === 9) {\n return str.slice(0, 7);\n }\n return str;\n};\n\nexport interface ShikiPluginOptions {\n /**\n * https://shiki.style/themes\n */\n theme: BundledTheme;\n}\n\n/**\n * A plugin to render \"code\" nodes, with syntax highlighting powered by shiki.\n */\nexport const shikiPlugin = ({\n theme,\n}: ShikiPluginOptions): RemarkDocxPlugin => {\n let highlighter: Awaited<ReturnType<typeof createHighlighter>> | undefined;\n const langs = new Set<string>();\n const failedLangs = new Set<string>();\n\n return async ({ root }) => {\n const newLangs: string[] = [];\n\n visit(root, \"code\", ({ lang }) => {\n if (lang) {\n if (!langs.has(lang)) {\n langs.add(lang);\n newLangs.push(lang);\n }\n }\n });\n\n if (!highlighter) {\n highlighter = await createHighlighter({\n themes: [theme],\n langs: [],\n });\n }\n await Promise.all(\n newLangs.map(async (l) => {\n try {\n await highlighter!.loadLanguage(l as BundledLanguage);\n } catch (e) {\n failedLangs.add(l);\n warnOnce(String(e));\n }\n }),\n );\n\n return {\n code: ({ value, lang }) => {\n if (!lang || failedLangs.has(lang)) {\n return null;\n }\n const res = highlighter!.codeToTokens(value, {\n lang: lang as BundledLanguage,\n theme,\n });\n let { bg, fg } = res;\n if (fg) {\n fg = formatHex(fg);\n }\n if (bg) {\n bg = formatHex(bg);\n }\n\n return res.tokens.map((r) => {\n return new Paragraph({\n shading: {\n type: \"clear\",\n color: \"auto\",\n fill: bg,\n },\n children: r.map(({ content, bgColor, color, fontStyle }) => {\n if (color) {\n color = formatHex(color);\n }\n if (bgColor) {\n bgColor = formatHex(bgColor);\n }\n return new TextRun({\n text: content,\n color: color ?? fg,\n shading: bgColor\n ? {\n type: \"clear\",\n color: \"auto\",\n fill: bgColor,\n }\n : undefined,\n bold: fontStyle === (2 satisfies FontStyle.Bold),\n italics: fontStyle === (1 satisfies FontStyle.Italic),\n underline:\n fontStyle === (4 satisfies FontStyle.Underline)\n ? { type: \"single\", color: fg }\n : undefined,\n strike: fontStyle === (8 satisfies FontStyle.Strikethrough),\n });\n }),\n });\n });\n },\n };\n };\n};\n"],"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/plugins/shiki/index.ts"],"sourcesContent":["import { Paragraph, TextRun } from \"docx\";\nimport type { RemarkDocxPlugin } from \"../../types\";\nimport {\n createHighlighter,\n type BundledLanguage,\n type BundledTheme,\n} from \"shiki\";\nimport { visit } from \"unist-util-visit\";\nimport type { FontStyle } from \"shiki/textmate\";\nimport { warnOnce } from \"../../utils\";\n\n/**\n * Format to 6 disit hex\n */\nconst formatHex = (str: string): string => {\n // #RGB\n if (str.length === 4) {\n const r = str[1]!;\n const g = str[2]!;\n const b = str[3]!;\n return str[0]! + r + r + g + g + b + b;\n }\n // #RRGGBBAA\n if (str.length === 9) {\n return str.slice(0, 7);\n }\n return str;\n};\n\nexport interface ShikiPluginOptions {\n /**\n * https://shiki.style/themes\n */\n theme: BundledTheme;\n}\n\n/**\n * A plugin to render \"code\" nodes, with syntax highlighting powered by shiki.\n */\nexport const shikiPlugin = ({\n theme,\n}: ShikiPluginOptions): RemarkDocxPlugin => {\n let highlighter: Awaited<ReturnType<typeof createHighlighter>> | undefined;\n const langs = new Set<string>();\n const failedLangs = new Set<string>();\n\n return async ({ root }) => {\n const newLangs: string[] = [];\n\n visit(root, \"code\", ({ lang }) => {\n if (lang) {\n if (!langs.has(lang)) {\n langs.add(lang);\n newLangs.push(lang);\n }\n }\n });\n\n if (!highlighter) {\n highlighter = await createHighlighter({\n themes: [theme],\n langs: [],\n });\n }\n await Promise.all(\n newLangs.map(async (l) => {\n try {\n await highlighter!.loadLanguage(l as BundledLanguage);\n } catch (e) {\n failedLangs.add(l);\n warnOnce(String(e));\n }\n }),\n );\n\n return {\n code: ({ value, lang }) => {\n if (!lang || failedLangs.has(lang)) {\n return null;\n }\n const res = highlighter!.codeToTokens(value, {\n lang: lang as BundledLanguage,\n theme,\n });\n let { bg, fg } = res;\n if (fg) {\n fg = formatHex(fg);\n }\n if (bg) {\n bg = formatHex(bg);\n }\n\n return res.tokens.map((r) => {\n return new Paragraph({\n shading: {\n type: \"clear\",\n color: \"auto\",\n fill: bg,\n },\n children: r.map(({ content, bgColor, color, fontStyle }) => {\n if (color) {\n color = formatHex(color);\n }\n if (bgColor) {\n bgColor = formatHex(bgColor);\n }\n return new TextRun({\n text: content,\n color: color ?? fg,\n shading: bgColor\n ? {\n type: \"clear\",\n color: \"auto\",\n fill: bgColor,\n }\n : undefined,\n bold: fontStyle === (2 satisfies FontStyle.Bold),\n italics: fontStyle === (1 satisfies FontStyle.Italic),\n underline:\n fontStyle === (4 satisfies FontStyle.Underline)\n ? { type: \"single\", color: fg }\n : undefined,\n strike: fontStyle === (8 satisfies FontStyle.Strikethrough),\n });\n }),\n });\n });\n },\n };\n };\n};\n"],"mappings":";;;;;AAcA,IAAM,KAAa,MAAwB;CAEzC,IAAI,EAAI,WAAW,GAAG;EACpB,IAAM,IAAI,EAAI,IACR,IAAI,EAAI,IACR,IAAI,EAAI;EACd,OAAO,EAAI,KAAM,IAAI,IAAI,IAAI,IAAI,IAAI;CACvC;CAKA,OAHI,EAAI,WAAW,IACV,EAAI,MAAM,GAAG,CAAC,IAEhB;AACT,GAYa,KAAe,EAC1B,eAC0C;CAC1C,IAAI,GACE,oBAAQ,IAAI,IAAY,GACxB,oBAAc,IAAI,IAAY;CAEpC,OAAO,OAAO,EAAE,cAAW;EACzB,IAAM,IAAqB,CAAC;EA4B5B,OA1BA,EAAM,GAAM,SAAS,EAAE,cAAW;GAChC,AAAI,MACG,EAAM,IAAI,CAAI,MACjB,EAAM,IAAI,CAAI,GACd,EAAS,KAAK,CAAI;EAGxB,CAAC,GAED,AACE,MAAc,MAAM,EAAkB;GACpC,QAAQ,CAAC,CAAK;GACd,OAAO,CAAC;EACV,CAAC,GAEH,MAAM,QAAQ,IACZ,EAAS,IAAI,OAAO,MAAM;GACxB,IAAI;IACF,MAAM,EAAa,aAAa,CAAoB;GACtD,SAAS,GAAG;IAEV,AADA,EAAY,IAAI,CAAC,GACjB,EAAS,OAAO,CAAC,CAAC;GACpB;EACF,CAAC,CACH,GAEO,EACL,OAAO,EAAE,UAAO,cAAW;GACzB,IAAI,CAAC,KAAQ,EAAY,IAAI,CAAI,GAC/B,OAAO;GAET,IAAM,IAAM,EAAa,aAAa,GAAO;IACrC;IACN;GACF,CAAC,GACG,EAAE,OAAI,UAAO;GAQjB,OAPA,AACE,MAAK,EAAU,CAAE,GAEnB,AACE,MAAK,EAAU,CAAE,GAGZ,EAAI,OAAO,KAAK,MACd,IAAI,EAAU;IACnB,SAAS;KACP,MAAM;KACN,OAAO;KACP,MAAM;IACR;IACA,UAAU,EAAE,KAAK,EAAE,YAAS,YAAS,UAAO,oBAC1C,AACE,MAAQ,EAAU,CAAK,GAEzB,AACE,MAAU,EAAU,CAAO,GAEtB,IAAI,EAAQ;KACjB,MAAM;KACN,OAAO,KAAS;KAChB,SAAS,IACL;MACE,MAAM;MACN,OAAO;MACP,MAAM;KACR,IACA,KAAA;KACJ,MAAM,MAAe;KACrB,SAAS,MAAe;KACxB,WACE,MAAe,IACX;MAAE,MAAM;MAAU,OAAO;KAAG,IAC5B,KAAA;KACN,QAAQ,MAAe;IACzB,CAAC,EACF;GACH,CAAC,CACF;EACH,EACF;CACF;AACF"}
|
package/lib/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Paragraph, ParagraphChild, Table, TableOfContents } from 'docx';
|
|
2
|
+
import { GetDefinition } from 'mdast-util-definitions';
|
|
3
|
+
import { SupportedImageType } from './utils';
|
|
2
4
|
import type * as mdast from "mdast";
|
|
3
|
-
import type { GetDefinition } from "mdast-util-definitions";
|
|
4
|
-
import type { SupportedImageType } from "./utils";
|
|
5
5
|
export type DocxContent = Paragraph | Table | TableOfContents | ParagraphChild;
|
|
6
6
|
type KnownNodeType = mdast.RootContent["type"];
|
|
7
7
|
type MdastNode<T extends string> = T extends KnownNodeType ? Extract<mdast.RootContent, {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/utils.ts
|
|
2
|
+
var e = {};
|
|
3
|
+
function t(t, n = !1) {
|
|
4
|
+
!n && !e[t] && (e[t] = !0, console.warn(t));
|
|
5
|
+
}
|
|
6
|
+
var n = [
|
|
7
|
+
"png",
|
|
8
|
+
"jpg",
|
|
9
|
+
"gif",
|
|
10
|
+
"bmp",
|
|
11
|
+
"svg"
|
|
12
|
+
], r = (e) => e ? !!n.includes(e) : !1;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { t as n, r as t };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=utils-BBifD5si.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils-BBifD5si.js","names":[],"sources":["../src/utils.ts"],"sourcesContent":["const alreadyWarned: { [message: string]: boolean } = {};\n\n/**\n * @internal\n */\nexport function warnOnce(message: string, cond: boolean = false): void {\n if (!cond && !alreadyWarned[message]) {\n alreadyWarned[message] = true;\n console.warn(message);\n }\n}\n\nconst supportedTypes = [\"png\", \"jpg\", \"gif\", \"bmp\", \"svg\"] as const;\nexport type SupportedImageType = (typeof supportedTypes)[number];\n\nexport const isSupportedType = (\n type: string | undefined,\n): type is SupportedImageType => {\n if (!type) return false;\n if ((supportedTypes as readonly string[]).includes(type)) {\n return true;\n }\n return false;\n};\n"],"mappings":";AAAA,IAAM,IAAgD,CAAC;AAKvD,SAAgB,EAAS,GAAiB,IAAgB,IAAa;CACrE,AAAI,CAAC,KAAQ,CAAC,EAAc,OAC1B,EAAc,KAAW,IACzB,QAAQ,KAAK,CAAO;AAExB;AAEA,IAAM,IAAiB;CAAC;CAAO;CAAO;CAAO;CAAO;AAAK,GAG5C,KACX,MAEK,IACL,EAAK,EAAqC,SAAS,CAAI,IADrC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var e={};function t(t,n=!1){!n&&!e[t]&&(e[t]=!0,console.warn(t))}var n=[`png`,`jpg`,`gif`,`bmp`,`svg`],r=e=>e?!!n.includes(e):!1;Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return r}});
|
|
2
|
+
//# sourceMappingURL=utils-D_YAYv4R.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils-D_YAYv4R.cjs","names":[],"sources":["../src/utils.ts"],"sourcesContent":["const alreadyWarned: { [message: string]: boolean } = {};\n\n/**\n * @internal\n */\nexport function warnOnce(message: string, cond: boolean = false): void {\n if (!cond && !alreadyWarned[message]) {\n alreadyWarned[message] = true;\n console.warn(message);\n }\n}\n\nconst supportedTypes = [\"png\", \"jpg\", \"gif\", \"bmp\", \"svg\"] as const;\nexport type SupportedImageType = (typeof supportedTypes)[number];\n\nexport const isSupportedType = (\n type: string | undefined,\n): type is SupportedImageType => {\n if (!type) return false;\n if ((supportedTypes as readonly string[]).includes(type)) {\n return true;\n }\n return false;\n};\n"],"mappings":"AAAA,IAAM,EAAgD,CAAC,EAKvD,SAAgB,EAAS,EAAiB,EAAgB,GAAa,CACjE,CAAC,GAAQ,CAAC,EAAc,KAC1B,EAAc,GAAW,GACzB,QAAQ,KAAK,CAAO,EAExB,CAEA,IAAM,EAAiB,CAAC,MAAO,MAAO,MAAO,MAAO,KAAK,EAG5C,EACX,GAEK,EACL,EAAK,EAAqC,SAAS,CAAI,EADrC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "remark-docx",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.29",
|
|
4
4
|
"description": "remark plugin to compile markdown to docx (Microsoft Word, Office Open XML).",
|
|
5
5
|
"main": "lib/index.cjs",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
],
|
|
25
25
|
"sideEffects": false,
|
|
26
26
|
"scripts": {
|
|
27
|
-
"build": "
|
|
27
|
+
"build": "vite build",
|
|
28
28
|
"test": "vitest run",
|
|
29
29
|
"tsc": "tsc -p . --noEmit",
|
|
30
30
|
"storybook": "storybook dev -p 6006",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@mathjax/src": "^4.1.2",
|
|
37
37
|
"deepmerge": "^4.3.1",
|
|
38
|
-
"docx": "9.
|
|
38
|
+
"docx": "9.7.1",
|
|
39
39
|
"fast-xml-parser": "^5.3.2",
|
|
40
40
|
"hast-util-from-html": "^2.0.3",
|
|
41
41
|
"hast-util-to-mdast": "^10.1.2",
|
|
@@ -48,7 +48,6 @@
|
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@prettier/plugin-xml": "^3.4.2",
|
|
51
|
-
"@rollup/plugin-typescript": "^12.0.0",
|
|
52
51
|
"@storybook/react-vite": "^10.3.1",
|
|
53
52
|
"@types/adm-zip": "^0.5.0",
|
|
54
53
|
"@types/deepmerge": "^2.1.0",
|
|
@@ -73,14 +72,14 @@
|
|
|
73
72
|
"remark-parse": "^11.0.0",
|
|
74
73
|
"remark-stringify": "^11.0.0",
|
|
75
74
|
"rimraf": "^6.1.2",
|
|
76
|
-
"rollup": "^4.53.3",
|
|
77
75
|
"storybook": "^10.3.1",
|
|
78
76
|
"tslib": "^2.8.1",
|
|
79
77
|
"typedoc": "^0.28.14",
|
|
80
78
|
"typedoc-plugin-markdown": "^4.9.0",
|
|
81
|
-
"typescript": "^
|
|
79
|
+
"typescript": "^6.0.0",
|
|
82
80
|
"unified": "^11.0.4",
|
|
83
81
|
"vite": "^8.0.1",
|
|
82
|
+
"vite-plugin-dts": "^5.0.2",
|
|
84
83
|
"vitest": "^4.1.0"
|
|
85
84
|
},
|
|
86
85
|
"repository": {
|
package/lib/utils-BVB8aSvE.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const alreadyWarned = {};
|
|
4
|
-
/**
|
|
5
|
-
* @internal
|
|
6
|
-
*/
|
|
7
|
-
function warnOnce(message, cond = false) {
|
|
8
|
-
if (!cond && !alreadyWarned[message]) {
|
|
9
|
-
alreadyWarned[message] = true;
|
|
10
|
-
console.warn(message);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
const supportedTypes = ["png", "jpg", "gif", "bmp", "svg"];
|
|
14
|
-
const isSupportedType = (type) => {
|
|
15
|
-
if (!type)
|
|
16
|
-
return false;
|
|
17
|
-
if (supportedTypes.includes(type)) {
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
return false;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
exports.isSupportedType = isSupportedType;
|
|
24
|
-
exports.warnOnce = warnOnce;
|
|
25
|
-
//# sourceMappingURL=utils-BVB8aSvE.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils-BVB8aSvE.js","sources":["../src/utils.ts"],"sourcesContent":["const alreadyWarned: { [message: string]: boolean } = {};\n\n/**\n * @internal\n */\nexport function warnOnce(message: string, cond: boolean = false): void {\n if (!cond && !alreadyWarned[message]) {\n alreadyWarned[message] = true;\n console.warn(message);\n }\n}\n\nconst supportedTypes = [\"png\", \"jpg\", \"gif\", \"bmp\", \"svg\"] as const;\nexport type SupportedImageType = (typeof supportedTypes)[number];\n\nexport const isSupportedType = (\n type: string | undefined,\n): type is SupportedImageType => {\n if (!type) return false;\n if ((supportedTypes as readonly string[]).includes(type)) {\n return true;\n }\n return false;\n};\n"],"names":[],"mappings":";;AAAA,MAAM,aAAa,GAAmC,EAAE;AAExD;;AAEG;SACa,QAAQ,CAAC,OAAe,EAAE,OAAgB,KAAK,EAAA;IAC7D,IAAI,CAAC,IAAI,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE;AACpC,QAAA,aAAa,CAAC,OAAO,CAAC,GAAG,IAAI;AAC7B,QAAA,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC;IACvB;AACF;AAEA,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAU;AAG5D,MAAM,eAAe,GAAG,CAC7B,IAAwB,KACM;AAC9B,IAAA,IAAI,CAAC,IAAI;AAAE,QAAA,OAAO,KAAK;AACvB,IAAA,IAAK,cAAoC,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;AACxD,QAAA,OAAO,IAAI;IACb;AACA,IAAA,OAAO,KAAK;AACd;;;;;"}
|
package/lib/utils-KFMY7wxz.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
const alreadyWarned = {};
|
|
2
|
-
/**
|
|
3
|
-
* @internal
|
|
4
|
-
*/
|
|
5
|
-
function warnOnce(message, cond = false) {
|
|
6
|
-
if (!cond && !alreadyWarned[message]) {
|
|
7
|
-
alreadyWarned[message] = true;
|
|
8
|
-
console.warn(message);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
const supportedTypes = ["png", "jpg", "gif", "bmp", "svg"];
|
|
12
|
-
const isSupportedType = (type) => {
|
|
13
|
-
if (!type)
|
|
14
|
-
return false;
|
|
15
|
-
if (supportedTypes.includes(type)) {
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
18
|
-
return false;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export { isSupportedType as i, warnOnce as w };
|
|
22
|
-
//# sourceMappingURL=utils-KFMY7wxz.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils-KFMY7wxz.js","sources":["../src/utils.ts"],"sourcesContent":["const alreadyWarned: { [message: string]: boolean } = {};\n\n/**\n * @internal\n */\nexport function warnOnce(message: string, cond: boolean = false): void {\n if (!cond && !alreadyWarned[message]) {\n alreadyWarned[message] = true;\n console.warn(message);\n }\n}\n\nconst supportedTypes = [\"png\", \"jpg\", \"gif\", \"bmp\", \"svg\"] as const;\nexport type SupportedImageType = (typeof supportedTypes)[number];\n\nexport const isSupportedType = (\n type: string | undefined,\n): type is SupportedImageType => {\n if (!type) return false;\n if ((supportedTypes as readonly string[]).includes(type)) {\n return true;\n }\n return false;\n};\n"],"names":[],"mappings":"AAAA,MAAM,aAAa,GAAmC,EAAE;AAExD;;AAEG;SACa,QAAQ,CAAC,OAAe,EAAE,OAAgB,KAAK,EAAA;IAC7D,IAAI,CAAC,IAAI,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE;AACpC,QAAA,aAAa,CAAC,OAAO,CAAC,GAAG,IAAI;AAC7B,QAAA,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC;IACvB;AACF;AAEA,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAU;AAG5D,MAAM,eAAe,GAAG,CAC7B,IAAwB,KACM;AAC9B,IAAA,IAAI,CAAC,IAAI;AAAE,QAAA,OAAO,KAAK;AACvB,IAAA,IAAK,cAAoC,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;AACxD,QAAA,OAAO,IAAI;IACb;AACA,IAAA,OAAO,KAAK;AACd;;;;"}
|