remark-docx 0.3.19 → 0.3.21
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/README.md +19 -6
- package/lib/index.cjs +95 -78
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +94 -77
- package/lib/index.js.map +1 -1
- package/lib/mdast-util-to-docx.d.ts +21 -2
- package/lib/plugins/image/index.cjs +1 -1
- package/lib/plugins/image/index.cjs.map +1 -1
- package/lib/plugins/image/index.d.ts +1 -1
- package/lib/plugins/image/index.js +1 -1
- package/lib/plugins/image/index.js.map +1 -1
- package/lib/types.d.ts +1 -1
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -6,15 +6,17 @@
|
|
|
6
6
|
|
|
7
7
|
- Uses [docx](https://github.com/dolanmiu/docx) for compilation.
|
|
8
8
|
- Works in any environment (e.g. browser, Node.js).
|
|
9
|
-
-
|
|
9
|
+
- Provides reasonable default style and also tunable enough (WIP).
|
|
10
|
+
- Supports RTL.
|
|
11
|
+
- Has own plugin system. You can fully customize markdown to Word transformation.
|
|
10
12
|
|
|
11
|
-
### Supported mdast nodes
|
|
13
|
+
### Supported [mdast](https://github.com/syntax-tree/mdast) nodes
|
|
12
14
|
|
|
13
15
|
Currently, some of the default styles may not be nice. If you have feature requests or improvements, please create a [issue](https://github.com/inokawa/remark-docx/issues) or [PR](https://github.com/inokawa/remark-docx/pulls).
|
|
14
16
|
|
|
15
17
|
- [x] paragraph
|
|
16
18
|
- [x] heading
|
|
17
|
-
- [x] thematicBreak (rendered as Page Break/Section Break)
|
|
19
|
+
- [x] thematicBreak (rendered as Page Break / Section Break / Horizontal line)
|
|
18
20
|
- [x] blockquote
|
|
19
21
|
- [x] list / listItem
|
|
20
22
|
- [x] table / tableRow / tableCell
|
|
@@ -99,15 +101,26 @@ const processor = unified()
|
|
|
99
101
|
.use(docx, { plugins: [imagePlugin()] });
|
|
100
102
|
```
|
|
101
103
|
|
|
102
|
-
|
|
104
|
+
URLs are resolved with [fetch API](https://developer.mozilla.org/docs/Web/API/Fetch_API) by default. You can use other methods such as file system.
|
|
105
|
+
|
|
106
|
+
```javascript
|
|
107
|
+
import * as fs from "fs/promises";
|
|
108
|
+
|
|
109
|
+
imagePlugin({
|
|
110
|
+
load: async (url) => {
|
|
111
|
+
return (await fs.readFile(url)).buffer;
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
When we embed `svg` to docx, it also requires `png` image since legacy Word can't render `svg`. On browser, this plugin generate it automatically. On other enviroment like Node.js, please implement `fallbackSvg` prop.
|
|
103
117
|
|
|
104
118
|
```javascript
|
|
105
119
|
import sharp from "sharp";
|
|
106
120
|
|
|
107
121
|
imagePlugin({
|
|
108
122
|
fallbackSvg: async ({ buffer }) => {
|
|
109
|
-
|
|
110
|
-
return png.buffer;
|
|
123
|
+
return (await sharp(buffer).png().toBuffer()).buffer;
|
|
111
124
|
},
|
|
112
125
|
});
|
|
113
126
|
```
|
package/lib/index.cjs
CHANGED
|
@@ -1,38 +1,29 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var docx = require('docx');
|
|
4
|
+
var utils = require('./utils-19qN-XsS.js');
|
|
4
5
|
var mdastUtilDefinitions = require('mdast-util-definitions');
|
|
5
|
-
|
|
6
|
-
const alreadyWarned = {};
|
|
7
|
-
/**
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
function warnOnce(message, cond = false) {
|
|
11
|
-
if (!cond && !alreadyWarned[message]) {
|
|
12
|
-
alreadyWarned[message] = true;
|
|
13
|
-
console.warn(message);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
6
|
+
var deepmerge = require('deepmerge');
|
|
16
7
|
|
|
17
8
|
const BULLET_LIST_REF = "bullet";
|
|
18
9
|
const ORDERED_LIST_REF = "ordered";
|
|
19
10
|
const COMPLETE_TASK_LIST_REF = "task-complete";
|
|
20
11
|
const INCOMPLETE_TASK_LIST_REF = "task-incomplete";
|
|
21
12
|
const HYPERLINK_STYLE_ID = "Hyperlink";
|
|
22
|
-
const
|
|
13
|
+
const calcIndent = (i) => {
|
|
14
|
+
const INDENT_UNIT = 10 * 40;
|
|
15
|
+
return { hanging: INDENT_UNIT, left: INDENT_UNIT * (i + 1) };
|
|
16
|
+
};
|
|
23
17
|
const createFootnoteRegistry = () => {
|
|
24
18
|
const idToInternalId = new Map();
|
|
25
19
|
const defs = new Map();
|
|
26
|
-
const getId = (id) => {
|
|
27
|
-
let internalId = idToInternalId.get(id);
|
|
28
|
-
if (internalId == null) {
|
|
29
|
-
idToInternalId.set(id, (internalId = idToInternalId.size + 1));
|
|
30
|
-
}
|
|
31
|
-
return internalId;
|
|
32
|
-
};
|
|
33
20
|
return {
|
|
34
21
|
id: (id) => {
|
|
35
|
-
|
|
22
|
+
let internalId = idToInternalId.get(id);
|
|
23
|
+
if (internalId == null) {
|
|
24
|
+
idToInternalId.set(id, (internalId = idToInternalId.size + 1));
|
|
25
|
+
}
|
|
26
|
+
return internalId;
|
|
36
27
|
},
|
|
37
28
|
set: (id, def) => {
|
|
38
29
|
defs.set(id, def);
|
|
@@ -45,7 +36,7 @@ const createFootnoteRegistry = () => {
|
|
|
45
36
|
},
|
|
46
37
|
};
|
|
47
38
|
};
|
|
48
|
-
const
|
|
39
|
+
const createOrderedListRegistry = () => {
|
|
49
40
|
let counter = 1;
|
|
50
41
|
const ids = [];
|
|
51
42
|
return {
|
|
@@ -77,7 +68,6 @@ const composeBuilders = (pluginsBuilders, defaultBuilders) => {
|
|
|
77
68
|
}, defaultBuilders);
|
|
78
69
|
};
|
|
79
70
|
const buildLevels = (formats) => {
|
|
80
|
-
const INDENT_UNIT = 10 * 40;
|
|
81
71
|
return formats.map(({ format, text }, i) => {
|
|
82
72
|
return {
|
|
83
73
|
level: i,
|
|
@@ -86,15 +76,47 @@ const buildLevels = (formats) => {
|
|
|
86
76
|
alignment: docx.AlignmentType.LEFT,
|
|
87
77
|
style: {
|
|
88
78
|
paragraph: {
|
|
89
|
-
indent:
|
|
79
|
+
indent: calcIndent(i),
|
|
90
80
|
},
|
|
91
81
|
},
|
|
92
82
|
};
|
|
93
83
|
});
|
|
94
84
|
};
|
|
95
|
-
const
|
|
85
|
+
const docxParagraph = (options, ctx) => {
|
|
86
|
+
if (ctx.quote != null) {
|
|
87
|
+
options.indent = calcIndent(ctx.quote + 1);
|
|
88
|
+
}
|
|
89
|
+
if (ctx.list) {
|
|
90
|
+
const { level, meta } = ctx.list;
|
|
91
|
+
if (meta.type === "task") {
|
|
92
|
+
options.numbering = {
|
|
93
|
+
reference: meta.checked
|
|
94
|
+
? COMPLETE_TASK_LIST_REF
|
|
95
|
+
: INCOMPLETE_TASK_LIST_REF,
|
|
96
|
+
level,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
else if (meta.type === "ordered") {
|
|
100
|
+
options.numbering = {
|
|
101
|
+
reference: meta.reference,
|
|
102
|
+
level,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
options.numbering = {
|
|
107
|
+
reference: BULLET_LIST_REF,
|
|
108
|
+
level,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (ctx.rtl) {
|
|
113
|
+
options.bidirectional = true;
|
|
114
|
+
}
|
|
115
|
+
return new docx.Paragraph(options);
|
|
116
|
+
};
|
|
117
|
+
const mdastToDocx = async (node, { plugins = [], title, subject, creator, keywords, description, styles, size, margin, orientation, spacing, direction, background, thematicBreak = "page", orderedListFormat, } = {}) => {
|
|
96
118
|
const definition = mdastUtilDefinitions.definitions(node);
|
|
97
|
-
const
|
|
119
|
+
const ordered = createOrderedListRegistry();
|
|
98
120
|
const footnote = createFootnoteRegistry();
|
|
99
121
|
const pluginCtx = { root: node, definition };
|
|
100
122
|
const builders = composeBuilders(await Promise.all(plugins.map((p) => p(pluginCtx))), {
|
|
@@ -128,7 +150,7 @@ const mdastToDocx = async (node, { plugins = [], title, subject, creator, keywor
|
|
|
128
150
|
const renderNode = (node, c) => {
|
|
129
151
|
const builder = builders[node.type];
|
|
130
152
|
if (!builder) {
|
|
131
|
-
warnOnce(`${node.type} node is not supported without plugins.`);
|
|
153
|
+
utils.warnOnce(`${node.type} node is not supported without plugins.`);
|
|
132
154
|
return null;
|
|
133
155
|
}
|
|
134
156
|
const r = builder(node, c);
|
|
@@ -179,11 +201,11 @@ const mdastToDocx = async (node, { plugins = [], title, subject, creator, keywor
|
|
|
179
201
|
},
|
|
180
202
|
width: pageWidth - marginLeft - marginRight,
|
|
181
203
|
deco: {},
|
|
182
|
-
indent: 0,
|
|
183
204
|
thematicBreak,
|
|
205
|
+
rtl: direction === "rtl",
|
|
184
206
|
definition: definition,
|
|
185
207
|
footnote,
|
|
186
|
-
orderedId:
|
|
208
|
+
orderedId: ordered.createId,
|
|
187
209
|
};
|
|
188
210
|
const sections = [[]];
|
|
189
211
|
for (const n of node.children) {
|
|
@@ -209,7 +231,7 @@ const mdastToDocx = async (node, { plugins = [], title, subject, creator, keywor
|
|
|
209
231
|
]);
|
|
210
232
|
const sectionProperties = {
|
|
211
233
|
page: {
|
|
212
|
-
size: { width: pageWidth, height: pageHeight },
|
|
234
|
+
size: { width: pageWidth, height: pageHeight, orientation },
|
|
213
235
|
margin: {
|
|
214
236
|
top: marginTop,
|
|
215
237
|
left: marginLeft,
|
|
@@ -224,7 +246,15 @@ const mdastToDocx = async (node, { plugins = [], title, subject, creator, keywor
|
|
|
224
246
|
creator,
|
|
225
247
|
keywords,
|
|
226
248
|
description,
|
|
227
|
-
styles:
|
|
249
|
+
styles: deepmerge({
|
|
250
|
+
default: {
|
|
251
|
+
document: {
|
|
252
|
+
paragraph: {
|
|
253
|
+
spacing: spacing ? { after: spacing } : undefined,
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
}, styles || {}),
|
|
228
258
|
background,
|
|
229
259
|
sections: sections
|
|
230
260
|
.filter((s) => s.length)
|
|
@@ -246,7 +276,7 @@ const mdastToDocx = async (node, { plugins = [], title, subject, creator, keywor
|
|
|
246
276
|
{ text: "\u25A0", format: "BULLET" },
|
|
247
277
|
]),
|
|
248
278
|
},
|
|
249
|
-
...
|
|
279
|
+
...ordered.getIds().map((ref) => ({
|
|
250
280
|
reference: ref,
|
|
251
281
|
levels: orderedLevels,
|
|
252
282
|
})),
|
|
@@ -275,7 +305,7 @@ const mdastToDocx = async (node, { plugins = [], title, subject, creator, keywor
|
|
|
275
305
|
],
|
|
276
306
|
},
|
|
277
307
|
});
|
|
278
|
-
// HACK: docx.js has no
|
|
308
|
+
// HACK: docx.js has no option to remove default numbering definitions from .docx. So do it here for now.
|
|
279
309
|
// https://github.com/dolanmiu/docx/blob/master/src/file/numbering/numbering.ts
|
|
280
310
|
const defaultBulletKey = "default-bullet-numbering";
|
|
281
311
|
const _numbering = doc.numbering;
|
|
@@ -284,40 +314,9 @@ const mdastToDocx = async (node, { plugins = [], title, subject, creator, keywor
|
|
|
284
314
|
return docx.Packer.toArrayBuffer(doc);
|
|
285
315
|
};
|
|
286
316
|
const buildParagraph = ({ children }, ctx) => {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
children: nodes,
|
|
291
|
-
};
|
|
292
|
-
if (ctx.indent > 0) {
|
|
293
|
-
options.indent = {
|
|
294
|
-
start: docx.convertInchesToTwip(INDENT * ctx.indent),
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
if (list) {
|
|
298
|
-
const { level, meta } = list;
|
|
299
|
-
if (meta.type === "task") {
|
|
300
|
-
options.numbering = {
|
|
301
|
-
reference: meta.checked
|
|
302
|
-
? COMPLETE_TASK_LIST_REF
|
|
303
|
-
: INCOMPLETE_TASK_LIST_REF,
|
|
304
|
-
level,
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
else if (meta.type === "ordered") {
|
|
308
|
-
options.numbering = {
|
|
309
|
-
reference: meta.reference,
|
|
310
|
-
level,
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
else {
|
|
314
|
-
options.numbering = {
|
|
315
|
-
reference: BULLET_LIST_REF,
|
|
316
|
-
level,
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
return new docx.Paragraph(options);
|
|
317
|
+
return docxParagraph({
|
|
318
|
+
children: ctx.render(children),
|
|
319
|
+
}, ctx);
|
|
321
320
|
};
|
|
322
321
|
const buildHeading = ({ children, depth }, ctx) => {
|
|
323
322
|
let level;
|
|
@@ -341,22 +340,29 @@ const buildHeading = ({ children, depth }, ctx) => {
|
|
|
341
340
|
level = "HEADING_5";
|
|
342
341
|
break;
|
|
343
342
|
}
|
|
344
|
-
return
|
|
343
|
+
return docxParagraph({
|
|
345
344
|
heading: docx.HeadingLevel[level],
|
|
346
345
|
children: ctx.render(children),
|
|
347
|
-
});
|
|
346
|
+
}, ctx);
|
|
348
347
|
};
|
|
349
348
|
const buildThematicBreak = (_, ctx) => {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
349
|
+
switch (ctx.thematicBreak) {
|
|
350
|
+
case "page": {
|
|
351
|
+
return new docx.Paragraph({ children: [new docx.PageBreak()] });
|
|
352
|
+
}
|
|
353
|
+
case "section": {
|
|
354
|
+
// Returning empty array at toplevel means section insertion.
|
|
355
|
+
return [];
|
|
356
|
+
}
|
|
357
|
+
case "line": {
|
|
358
|
+
return new docx.Paragraph({ thematicBreak: true });
|
|
359
|
+
}
|
|
353
360
|
}
|
|
354
|
-
return new docx.Paragraph({ children: [new docx.PageBreak()] });
|
|
355
361
|
};
|
|
356
362
|
const buildBlockquote = ({ children }, ctx) => {
|
|
357
363
|
return ctx.render(children, {
|
|
358
364
|
...ctx,
|
|
359
|
-
|
|
365
|
+
quote: ctx.quote == null ? 0 : ctx.quote + 1,
|
|
360
366
|
});
|
|
361
367
|
};
|
|
362
368
|
const buildList = ({ children, ordered }, ctx) => {
|
|
@@ -415,7 +421,7 @@ const buildTable = ({ children, align }, ctx) => {
|
|
|
415
421
|
});
|
|
416
422
|
const columnLength = children[0].children.length;
|
|
417
423
|
const columnWidth = ctx.width / columnLength;
|
|
418
|
-
|
|
424
|
+
const options = {
|
|
419
425
|
columnWidths: Array.from({ length: columnLength }).map(() => columnWidth),
|
|
420
426
|
rows: children.map((r) => {
|
|
421
427
|
return new docx.TableRow({
|
|
@@ -426,16 +432,24 @@ const buildTable = ({ children, align }, ctx) => {
|
|
|
426
432
|
children: [
|
|
427
433
|
new docx.Paragraph({
|
|
428
434
|
alignment: docx.AlignmentType[(_a = textAlign === null || textAlign === void 0 ? void 0 : textAlign[i]) !== null && _a !== void 0 ? _a : "LEFT"],
|
|
429
|
-
children: ctx.render(c.children
|
|
435
|
+
children: ctx.render(c.children, {
|
|
436
|
+
...ctx,
|
|
437
|
+
// https://github.com/dolanmiu/docx/blob/master/demo/22-right-to-left-text.ts
|
|
438
|
+
rtl: undefined,
|
|
439
|
+
}),
|
|
430
440
|
}),
|
|
431
441
|
],
|
|
432
442
|
});
|
|
433
443
|
}),
|
|
434
444
|
});
|
|
435
445
|
}),
|
|
436
|
-
}
|
|
446
|
+
};
|
|
447
|
+
if (ctx.rtl) {
|
|
448
|
+
options.visuallyRightToLeft = true;
|
|
449
|
+
}
|
|
450
|
+
return new docx.Table(options);
|
|
437
451
|
};
|
|
438
|
-
const buildText = ({ value }, { deco }) => {
|
|
452
|
+
const buildText = ({ value }, { deco, rtl }) => {
|
|
439
453
|
const options = {
|
|
440
454
|
text: value,
|
|
441
455
|
bold: deco.bold,
|
|
@@ -449,6 +463,9 @@ const buildText = ({ value }, { deco }) => {
|
|
|
449
463
|
// https://docx.js.org/#/usage/hyperlinks?id=styling-hyperlinks
|
|
450
464
|
options.style = HYPERLINK_STYLE_ID;
|
|
451
465
|
}
|
|
466
|
+
if (rtl) {
|
|
467
|
+
options.rightToLeft = true;
|
|
468
|
+
}
|
|
452
469
|
return new docx.TextRun(options);
|
|
453
470
|
};
|
|
454
471
|
const buildEmphasis = ({ children }, ctx) => {
|
|
@@ -510,7 +527,7 @@ const noop = () => {
|
|
|
510
527
|
return null;
|
|
511
528
|
};
|
|
512
529
|
const fallbackText = (node, ctx) => {
|
|
513
|
-
warnOnce(`${node.type} node is not supported without plugins, falling back to text.`);
|
|
530
|
+
utils.warnOnce(`${node.type} node is not supported without plugins, falling back to text.`);
|
|
514
531
|
return buildText({ value: node.value }, ctx);
|
|
515
532
|
};
|
|
516
533
|
|
package/lib/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/src/utils.ts","../src/src/mdast-util-to-docx.ts","../src/src/plugin.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","import {\n convertInchesToTwip,\n Packer,\n Document,\n Paragraph,\n Table,\n TableRow,\n TableCell,\n TextRun,\n ExternalHyperlink,\n HeadingLevel,\n LevelFormat,\n AlignmentType,\n type ILevelsOptions,\n FootnoteReferenceRun,\n type IPropertiesOptions,\n sectionPageSizeDefaults,\n sectionMarginDefaults,\n type IRunOptions,\n type IParagraphOptions,\n PageBreak,\n type ISectionPropertiesOptions,\n} from \"docx\";\nimport type * as mdast from \"mdast\";\nimport { warnOnce } from \"./utils\";\nimport { definitions } from \"mdast-util-definitions\";\nimport type {\n Context,\n DocxChild,\n DocxContent,\n FootnoteRegistry,\n ListContext,\n NodeBuilder,\n NodeBuilders,\n RemarkDocxPlugin,\n ThematicBreakType,\n Writeable,\n} from \"./types\";\n\nconst BULLET_LIST_REF = \"bullet\";\nconst ORDERED_LIST_REF = \"ordered\";\nconst COMPLETE_TASK_LIST_REF = \"task-complete\";\nconst INCOMPLETE_TASK_LIST_REF = \"task-incomplete\";\nconst HYPERLINK_STYLE_ID = \"Hyperlink\";\nconst INDENT = 0.5;\n\nconst createFootnoteRegistry = (): FootnoteRegistry => {\n const idToInternalId = new Map<string, number>();\n const defs = new Map<number, Paragraph[]>();\n\n const getId = (id: string): number => {\n let internalId = idToInternalId.get(id);\n if (internalId == null) {\n idToInternalId.set(id, (internalId = idToInternalId.size + 1));\n }\n return internalId;\n };\n\n return {\n id: (id) => {\n return getId(id);\n },\n set: (id, def) => {\n defs.set(id, def);\n },\n toConfig: () => {\n return defs.entries().reduce(\n (acc, [key, def]) => {\n acc[key] = { children: def };\n return acc;\n },\n {} as {\n [key: string]: { children: Paragraph[] };\n },\n );\n },\n };\n};\n\ntype ListFormat = {\n format: keyof typeof LevelFormat;\n text: string;\n};\n\ntype NumberingRegistry = {\n createId: () => string;\n getIds: () => string[];\n};\nconst createNumberingRegistry = (): NumberingRegistry => {\n let counter = 1;\n\n const ids: string[] = [];\n\n return {\n createId: () => {\n const id = `${ORDERED_LIST_REF}-${counter++}`;\n ids.push(id);\n return id;\n },\n getIds: () => {\n return ids;\n },\n };\n};\n\nconst composeBuilders = (\n pluginsBuilders: readonly NodeBuilders[],\n defaultBuilders: NodeBuilders,\n): NodeBuilders => {\n return pluginsBuilders.reduceRight<NodeBuilders>((acc, p) => {\n type Key = keyof typeof p;\n for (const [k, cur] of Object.entries(p)) {\n const prev = acc[k as Key];\n acc[k as Key] = (\n prev\n ? (n, c) => {\n const r = cur(n as any, c);\n if (r) {\n return r;\n }\n return prev(n as any, c);\n }\n : cur\n ) as NodeBuilder<any>;\n }\n return acc;\n }, defaultBuilders);\n};\n\nconst buildLevels = (formats: readonly ListFormat[]): ILevelsOptions[] => {\n const INDENT_UNIT = 10 * 40;\n return formats.map(({ format, text }, i) => {\n return {\n level: i,\n format: LevelFormat[format],\n text: text,\n alignment: AlignmentType.LEFT,\n style: {\n paragraph: {\n indent: { hanging: INDENT_UNIT, left: INDENT_UNIT * (i + 1) },\n },\n },\n };\n });\n};\n\nexport interface DocxOptions extends Pick<\n IPropertiesOptions,\n | \"title\"\n | \"subject\"\n | \"creator\"\n | \"keywords\"\n | \"description\"\n | \"styles\"\n | \"background\"\n> {\n /**\n * Page size defined in twip (1 twip == 1/1440 inch).\n * @default A4 ({@link sectionPageSizeDefaults})\n */\n size?: { width?: number; height?: number };\n /**\n * Page margin defined in twip (1 twip == 1/1440 inch).\n * @default 1 inch ({@link sectionMarginDefaults})\n */\n margin?: { top?: number; left?: number; bottom?: number; right?: number };\n /**\n * An option to override the text format of ordered list.\n * See https://docx.js.org/#/usage/numbering?id=level-options for more details.\n */\n orderedListFormat?: ListFormat[];\n /**\n * An option to select how thematicBreak works. \"page\" is Page Break. \"section\" is Section Break.\n * @default \"page\"\n */\n thematicBreak?: ThematicBreakType;\n /**\n * Plugins to customize how mdast nodes are compiled.\n */\n plugins?: RemarkDocxPlugin[];\n}\n\nexport const mdastToDocx = async (\n node: mdast.Root,\n {\n plugins = [],\n title,\n subject,\n creator,\n keywords,\n description,\n styles,\n size,\n margin,\n background,\n thematicBreak = \"page\",\n orderedListFormat,\n }: DocxOptions = {},\n): Promise<ArrayBuffer> => {\n const definition = definitions(node);\n\n const numbering = createNumberingRegistry();\n const footnote = createFootnoteRegistry();\n\n const pluginCtx = { root: node, definition };\n\n const builders = composeBuilders(\n await Promise.all(plugins.map((p) => p(pluginCtx))),\n {\n paragraph: buildParagraph,\n heading: buildHeading,\n thematicBreak: buildThematicBreak,\n blockquote: buildBlockquote,\n list: buildList,\n listItem: buildListItem,\n table: buildTable,\n tableRow: noop,\n tableCell: noop,\n html: fallbackText,\n code: fallbackText,\n definition: noop,\n footnoteDefinition: buildFootnoteDefinition,\n text: buildText,\n emphasis: buildEmphasis,\n strong: buildStrong,\n delete: buildDelete,\n inlineCode: buildInlineCode,\n break: buildBreak,\n link: buildLink,\n linkReference: buildLinkReference,\n // image: warnImage,\n // imageReference: warnImage,\n footnoteReference: buildFootnoteReference,\n math: fallbackText,\n inlineMath: fallbackText,\n },\n );\n\n const renderNode = (\n node: mdast.RootContent,\n c: Context,\n ): DocxContent[] | null => {\n const builder = builders[node.type];\n if (!builder) {\n warnOnce(`${node.type} node is not supported without plugins.`);\n return null;\n }\n const r = builder(node as any, c);\n if (r) {\n if (Array.isArray(r)) {\n return r;\n } else {\n return [r];\n }\n }\n return null;\n };\n\n let { WIDTH: pageWidth, HEIGHT: pageHeight } = sectionPageSizeDefaults;\n if (size) {\n if (size.width != null) {\n pageWidth = size.width;\n }\n if (size.height != null) {\n pageHeight = size.height;\n }\n }\n let {\n TOP: marginTop,\n LEFT: marginLeft,\n BOTTOM: marginBottom,\n RIGHT: marginRight,\n } = sectionMarginDefaults;\n if (margin) {\n if (margin.top != null) {\n marginTop = margin.top;\n }\n if (margin.left != null) {\n marginLeft = margin.left;\n }\n if (margin.bottom != null) {\n marginBottom = margin.bottom;\n }\n if (margin.right != null) {\n marginRight = margin.right;\n }\n }\n\n const ctx: Context = {\n render(nodes, c) {\n const results: DocxContent[] = [];\n for (const node of nodes) {\n const r = renderNode(node, c ?? this);\n if (r) {\n results.push(...r);\n }\n }\n return results;\n },\n width: pageWidth - marginLeft - marginRight,\n deco: {},\n indent: 0,\n thematicBreak,\n definition: definition,\n footnote,\n orderedId: numbering.createId,\n };\n\n const sections: DocxContent[][] = [[]];\n for (const n of node.children) {\n const r = renderNode(n, ctx);\n if (r) {\n if (!r.length) {\n // thematicBreak\n sections.push([]);\n } else {\n const lastSection = sections[sections.length - 1]!;\n lastSection.push(...r);\n }\n }\n }\n\n const orderedLevels = buildLevels(\n orderedListFormat ?? [\n { text: \"%1.\", format: \"DECIMAL\" },\n { text: \"%2.\", format: \"DECIMAL\" },\n { text: \"%3.\", format: \"DECIMAL\" },\n { text: \"%4.\", format: \"DECIMAL\" },\n { text: \"%5.\", format: \"DECIMAL\" },\n { text: \"%6.\", format: \"DECIMAL\" },\n ],\n );\n\n const sectionProperties: ISectionPropertiesOptions = {\n page: {\n size: { width: pageWidth, height: pageHeight },\n margin: {\n top: marginTop,\n left: marginLeft,\n bottom: marginBottom,\n right: marginRight,\n },\n },\n };\n\n const doc = new Document({\n title,\n subject,\n creator,\n keywords,\n description,\n styles: styles,\n background,\n sections: sections\n .filter((s) => s.length)\n .map((s) => ({\n properties: sectionProperties,\n children: s as DocxChild[],\n })),\n footnotes: footnote.toConfig(),\n numbering: {\n config: [\n {\n reference: BULLET_LIST_REF,\n levels: buildLevels([\n { text: \"\\u25CF\", format: \"BULLET\" },\n { text: \"\\u25CB\", format: \"BULLET\" },\n { text: \"\\u25A0\", format: \"BULLET\" },\n { text: \"\\u25CF\", format: \"BULLET\" },\n { text: \"\\u25CB\", format: \"BULLET\" },\n { text: \"\\u25A0\", format: \"BULLET\" },\n ]),\n },\n ...numbering.getIds().map((ref) => ({\n reference: ref,\n levels: orderedLevels,\n })),\n {\n reference: COMPLETE_TASK_LIST_REF,\n levels: buildLevels([\n { text: \"\\u2611\", format: \"BULLET\" },\n { text: \"\\u2611\", format: \"BULLET\" },\n { text: \"\\u2611\", format: \"BULLET\" },\n { text: \"\\u2611\", format: \"BULLET\" },\n { text: \"\\u2611\", format: \"BULLET\" },\n { text: \"\\u2611\", format: \"BULLET\" },\n ]),\n },\n {\n reference: INCOMPLETE_TASK_LIST_REF,\n levels: buildLevels([\n { text: \"\\u2610\", format: \"BULLET\" },\n { text: \"\\u2610\", format: \"BULLET\" },\n { text: \"\\u2610\", format: \"BULLET\" },\n { text: \"\\u2610\", format: \"BULLET\" },\n { text: \"\\u2610\", format: \"BULLET\" },\n { text: \"\\u2610\", format: \"BULLET\" },\n ]),\n },\n ],\n },\n });\n\n // HACK: docx.js has no way to remove default numberings styles from .docx. So do it here for now.\n // https://github.com/dolanmiu/docx/blob/master/src/file/numbering/numbering.ts\n const defaultBulletKey = \"default-bullet-numbering\";\n const _numbering = (doc as any).numbering;\n _numbering.abstractNumberingMap.delete(defaultBulletKey);\n _numbering.concreteNumberingMap.delete(defaultBulletKey);\n\n return Packer.toArrayBuffer(doc);\n};\n\nconst buildParagraph: NodeBuilder<\"paragraph\"> = ({ children }, ctx) => {\n const list = ctx.list;\n const nodes = ctx.render(children);\n\n const options: Writeable<IParagraphOptions> = {\n children: nodes,\n };\n\n if (ctx.indent > 0) {\n options.indent = {\n start: convertInchesToTwip(INDENT * ctx.indent),\n };\n }\n\n if (list) {\n const { level, meta } = list;\n if (meta.type === \"task\") {\n options.numbering = {\n reference: meta.checked\n ? COMPLETE_TASK_LIST_REF\n : INCOMPLETE_TASK_LIST_REF,\n level,\n };\n } else if (meta.type === \"ordered\") {\n options.numbering = {\n reference: meta.reference,\n level,\n };\n } else {\n options.numbering = {\n reference: BULLET_LIST_REF,\n level,\n };\n }\n }\n\n return new Paragraph(options);\n};\n\nconst buildHeading: NodeBuilder<\"heading\"> = ({ children, depth }, ctx) => {\n let level: keyof typeof HeadingLevel;\n switch (depth) {\n case 1:\n level = \"TITLE\";\n break;\n case 2:\n level = \"HEADING_1\";\n break;\n case 3:\n level = \"HEADING_2\";\n break;\n case 4:\n level = \"HEADING_3\";\n break;\n case 5:\n level = \"HEADING_4\";\n break;\n case 6:\n level = \"HEADING_5\";\n break;\n }\n return new Paragraph({\n heading: HeadingLevel[level],\n children: ctx.render(children),\n });\n};\n\nconst buildThematicBreak: NodeBuilder<\"thematicBreak\"> = (_, ctx) => {\n if (ctx.thematicBreak === \"section\") {\n // Returning empty array at toplevel means section insertion.\n return [];\n }\n return new Paragraph({ children: [new PageBreak()] });\n};\n\nconst buildBlockquote: NodeBuilder<\"blockquote\"> = ({ children }, ctx) => {\n return ctx.render(children, {\n ...ctx,\n indent: ctx.indent + 1,\n });\n};\n\nconst buildList: NodeBuilder<\"list\"> = ({ children, ordered }, ctx) => {\n const parentList = ctx.list;\n\n let meta: ListContext[\"meta\"];\n if (ordered) {\n meta = {\n type: \"ordered\",\n reference:\n parentList && parentList.meta.type === \"ordered\"\n ? parentList.meta.reference\n : ctx.orderedId(),\n };\n } else {\n meta = { type: \"bullet\" };\n }\n\n return ctx.render(children, {\n ...ctx,\n list: {\n level: !parentList ? 0 : parentList.level + 1,\n meta,\n },\n });\n};\n\nconst buildListItem: NodeBuilder<\"listItem\"> = ({ children, checked }, ctx) => {\n let list = ctx.list;\n if (list) {\n // listItem must be the child of list\n if (checked != null) {\n list = {\n level: list.level,\n meta: {\n type: \"task\",\n checked,\n },\n };\n }\n }\n return ctx.render(children, {\n ...ctx,\n list,\n });\n};\n\nconst buildTable: NodeBuilder<\"table\"> = ({ children, align }, ctx) => {\n const textAlign = align?.map((a): keyof typeof AlignmentType => {\n switch (a) {\n case \"left\":\n return \"LEFT\";\n case \"right\":\n return \"RIGHT\";\n case \"center\":\n return \"CENTER\";\n default:\n return \"LEFT\";\n }\n });\n\n const columnLength = children[0]!.children.length;\n const columnWidth = ctx.width / columnLength;\n\n return new Table({\n columnWidths: Array.from({ length: columnLength }).map(() => columnWidth),\n rows: children.map((r) => {\n return new TableRow({\n children: r.children.map((c, i) => {\n return new TableCell({\n width: { size: columnWidth, type: \"dxa\" },\n children: [\n new Paragraph({\n alignment: AlignmentType[textAlign?.[i] ?? \"LEFT\"],\n children: ctx.render(c.children),\n }),\n ],\n });\n }),\n });\n }),\n });\n};\n\nconst buildText: NodeBuilder<\"text\"> = ({ value }, { deco }) => {\n const options: Writeable<IRunOptions> = {\n text: value,\n bold: deco.bold,\n italics: deco.italic,\n strike: deco.strike,\n };\n if (deco.inlineCode) {\n options.highlight = \"lightGray\";\n }\n if (deco.link) {\n // https://docx.js.org/#/usage/hyperlinks?id=styling-hyperlinks\n options.style = HYPERLINK_STYLE_ID;\n }\n return new TextRun(options);\n};\n\nconst buildEmphasis: NodeBuilder<\"emphasis\"> = ({ children }, ctx) => {\n return ctx.render(children, {\n ...ctx,\n deco: { ...ctx.deco, italic: true },\n });\n};\n\nconst buildStrong: NodeBuilder<\"strong\"> = ({ children }, ctx) => {\n return ctx.render(children, {\n ...ctx,\n deco: { ...ctx.deco, bold: true },\n });\n};\n\nconst buildDelete: NodeBuilder<\"delete\"> = ({ children }, ctx) => {\n return ctx.render(children, {\n ...ctx,\n deco: { ...ctx.deco, strike: true },\n });\n};\n\nconst buildInlineCode: NodeBuilder<\"inlineCode\"> = ({ value }, ctx) => {\n return buildText(\n { type: \"text\", value },\n {\n ...ctx,\n deco: { ...ctx.deco, inlineCode: true },\n },\n );\n};\n\nconst buildBreak: NodeBuilder<\"break\"> = () => {\n return new TextRun({ text: \"\", break: 1 });\n};\n\nconst buildLink: NodeBuilder<\"link\"> = ({ children, url }, ctx) => {\n if (url.startsWith(\"#\")) {\n // TODO support anchor link\n return ctx.render(children);\n }\n return new ExternalHyperlink({\n link: url,\n children: ctx.render(children, {\n ...ctx,\n deco: { ...ctx.deco, link: true },\n }),\n });\n};\n\nconst buildLinkReference: NodeBuilder<\"linkReference\"> = (\n { children, identifier },\n ctx,\n) => {\n const def = ctx.definition(identifier);\n if (def == null) {\n return ctx.render(children);\n }\n return buildLink({ type: \"link\", children, url: def.url }, ctx);\n};\n\nconst buildFootnoteDefinition: NodeBuilder<\"footnoteDefinition\"> = (\n { children, identifier },\n ctx,\n) => {\n const contents = ctx.render(children).filter((c) => c instanceof Paragraph);\n ctx.footnote.set(ctx.footnote.id(identifier), contents);\n return null;\n};\n\nconst buildFootnoteReference: NodeBuilder<\"footnoteReference\"> = (\n { identifier },\n ctx,\n) => {\n return new FootnoteReferenceRun(ctx.footnote.id(identifier));\n};\n\nconst noop = () => {\n return null;\n};\n\nconst fallbackText = (node: { type: string; value: string }, ctx: Context) => {\n warnOnce(\n `${node.type} node is not supported without plugins, falling back to text.`,\n );\n return buildText({ type: \"text\", value: node.value }, ctx);\n};\n","import type { Plugin } from \"unified\";\nimport type { Root } from \"mdast\";\nimport { mdastToDocx, type DocxOptions } from \"./mdast-util-to-docx\";\n\nexport type { DocxOptions };\n\ndeclare module \"unified\" {\n interface CompileResultMap {\n docx: Promise<ArrayBuffer>;\n }\n}\n\nconst plugin: Plugin<[DocxOptions?], Root, Promise<ArrayBuffer>> = function (\n opts,\n) {\n this.compiler = (node) => {\n return mdastToDocx(node as Root, opts);\n };\n};\nexport default plugin;\n"],"names":["LevelFormat","AlignmentType","definitions","sectionPageSizeDefaults","sectionMarginDefaults","Document","Packer","convertInchesToTwip","Paragraph","HeadingLevel","PageBreak","Table","TableRow","TableCell","TextRun","ExternalHyperlink","FootnoteReferenceRun"],"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;;AC6BA,MAAM,eAAe,GAAG,QAAQ;AAChC,MAAM,gBAAgB,GAAG,SAAS;AAClC,MAAM,sBAAsB,GAAG,eAAe;AAC9C,MAAM,wBAAwB,GAAG,iBAAiB;AAClD,MAAM,kBAAkB,GAAG,WAAW;AACtC,MAAM,MAAM,GAAG,GAAG;AAElB,MAAM,sBAAsB,GAAG,MAAuB;AACpD,IAAA,MAAM,cAAc,GAAG,IAAI,GAAG,EAAkB;AAChD,IAAA,MAAM,IAAI,GAAG,IAAI,GAAG,EAAuB;AAE3C,IAAA,MAAM,KAAK,GAAG,CAAC,EAAU,KAAY;QACnC,IAAI,UAAU,GAAG,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC;AACvC,QAAA,IAAI,UAAU,IAAI,IAAI,EAAE;AACtB,YAAA,cAAc,CAAC,GAAG,CAAC,EAAE,GAAG,UAAU,GAAG,cAAc,CAAC,IAAI,GAAG,CAAC,EAAE;QAChE;AACA,QAAA,OAAO,UAAU;AACnB,IAAA,CAAC;IAED,OAAO;AACL,QAAA,EAAE,EAAE,CAAC,EAAE,KAAI;AACT,YAAA,OAAO,KAAK,CAAC,EAAE,CAAC;QAClB,CAAC;AACD,QAAA,GAAG,EAAE,CAAC,EAAE,EAAE,GAAG,KAA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EAAE,IAAI,CAAC;AACxC,IAAA,CAAC;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/mdast-util-to-docx.ts","../src/plugin.ts"],"sourcesContent":["import {\n Packer,\n Document,\n Paragraph,\n Table,\n TableRow,\n TableCell,\n TextRun,\n ExternalHyperlink,\n HeadingLevel,\n LevelFormat,\n AlignmentType,\n type ILevelsOptions,\n FootnoteReferenceRun,\n type IPropertiesOptions,\n sectionPageSizeDefaults,\n sectionMarginDefaults,\n type IRunOptions,\n type IParagraphOptions,\n PageBreak,\n type ISectionPropertiesOptions,\n type IIndentAttributesProperties,\n type IStylesOptions,\n type ITableOptions,\n} from \"docx\";\nimport type * as mdast from \"mdast\";\nimport { warnOnce } from \"./utils\";\nimport { definitions } from \"mdast-util-definitions\";\nimport deepmerge from \"deepmerge\";\nimport type {\n Context,\n DocxChild,\n DocxContent,\n FootnoteRegistry,\n ListContext,\n NodeBuilder,\n NodeBuilders,\n RemarkDocxPlugin,\n ThematicBreakType,\n Writeable,\n} from \"./types\";\n\nconst BULLET_LIST_REF = \"bullet\";\nconst ORDERED_LIST_REF = \"ordered\";\nconst COMPLETE_TASK_LIST_REF = \"task-complete\";\nconst INCOMPLETE_TASK_LIST_REF = \"task-incomplete\";\nconst HYPERLINK_STYLE_ID = \"Hyperlink\";\n\nconst calcIndent = (i: number): IIndentAttributesProperties => {\n const INDENT_UNIT = 10 * 40;\n return { hanging: INDENT_UNIT, left: INDENT_UNIT * (i + 1) };\n};\n\nconst createFootnoteRegistry = (): FootnoteRegistry => {\n const idToInternalId = new Map<string, number>();\n const defs = new Map<number, Paragraph[]>();\n\n return {\n id: (id) => {\n let internalId = idToInternalId.get(id);\n if (internalId == null) {\n idToInternalId.set(id, (internalId = idToInternalId.size + 1));\n }\n return internalId;\n },\n set: (id, def) => {\n defs.set(id, def);\n },\n toConfig: () => {\n return defs.entries().reduce(\n (acc, [key, def]) => {\n acc[key] = { children: def };\n return acc;\n },\n {} as {\n [key: string]: { children: Paragraph[] };\n },\n );\n },\n };\n};\n\ntype ListFormat = {\n format: keyof typeof LevelFormat;\n text: string;\n};\n\ntype OrderedListRegistry = {\n createId: () => string;\n getIds: () => string[];\n};\nconst createOrderedListRegistry = (): OrderedListRegistry => {\n let counter = 1;\n\n const ids: string[] = [];\n\n return {\n createId: () => {\n const id = `${ORDERED_LIST_REF}-${counter++}`;\n ids.push(id);\n return id;\n },\n getIds: () => {\n return ids;\n },\n };\n};\n\nconst composeBuilders = (\n pluginsBuilders: readonly NodeBuilders[],\n defaultBuilders: NodeBuilders,\n): NodeBuilders => {\n return pluginsBuilders.reduceRight<NodeBuilders>((acc, p) => {\n type Key = keyof typeof p;\n for (const [k, cur] of Object.entries(p)) {\n const prev = acc[k as Key];\n acc[k as Key] = (\n prev\n ? (n, c) => {\n const r = cur(n as any, c);\n if (r) {\n return r;\n }\n return prev(n as any, c);\n }\n : cur\n ) as NodeBuilder<any>;\n }\n return acc;\n }, defaultBuilders);\n};\n\nconst buildLevels = (formats: readonly ListFormat[]): ILevelsOptions[] => {\n return formats.map(({ format, text }, i) => {\n return {\n level: i,\n format: LevelFormat[format],\n text: text,\n alignment: AlignmentType.LEFT,\n style: {\n paragraph: {\n indent: calcIndent(i),\n },\n },\n };\n });\n};\n\nconst docxParagraph = (\n options: Writeable<IParagraphOptions>,\n ctx: Context,\n): Paragraph => {\n if (ctx.quote != null) {\n options.indent = calcIndent(ctx.quote + 1);\n }\n\n if (ctx.list) {\n const { level, meta } = ctx.list;\n if (meta.type === \"task\") {\n options.numbering = {\n reference: meta.checked\n ? COMPLETE_TASK_LIST_REF\n : INCOMPLETE_TASK_LIST_REF,\n level,\n };\n } else if (meta.type === \"ordered\") {\n options.numbering = {\n reference: meta.reference,\n level,\n };\n } else {\n options.numbering = {\n reference: BULLET_LIST_REF,\n level,\n };\n }\n }\n\n if (ctx.rtl) {\n options.bidirectional = true;\n }\n\n return new Paragraph(options);\n};\n\nexport interface DocxOptions extends Pick<\n IPropertiesOptions,\n | \"title\"\n | \"subject\"\n | \"creator\"\n | \"keywords\"\n | \"description\"\n | \"styles\"\n | \"background\"\n> {\n /**\n * Page size defined in twip (1 twip == 1/1440 inch).\n * @default A4 ({@link sectionPageSizeDefaults})\n */\n size?: { width?: number; height?: number };\n /**\n * Page margin defined in twip (1 twip == 1/1440 inch).\n * @default 1 inch ({@link sectionMarginDefaults})\n */\n margin?: { top?: number; left?: number; bottom?: number; right?: number };\n /**\n * Page orientation.\n * @default \"portrait\"\n */\n orientation?: \"portrait\" | \"landscape\";\n /**\n * Spacing after Paragraphs in twip (1 twip == 1/1440 inch).\n * @default 0\n */\n spacing?: number;\n /**\n * Direction of texts.\n * @default \"ltr\"\n */\n direction?: \"ltr\" | \"rtl\";\n /**\n * An option to override the text format of ordered list.\n * See https://docx.js.org/#/usage/numbering?id=level-options for more details.\n */\n orderedListFormat?: ListFormat[];\n /**\n * An option to select how thematicBreak works.\n *\n * - \"page\": Page Break\n * - \"section\": Section Break\n * - \"line\": Horizontal line\n * @default \"page\"\n */\n thematicBreak?: ThematicBreakType;\n /**\n * Plugins to customize how mdast nodes are compiled.\n */\n plugins?: RemarkDocxPlugin[];\n}\n\nexport const mdastToDocx = async (\n node: mdast.Root,\n {\n plugins = [],\n title,\n subject,\n creator,\n keywords,\n description,\n styles,\n size,\n margin,\n orientation,\n spacing,\n direction,\n background,\n thematicBreak = \"page\",\n orderedListFormat,\n }: DocxOptions = {},\n): Promise<ArrayBuffer> => {\n const definition = definitions(node);\n\n const ordered = createOrderedListRegistry();\n const footnote = createFootnoteRegistry();\n\n const pluginCtx = { root: node, definition };\n\n const builders = composeBuilders(\n await Promise.all(plugins.map((p) => p(pluginCtx))),\n {\n paragraph: buildParagraph,\n heading: buildHeading,\n thematicBreak: buildThematicBreak,\n blockquote: buildBlockquote,\n list: buildList,\n listItem: buildListItem,\n table: buildTable,\n tableRow: noop,\n tableCell: noop,\n html: fallbackText,\n code: fallbackText,\n definition: noop,\n footnoteDefinition: buildFootnoteDefinition,\n text: buildText,\n emphasis: buildEmphasis,\n strong: buildStrong,\n delete: buildDelete,\n inlineCode: buildInlineCode,\n break: buildBreak,\n link: buildLink,\n linkReference: buildLinkReference,\n // image: warnImage,\n // imageReference: warnImage,\n footnoteReference: buildFootnoteReference,\n math: fallbackText,\n inlineMath: fallbackText,\n },\n );\n\n const renderNode = (\n node: mdast.RootContent,\n c: Context,\n ): DocxContent[] | null => {\n const builder = builders[node.type];\n if (!builder) {\n warnOnce(`${node.type} node is not supported without plugins.`);\n return null;\n }\n const r = builder(node as any, c);\n if (r) {\n if (Array.isArray(r)) {\n return r;\n } else {\n return [r];\n }\n }\n return null;\n };\n\n let { WIDTH: pageWidth, HEIGHT: pageHeight } = sectionPageSizeDefaults;\n if (size) {\n if (size.width != null) {\n pageWidth = size.width;\n }\n if (size.height != null) {\n pageHeight = size.height;\n }\n }\n let {\n TOP: marginTop,\n LEFT: marginLeft,\n BOTTOM: marginBottom,\n RIGHT: marginRight,\n } = sectionMarginDefaults;\n if (margin) {\n if (margin.top != null) {\n marginTop = margin.top;\n }\n if (margin.left != null) {\n marginLeft = margin.left;\n }\n if (margin.bottom != null) {\n marginBottom = margin.bottom;\n }\n if (margin.right != null) {\n marginRight = margin.right;\n }\n }\n\n const ctx: Context = {\n render(nodes, c) {\n const results: DocxContent[] = [];\n for (const node of nodes) {\n const r = renderNode(node, c ?? this);\n if (r) {\n results.push(...r);\n }\n }\n return results;\n },\n width: pageWidth - marginLeft - marginRight,\n deco: {},\n thematicBreak,\n rtl: direction === \"rtl\",\n definition: definition,\n footnote,\n orderedId: ordered.createId,\n };\n\n const sections: DocxContent[][] = [[]];\n for (const n of node.children) {\n const r = renderNode(n, ctx);\n if (r) {\n if (!r.length) {\n // thematicBreak\n sections.push([]);\n } else {\n const lastSection = sections[sections.length - 1]!;\n lastSection.push(...r);\n }\n }\n }\n\n const orderedLevels = buildLevels(\n orderedListFormat ?? [\n { text: \"%1.\", format: \"DECIMAL\" },\n { text: \"%2.\", format: \"DECIMAL\" },\n { text: \"%3.\", format: \"DECIMAL\" },\n { text: \"%4.\", format: \"DECIMAL\" },\n { text: \"%5.\", format: \"DECIMAL\" },\n { text: \"%6.\", format: \"DECIMAL\" },\n ],\n );\n\n const sectionProperties: ISectionPropertiesOptions = {\n page: {\n size: { width: pageWidth, height: pageHeight, orientation },\n margin: {\n top: marginTop,\n left: marginLeft,\n bottom: marginBottom,\n right: marginRight,\n },\n },\n };\n\n const doc = new Document({\n title,\n subject,\n creator,\n keywords,\n description,\n styles: deepmerge<IStylesOptions>(\n {\n default: {\n document: {\n paragraph: {\n spacing: spacing ? { after: spacing } : undefined,\n },\n },\n },\n },\n styles || {},\n ),\n background,\n sections: sections\n .filter((s) => s.length)\n .map((s) => ({\n properties: sectionProperties,\n children: s as DocxChild[],\n })),\n footnotes: footnote.toConfig(),\n numbering: {\n config: [\n {\n reference: BULLET_LIST_REF,\n levels: buildLevels([\n { text: \"\\u25CF\", format: \"BULLET\" },\n { text: \"\\u25CB\", format: \"BULLET\" },\n { text: \"\\u25A0\", format: \"BULLET\" },\n { text: \"\\u25CF\", format: \"BULLET\" },\n { text: \"\\u25CB\", format: \"BULLET\" },\n { text: \"\\u25A0\", format: \"BULLET\" },\n ]),\n },\n ...ordered.getIds().map((ref) => ({\n reference: ref,\n levels: orderedLevels,\n })),\n {\n reference: COMPLETE_TASK_LIST_REF,\n levels: buildLevels([\n { text: \"\\u2611\", format: \"BULLET\" },\n { text: \"\\u2611\", format: \"BULLET\" },\n { text: \"\\u2611\", format: \"BULLET\" },\n { text: \"\\u2611\", format: \"BULLET\" },\n { text: \"\\u2611\", format: \"BULLET\" },\n { text: \"\\u2611\", format: \"BULLET\" },\n ]),\n },\n {\n reference: INCOMPLETE_TASK_LIST_REF,\n levels: buildLevels([\n { text: \"\\u2610\", format: \"BULLET\" },\n { text: \"\\u2610\", format: \"BULLET\" },\n { text: \"\\u2610\", format: \"BULLET\" },\n { text: \"\\u2610\", format: \"BULLET\" },\n { text: \"\\u2610\", format: \"BULLET\" },\n { text: \"\\u2610\", format: \"BULLET\" },\n ]),\n },\n ],\n },\n });\n\n // HACK: docx.js has no option to remove default numbering definitions from .docx. So do it here for now.\n // https://github.com/dolanmiu/docx/blob/master/src/file/numbering/numbering.ts\n const defaultBulletKey = \"default-bullet-numbering\";\n const _numbering = (doc as any).numbering;\n _numbering.abstractNumberingMap.delete(defaultBulletKey);\n _numbering.concreteNumberingMap.delete(defaultBulletKey);\n\n return Packer.toArrayBuffer(doc);\n};\n\nconst buildParagraph: NodeBuilder<\"paragraph\"> = ({ children }, ctx) => {\n return docxParagraph(\n {\n children: ctx.render(children),\n },\n ctx,\n );\n};\n\nconst buildHeading: NodeBuilder<\"heading\"> = ({ children, depth }, ctx) => {\n let level: keyof typeof HeadingLevel;\n switch (depth) {\n case 1:\n level = \"TITLE\";\n break;\n case 2:\n level = \"HEADING_1\";\n break;\n case 3:\n level = \"HEADING_2\";\n break;\n case 4:\n level = \"HEADING_3\";\n break;\n case 5:\n level = \"HEADING_4\";\n break;\n case 6:\n level = \"HEADING_5\";\n break;\n }\n return docxParagraph(\n {\n heading: HeadingLevel[level],\n children: ctx.render(children),\n },\n ctx,\n );\n};\n\nconst buildThematicBreak: NodeBuilder<\"thematicBreak\"> = (_, ctx) => {\n switch (ctx.thematicBreak) {\n case \"page\": {\n return new Paragraph({ children: [new PageBreak()] });\n }\n case \"section\": {\n // Returning empty array at toplevel means section insertion.\n return [];\n }\n case \"line\": {\n return new Paragraph({ thematicBreak: true });\n }\n }\n};\n\nconst buildBlockquote: NodeBuilder<\"blockquote\"> = ({ children }, ctx) => {\n return ctx.render(children, {\n ...ctx,\n quote: ctx.quote == null ? 0 : ctx.quote + 1,\n });\n};\n\nconst buildList: NodeBuilder<\"list\"> = ({ children, ordered }, ctx) => {\n const parentList = ctx.list;\n\n let meta: ListContext[\"meta\"];\n if (ordered) {\n meta = {\n type: \"ordered\",\n reference:\n parentList && parentList.meta.type === \"ordered\"\n ? parentList.meta.reference\n : ctx.orderedId(),\n };\n } else {\n meta = { type: \"bullet\" };\n }\n\n return ctx.render(children, {\n ...ctx,\n list: {\n level: !parentList ? 0 : parentList.level + 1,\n meta,\n },\n });\n};\n\nconst buildListItem: NodeBuilder<\"listItem\"> = ({ children, checked }, ctx) => {\n let list = ctx.list;\n if (list) {\n // listItem must be the child of list\n if (checked != null) {\n list = {\n level: list.level,\n meta: {\n type: \"task\",\n checked,\n },\n };\n }\n }\n return ctx.render(children, {\n ...ctx,\n list,\n });\n};\n\nconst buildTable: NodeBuilder<\"table\"> = ({ children, align }, ctx) => {\n const textAlign = align?.map((a): keyof typeof AlignmentType => {\n switch (a) {\n case \"left\":\n return \"LEFT\";\n case \"right\":\n return \"RIGHT\";\n case \"center\":\n return \"CENTER\";\n default:\n return \"LEFT\";\n }\n });\n\n const columnLength = children[0]!.children.length;\n const columnWidth = ctx.width / columnLength;\n\n const options: Writeable<ITableOptions> = {\n columnWidths: Array.from({ length: columnLength }).map(() => columnWidth),\n rows: children.map((r) => {\n return new TableRow({\n children: r.children.map((c, i) => {\n return new TableCell({\n width: { size: columnWidth, type: \"dxa\" },\n children: [\n new Paragraph({\n alignment: AlignmentType[textAlign?.[i] ?? \"LEFT\"],\n children: ctx.render(c.children, {\n ...ctx,\n // https://github.com/dolanmiu/docx/blob/master/demo/22-right-to-left-text.ts\n rtl: undefined,\n }),\n }),\n ],\n });\n }),\n });\n }),\n };\n\n if (ctx.rtl) {\n options.visuallyRightToLeft = true;\n }\n\n return new Table(options);\n};\n\nconst buildText: NodeBuilder<\"text\"> = ({ value }, { deco, rtl }) => {\n const options: Writeable<IRunOptions> = {\n text: value,\n bold: deco.bold,\n italics: deco.italic,\n strike: deco.strike,\n };\n if (deco.inlineCode) {\n options.highlight = \"lightGray\";\n }\n if (deco.link) {\n // https://docx.js.org/#/usage/hyperlinks?id=styling-hyperlinks\n options.style = HYPERLINK_STYLE_ID;\n }\n if (rtl) {\n options.rightToLeft = true;\n }\n\n return new TextRun(options);\n};\n\nconst buildEmphasis: NodeBuilder<\"emphasis\"> = ({ children }, ctx) => {\n return ctx.render(children, {\n ...ctx,\n deco: { ...ctx.deco, italic: true },\n });\n};\n\nconst buildStrong: NodeBuilder<\"strong\"> = ({ children }, ctx) => {\n return ctx.render(children, {\n ...ctx,\n deco: { ...ctx.deco, bold: true },\n });\n};\n\nconst buildDelete: NodeBuilder<\"delete\"> = ({ children }, ctx) => {\n return ctx.render(children, {\n ...ctx,\n deco: { ...ctx.deco, strike: true },\n });\n};\n\nconst buildInlineCode: NodeBuilder<\"inlineCode\"> = ({ value }, ctx) => {\n return buildText(\n { type: \"text\", value },\n {\n ...ctx,\n deco: { ...ctx.deco, inlineCode: true },\n },\n );\n};\n\nconst buildBreak: NodeBuilder<\"break\"> = () => {\n return new TextRun({ text: \"\", break: 1 });\n};\n\nconst buildLink: NodeBuilder<\"link\"> = ({ children, url }, ctx) => {\n if (url.startsWith(\"#\")) {\n // TODO support anchor link\n return ctx.render(children);\n }\n return new ExternalHyperlink({\n link: url,\n children: ctx.render(children, {\n ...ctx,\n deco: { ...ctx.deco, link: true },\n }),\n });\n};\n\nconst buildLinkReference: NodeBuilder<\"linkReference\"> = (\n { children, identifier },\n ctx,\n) => {\n const def = ctx.definition(identifier);\n if (def == null) {\n return ctx.render(children);\n }\n return buildLink({ type: \"link\", children, url: def.url }, ctx);\n};\n\nconst buildFootnoteDefinition: NodeBuilder<\"footnoteDefinition\"> = (\n { children, identifier },\n ctx,\n) => {\n const contents = ctx.render(children).filter((c) => c instanceof Paragraph);\n ctx.footnote.set(ctx.footnote.id(identifier), contents);\n return null;\n};\n\nconst buildFootnoteReference: NodeBuilder<\"footnoteReference\"> = (\n { identifier },\n ctx,\n) => {\n return new FootnoteReferenceRun(ctx.footnote.id(identifier));\n};\n\nconst noop = () => {\n return null;\n};\n\nconst fallbackText = (node: { type: string; value: string }, ctx: Context) => {\n warnOnce(\n `${node.type} node is not supported without plugins, falling back to text.`,\n );\n return buildText({ type: \"text\", value: node.value }, ctx);\n};\n","import type { Plugin } from \"unified\";\nimport type { Root } from \"mdast\";\nimport { mdastToDocx, type DocxOptions } from \"./mdast-util-to-docx\";\n\nexport type { DocxOptions };\n\ndeclare module \"unified\" {\n interface CompileResultMap {\n docx: Promise<ArrayBuffer>;\n }\n}\n\nconst plugin: Plugin<[DocxOptions?], Root, Promise<ArrayBuffer>> = function (\n opts,\n) {\n this.compiler = (node) => {\n return mdastToDocx(node as Root, opts);\n };\n};\nexport default plugin;\n"],"names":["LevelFormat","AlignmentType","Paragraph","definitions","warnOnce","sectionPageSizeDefaults","sectionMarginDefaults","Document","Packer","HeadingLevel","PageBreak","TableRow","TableCell","Table","TextRun","ExternalHyperlink","FootnoteReferenceRun"],"mappings":";;;;;;;AA0CA,MAAM,eAAe,GAAG,QAAQ;AAChC,MAAM,gBAAgB,GAAG,SAAS;AAClC,MAAM,sBAAsB,GAAG,eAAe;AAC9C,MAAM,wBAAwB,GAAG,iBAAiB;AAClD,MAAM,kBAAkB,GAAG,WAAW;AAEtC,MAAM,UAAU,GAAG,CAAC,CAAS,KAAiC;AAC5D,IAAA,MAAM,WAAW,GAAG,EAAE,GAAG,EAAE;AAC3B,IAAA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,WAAW,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE;AAC9D,CAAC;AAED,MAAM,sBAAsB,GAAG,MAAuB;AACpD,IAAA,MAAM,cAAc,GAAG,IAAI,GAAG,EAAkB;AAChD,IAAA,MAAM,IAAI,GAAG,IAAI,GAAG,EAAuB;IAE3C,OAAO;AACL,QAAA,EAAE,EAAE,CAAC,EAAE,KAAI;YACT,IAAI,UAAU,GAAG,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC;AACvC,YAAA,IAAI,UAAU,IAAI,IAAI,EAAE;AACtB,gBAAA,cAAc,CAAC,GAAG,CAAC,EAAE,GAAG,UAAU,GAAG,cAAc,CAAC,IAAI,GA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AM,CAAC,CAAC,CAAC,KAAK,CAAC,YAAYb,cAAS,CAAC;AAC3E,IAAA,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC;AACvD,IAAA,OAAO,IAAI;AACb,CAAC;AAED,MAAM,sBAAsB,GAAqC,CAC/D,EAAE,UAAU,EAAE,EACd,GAAG,KACD;AACF,IAAA,OAAO,IAAIc,yBAAoB,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC;AAC9D,CAAC;AAED,MAAM,IAAI,GAAG,MAAK;AAChB,IAAA,OAAO,IAAI;AACb,CAAC;AAED,MAAM,YAAY,GAAG,CAAC,IAAqC,EAAE,GAAY,KAAI;AAC3E,IAAAZ,cAAQ,CACN,CAAA,EAAG,IAAI,CAAC,IAAI,CAAA,6DAAA,CAA+D,CAC5E;AACD,IAAA,OAAO,SAAS,CAAC,EAAgB,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,EAAE,GAAG,CAAC;AAC5D,CAAC;;AC7tBD,MAAM,MAAM,GAAuD,UACjE,IAAI,EAAA;AAEJ,IAAA,IAAI,CAAC,QAAQ,GAAG,CAAC,IAAI,KAAI;AACvB,QAAA,OAAO,WAAW,CAAC,IAAY,EAAE,IAAI,CAAC;AACxC,IAAA,CAAC;AACH;;;;"}
|
package/lib/index.js
CHANGED
|
@@ -1,36 +1,27 @@
|
|
|
1
|
-
import { sectionPageSizeDefaults, sectionMarginDefaults, Document, Packer, AlignmentType, LevelFormat, FootnoteReferenceRun, ExternalHyperlink, TextRun, Paragraph,
|
|
1
|
+
import { sectionPageSizeDefaults, sectionMarginDefaults, Document, Packer, AlignmentType, LevelFormat, FootnoteReferenceRun, ExternalHyperlink, TextRun, Paragraph, TableRow, TableCell, Table, PageBreak, HeadingLevel } from 'docx';
|
|
2
|
+
import { w as warnOnce } from './utils-BWBt3EKb.js';
|
|
2
3
|
import { definitions } from 'mdast-util-definitions';
|
|
3
|
-
|
|
4
|
-
const alreadyWarned = {};
|
|
5
|
-
/**
|
|
6
|
-
* @internal
|
|
7
|
-
*/
|
|
8
|
-
function warnOnce(message, cond = false) {
|
|
9
|
-
if (!cond && !alreadyWarned[message]) {
|
|
10
|
-
alreadyWarned[message] = true;
|
|
11
|
-
console.warn(message);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
4
|
+
import deepmerge from 'deepmerge';
|
|
14
5
|
|
|
15
6
|
const BULLET_LIST_REF = "bullet";
|
|
16
7
|
const ORDERED_LIST_REF = "ordered";
|
|
17
8
|
const COMPLETE_TASK_LIST_REF = "task-complete";
|
|
18
9
|
const INCOMPLETE_TASK_LIST_REF = "task-incomplete";
|
|
19
10
|
const HYPERLINK_STYLE_ID = "Hyperlink";
|
|
20
|
-
const
|
|
11
|
+
const calcIndent = (i) => {
|
|
12
|
+
const INDENT_UNIT = 10 * 40;
|
|
13
|
+
return { hanging: INDENT_UNIT, left: INDENT_UNIT * (i + 1) };
|
|
14
|
+
};
|
|
21
15
|
const createFootnoteRegistry = () => {
|
|
22
16
|
const idToInternalId = new Map();
|
|
23
17
|
const defs = new Map();
|
|
24
|
-
const getId = (id) => {
|
|
25
|
-
let internalId = idToInternalId.get(id);
|
|
26
|
-
if (internalId == null) {
|
|
27
|
-
idToInternalId.set(id, (internalId = idToInternalId.size + 1));
|
|
28
|
-
}
|
|
29
|
-
return internalId;
|
|
30
|
-
};
|
|
31
18
|
return {
|
|
32
19
|
id: (id) => {
|
|
33
|
-
|
|
20
|
+
let internalId = idToInternalId.get(id);
|
|
21
|
+
if (internalId == null) {
|
|
22
|
+
idToInternalId.set(id, (internalId = idToInternalId.size + 1));
|
|
23
|
+
}
|
|
24
|
+
return internalId;
|
|
34
25
|
},
|
|
35
26
|
set: (id, def) => {
|
|
36
27
|
defs.set(id, def);
|
|
@@ -43,7 +34,7 @@ const createFootnoteRegistry = () => {
|
|
|
43
34
|
},
|
|
44
35
|
};
|
|
45
36
|
};
|
|
46
|
-
const
|
|
37
|
+
const createOrderedListRegistry = () => {
|
|
47
38
|
let counter = 1;
|
|
48
39
|
const ids = [];
|
|
49
40
|
return {
|
|
@@ -75,7 +66,6 @@ const composeBuilders = (pluginsBuilders, defaultBuilders) => {
|
|
|
75
66
|
}, defaultBuilders);
|
|
76
67
|
};
|
|
77
68
|
const buildLevels = (formats) => {
|
|
78
|
-
const INDENT_UNIT = 10 * 40;
|
|
79
69
|
return formats.map(({ format, text }, i) => {
|
|
80
70
|
return {
|
|
81
71
|
level: i,
|
|
@@ -84,15 +74,47 @@ const buildLevels = (formats) => {
|
|
|
84
74
|
alignment: AlignmentType.LEFT,
|
|
85
75
|
style: {
|
|
86
76
|
paragraph: {
|
|
87
|
-
indent:
|
|
77
|
+
indent: calcIndent(i),
|
|
88
78
|
},
|
|
89
79
|
},
|
|
90
80
|
};
|
|
91
81
|
});
|
|
92
82
|
};
|
|
93
|
-
const
|
|
83
|
+
const docxParagraph = (options, ctx) => {
|
|
84
|
+
if (ctx.quote != null) {
|
|
85
|
+
options.indent = calcIndent(ctx.quote + 1);
|
|
86
|
+
}
|
|
87
|
+
if (ctx.list) {
|
|
88
|
+
const { level, meta } = ctx.list;
|
|
89
|
+
if (meta.type === "task") {
|
|
90
|
+
options.numbering = {
|
|
91
|
+
reference: meta.checked
|
|
92
|
+
? COMPLETE_TASK_LIST_REF
|
|
93
|
+
: INCOMPLETE_TASK_LIST_REF,
|
|
94
|
+
level,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
else if (meta.type === "ordered") {
|
|
98
|
+
options.numbering = {
|
|
99
|
+
reference: meta.reference,
|
|
100
|
+
level,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
options.numbering = {
|
|
105
|
+
reference: BULLET_LIST_REF,
|
|
106
|
+
level,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (ctx.rtl) {
|
|
111
|
+
options.bidirectional = true;
|
|
112
|
+
}
|
|
113
|
+
return new Paragraph(options);
|
|
114
|
+
};
|
|
115
|
+
const mdastToDocx = async (node, { plugins = [], title, subject, creator, keywords, description, styles, size, margin, orientation, spacing, direction, background, thematicBreak = "page", orderedListFormat, } = {}) => {
|
|
94
116
|
const definition = definitions(node);
|
|
95
|
-
const
|
|
117
|
+
const ordered = createOrderedListRegistry();
|
|
96
118
|
const footnote = createFootnoteRegistry();
|
|
97
119
|
const pluginCtx = { root: node, definition };
|
|
98
120
|
const builders = composeBuilders(await Promise.all(plugins.map((p) => p(pluginCtx))), {
|
|
@@ -177,11 +199,11 @@ const mdastToDocx = async (node, { plugins = [], title, subject, creator, keywor
|
|
|
177
199
|
},
|
|
178
200
|
width: pageWidth - marginLeft - marginRight,
|
|
179
201
|
deco: {},
|
|
180
|
-
indent: 0,
|
|
181
202
|
thematicBreak,
|
|
203
|
+
rtl: direction === "rtl",
|
|
182
204
|
definition: definition,
|
|
183
205
|
footnote,
|
|
184
|
-
orderedId:
|
|
206
|
+
orderedId: ordered.createId,
|
|
185
207
|
};
|
|
186
208
|
const sections = [[]];
|
|
187
209
|
for (const n of node.children) {
|
|
@@ -207,7 +229,7 @@ const mdastToDocx = async (node, { plugins = [], title, subject, creator, keywor
|
|
|
207
229
|
]);
|
|
208
230
|
const sectionProperties = {
|
|
209
231
|
page: {
|
|
210
|
-
size: { width: pageWidth, height: pageHeight },
|
|
232
|
+
size: { width: pageWidth, height: pageHeight, orientation },
|
|
211
233
|
margin: {
|
|
212
234
|
top: marginTop,
|
|
213
235
|
left: marginLeft,
|
|
@@ -222,7 +244,15 @@ const mdastToDocx = async (node, { plugins = [], title, subject, creator, keywor
|
|
|
222
244
|
creator,
|
|
223
245
|
keywords,
|
|
224
246
|
description,
|
|
225
|
-
styles:
|
|
247
|
+
styles: deepmerge({
|
|
248
|
+
default: {
|
|
249
|
+
document: {
|
|
250
|
+
paragraph: {
|
|
251
|
+
spacing: spacing ? { after: spacing } : undefined,
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
}, styles || {}),
|
|
226
256
|
background,
|
|
227
257
|
sections: sections
|
|
228
258
|
.filter((s) => s.length)
|
|
@@ -244,7 +274,7 @@ const mdastToDocx = async (node, { plugins = [], title, subject, creator, keywor
|
|
|
244
274
|
{ text: "\u25A0", format: "BULLET" },
|
|
245
275
|
]),
|
|
246
276
|
},
|
|
247
|
-
...
|
|
277
|
+
...ordered.getIds().map((ref) => ({
|
|
248
278
|
reference: ref,
|
|
249
279
|
levels: orderedLevels,
|
|
250
280
|
})),
|
|
@@ -273,7 +303,7 @@ const mdastToDocx = async (node, { plugins = [], title, subject, creator, keywor
|
|
|
273
303
|
],
|
|
274
304
|
},
|
|
275
305
|
});
|
|
276
|
-
// HACK: docx.js has no
|
|
306
|
+
// HACK: docx.js has no option to remove default numbering definitions from .docx. So do it here for now.
|
|
277
307
|
// https://github.com/dolanmiu/docx/blob/master/src/file/numbering/numbering.ts
|
|
278
308
|
const defaultBulletKey = "default-bullet-numbering";
|
|
279
309
|
const _numbering = doc.numbering;
|
|
@@ -282,40 +312,9 @@ const mdastToDocx = async (node, { plugins = [], title, subject, creator, keywor
|
|
|
282
312
|
return Packer.toArrayBuffer(doc);
|
|
283
313
|
};
|
|
284
314
|
const buildParagraph = ({ children }, ctx) => {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
children: nodes,
|
|
289
|
-
};
|
|
290
|
-
if (ctx.indent > 0) {
|
|
291
|
-
options.indent = {
|
|
292
|
-
start: convertInchesToTwip(INDENT * ctx.indent),
|
|
293
|
-
};
|
|
294
|
-
}
|
|
295
|
-
if (list) {
|
|
296
|
-
const { level, meta } = list;
|
|
297
|
-
if (meta.type === "task") {
|
|
298
|
-
options.numbering = {
|
|
299
|
-
reference: meta.checked
|
|
300
|
-
? COMPLETE_TASK_LIST_REF
|
|
301
|
-
: INCOMPLETE_TASK_LIST_REF,
|
|
302
|
-
level,
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
else if (meta.type === "ordered") {
|
|
306
|
-
options.numbering = {
|
|
307
|
-
reference: meta.reference,
|
|
308
|
-
level,
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
else {
|
|
312
|
-
options.numbering = {
|
|
313
|
-
reference: BULLET_LIST_REF,
|
|
314
|
-
level,
|
|
315
|
-
};
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
return new Paragraph(options);
|
|
315
|
+
return docxParagraph({
|
|
316
|
+
children: ctx.render(children),
|
|
317
|
+
}, ctx);
|
|
319
318
|
};
|
|
320
319
|
const buildHeading = ({ children, depth }, ctx) => {
|
|
321
320
|
let level;
|
|
@@ -339,22 +338,29 @@ const buildHeading = ({ children, depth }, ctx) => {
|
|
|
339
338
|
level = "HEADING_5";
|
|
340
339
|
break;
|
|
341
340
|
}
|
|
342
|
-
return
|
|
341
|
+
return docxParagraph({
|
|
343
342
|
heading: HeadingLevel[level],
|
|
344
343
|
children: ctx.render(children),
|
|
345
|
-
});
|
|
344
|
+
}, ctx);
|
|
346
345
|
};
|
|
347
346
|
const buildThematicBreak = (_, ctx) => {
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
347
|
+
switch (ctx.thematicBreak) {
|
|
348
|
+
case "page": {
|
|
349
|
+
return new Paragraph({ children: [new PageBreak()] });
|
|
350
|
+
}
|
|
351
|
+
case "section": {
|
|
352
|
+
// Returning empty array at toplevel means section insertion.
|
|
353
|
+
return [];
|
|
354
|
+
}
|
|
355
|
+
case "line": {
|
|
356
|
+
return new Paragraph({ thematicBreak: true });
|
|
357
|
+
}
|
|
351
358
|
}
|
|
352
|
-
return new Paragraph({ children: [new PageBreak()] });
|
|
353
359
|
};
|
|
354
360
|
const buildBlockquote = ({ children }, ctx) => {
|
|
355
361
|
return ctx.render(children, {
|
|
356
362
|
...ctx,
|
|
357
|
-
|
|
363
|
+
quote: ctx.quote == null ? 0 : ctx.quote + 1,
|
|
358
364
|
});
|
|
359
365
|
};
|
|
360
366
|
const buildList = ({ children, ordered }, ctx) => {
|
|
@@ -413,7 +419,7 @@ const buildTable = ({ children, align }, ctx) => {
|
|
|
413
419
|
});
|
|
414
420
|
const columnLength = children[0].children.length;
|
|
415
421
|
const columnWidth = ctx.width / columnLength;
|
|
416
|
-
|
|
422
|
+
const options = {
|
|
417
423
|
columnWidths: Array.from({ length: columnLength }).map(() => columnWidth),
|
|
418
424
|
rows: children.map((r) => {
|
|
419
425
|
return new TableRow({
|
|
@@ -424,16 +430,24 @@ const buildTable = ({ children, align }, ctx) => {
|
|
|
424
430
|
children: [
|
|
425
431
|
new Paragraph({
|
|
426
432
|
alignment: AlignmentType[(_a = textAlign === null || textAlign === void 0 ? void 0 : textAlign[i]) !== null && _a !== void 0 ? _a : "LEFT"],
|
|
427
|
-
children: ctx.render(c.children
|
|
433
|
+
children: ctx.render(c.children, {
|
|
434
|
+
...ctx,
|
|
435
|
+
// https://github.com/dolanmiu/docx/blob/master/demo/22-right-to-left-text.ts
|
|
436
|
+
rtl: undefined,
|
|
437
|
+
}),
|
|
428
438
|
}),
|
|
429
439
|
],
|
|
430
440
|
});
|
|
431
441
|
}),
|
|
432
442
|
});
|
|
433
443
|
}),
|
|
434
|
-
}
|
|
444
|
+
};
|
|
445
|
+
if (ctx.rtl) {
|
|
446
|
+
options.visuallyRightToLeft = true;
|
|
447
|
+
}
|
|
448
|
+
return new Table(options);
|
|
435
449
|
};
|
|
436
|
-
const buildText = ({ value }, { deco }) => {
|
|
450
|
+
const buildText = ({ value }, { deco, rtl }) => {
|
|
437
451
|
const options = {
|
|
438
452
|
text: value,
|
|
439
453
|
bold: deco.bold,
|
|
@@ -447,6 +461,9 @@ const buildText = ({ value }, { deco }) => {
|
|
|
447
461
|
// https://docx.js.org/#/usage/hyperlinks?id=styling-hyperlinks
|
|
448
462
|
options.style = HYPERLINK_STYLE_ID;
|
|
449
463
|
}
|
|
464
|
+
if (rtl) {
|
|
465
|
+
options.rightToLeft = true;
|
|
466
|
+
}
|
|
450
467
|
return new TextRun(options);
|
|
451
468
|
};
|
|
452
469
|
const buildEmphasis = ({ children }, ctx) => {
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/src/utils.ts","../src/src/mdast-util-to-docx.ts","../src/src/plugin.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","import {\n convertInchesToTwip,\n Packer,\n Document,\n Paragraph,\n Table,\n TableRow,\n TableCell,\n TextRun,\n ExternalHyperlink,\n HeadingLevel,\n LevelFormat,\n AlignmentType,\n type ILevelsOptions,\n FootnoteReferenceRun,\n type IPropertiesOptions,\n sectionPageSizeDefaults,\n sectionMarginDefaults,\n type IRunOptions,\n type IParagraphOptions,\n PageBreak,\n type ISectionPropertiesOptions,\n} from \"docx\";\nimport type * as mdast from \"mdast\";\nimport { warnOnce } from \"./utils\";\nimport { definitions } from \"mdast-util-definitions\";\nimport type {\n Context,\n DocxChild,\n DocxContent,\n FootnoteRegistry,\n ListContext,\n NodeBuilder,\n NodeBuilders,\n RemarkDocxPlugin,\n ThematicBreakType,\n Writeable,\n} from \"./types\";\n\nconst BULLET_LIST_REF = \"bullet\";\nconst ORDERED_LIST_REF = \"ordered\";\nconst COMPLETE_TASK_LIST_REF = \"task-complete\";\nconst INCOMPLETE_TASK_LIST_REF = \"task-incomplete\";\nconst HYPERLINK_STYLE_ID = \"Hyperlink\";\nconst INDENT = 0.5;\n\nconst createFootnoteRegistry = (): FootnoteRegistry => {\n const idToInternalId = new Map<string, number>();\n const defs = new Map<number, Paragraph[]>();\n\n const getId = (id: string): number => {\n let internalId = idToInternalId.get(id);\n if (internalId == null) {\n idToInternalId.set(id, (internalId = idToInternalId.size + 1));\n }\n return internalId;\n };\n\n return {\n id: (id) => {\n return getId(id);\n },\n set: (id, def) => {\n defs.set(id, def);\n },\n toConfig: () => {\n return defs.entries().reduce(\n (acc, [key, def]) => {\n acc[key] = { children: def };\n return acc;\n },\n {} as {\n [key: string]: { children: Paragraph[] };\n },\n );\n },\n };\n};\n\ntype ListFormat = {\n format: keyof typeof LevelFormat;\n text: string;\n};\n\ntype NumberingRegistry = {\n createId: () => string;\n getIds: () => string[];\n};\nconst createNumberingRegistry = (): NumberingRegistry => {\n let counter = 1;\n\n const ids: string[] = [];\n\n return {\n createId: () => {\n const id = `${ORDERED_LIST_REF}-${counter++}`;\n ids.push(id);\n return id;\n },\n getIds: () => {\n return ids;\n },\n };\n};\n\nconst composeBuilders = (\n pluginsBuilders: readonly NodeBuilders[],\n defaultBuilders: NodeBuilders,\n): NodeBuilders => {\n return pluginsBuilders.reduceRight<NodeBuilders>((acc, p) => {\n type Key = keyof typeof p;\n for (const [k, cur] of Object.entries(p)) {\n const prev = acc[k as Key];\n acc[k as Key] = (\n prev\n ? (n, c) => {\n const r = cur(n as any, c);\n if (r) {\n return r;\n }\n return prev(n as any, c);\n }\n : cur\n ) as NodeBuilder<any>;\n }\n return acc;\n }, defaultBuilders);\n};\n\nconst buildLevels = (formats: readonly ListFormat[]): ILevelsOptions[] => {\n const INDENT_UNIT = 10 * 40;\n return formats.map(({ format, text }, i) => {\n return {\n level: i,\n format: LevelFormat[format],\n text: text,\n alignment: AlignmentType.LEFT,\n style: {\n paragraph: {\n indent: { hanging: INDENT_UNIT, left: INDENT_UNIT * (i + 1) },\n },\n },\n };\n });\n};\n\nexport interface DocxOptions extends Pick<\n IPropertiesOptions,\n | \"title\"\n | \"subject\"\n | \"creator\"\n | \"keywords\"\n | \"description\"\n | \"styles\"\n | \"background\"\n> {\n /**\n * Page size defined in twip (1 twip == 1/1440 inch).\n * @default A4 ({@link sectionPageSizeDefaults})\n */\n size?: { width?: number; height?: number };\n /**\n * Page margin defined in twip (1 twip == 1/1440 inch).\n * @default 1 inch ({@link sectionMarginDefaults})\n */\n margin?: { top?: number; left?: number; bottom?: number; right?: number };\n /**\n * An option to override the text format of ordered list.\n * See https://docx.js.org/#/usage/numbering?id=level-options for more details.\n */\n orderedListFormat?: ListFormat[];\n /**\n * An option to select how thematicBreak works. \"page\" is Page Break. \"section\" is Section Break.\n * @default \"page\"\n */\n thematicBreak?: ThematicBreakType;\n /**\n * Plugins to customize how mdast nodes are compiled.\n */\n plugins?: RemarkDocxPlugin[];\n}\n\nexport const mdastToDocx = async (\n node: mdast.Root,\n {\n plugins = [],\n title,\n subject,\n creator,\n keywords,\n description,\n styles,\n size,\n margin,\n background,\n thematicBreak = \"page\",\n orderedListFormat,\n }: DocxOptions = {},\n): Promise<ArrayBuffer> => {\n const definition = definitions(node);\n\n const numbering = createNumberingRegistry();\n const footnote = createFootnoteRegistry();\n\n const pluginCtx = { root: node, definition };\n\n const builders = composeBuilders(\n await Promise.all(plugins.map((p) => p(pluginCtx))),\n {\n paragraph: buildParagraph,\n heading: buildHeading,\n thematicBreak: buildThematicBreak,\n blockquote: buildBlockquote,\n list: buildList,\n listItem: buildListItem,\n table: buildTable,\n tableRow: noop,\n tableCell: noop,\n html: fallbackText,\n code: fallbackText,\n definition: noop,\n footnoteDefinition: buildFootnoteDefinition,\n text: buildText,\n emphasis: buildEmphasis,\n strong: buildStrong,\n delete: buildDelete,\n inlineCode: buildInlineCode,\n break: buildBreak,\n link: buildLink,\n linkReference: buildLinkReference,\n // image: warnImage,\n // imageReference: warnImage,\n footnoteReference: buildFootnoteReference,\n math: fallbackText,\n inlineMath: fallbackText,\n },\n );\n\n const renderNode = (\n node: mdast.RootContent,\n c: Context,\n ): DocxContent[] | null => {\n const builder = builders[node.type];\n if (!builder) {\n warnOnce(`${node.type} node is not supported without plugins.`);\n return null;\n }\n const r = builder(node as any, c);\n if (r) {\n if (Array.isArray(r)) {\n return r;\n } else {\n return [r];\n }\n }\n return null;\n };\n\n let { WIDTH: pageWidth, HEIGHT: pageHeight } = sectionPageSizeDefaults;\n if (size) {\n if (size.width != null) {\n pageWidth = size.width;\n }\n if (size.height != null) {\n pageHeight = size.height;\n }\n }\n let {\n TOP: marginTop,\n LEFT: marginLeft,\n BOTTOM: marginBottom,\n RIGHT: marginRight,\n } = sectionMarginDefaults;\n if (margin) {\n if (margin.top != null) {\n marginTop = margin.top;\n }\n if (margin.left != null) {\n marginLeft = margin.left;\n }\n if (margin.bottom != null) {\n marginBottom = margin.bottom;\n }\n if (margin.right != null) {\n marginRight = margin.right;\n }\n }\n\n const ctx: Context = {\n render(nodes, c) {\n const results: DocxContent[] = [];\n for (const node of nodes) {\n const r = renderNode(node, c ?? this);\n if (r) {\n results.push(...r);\n }\n }\n return results;\n },\n width: pageWidth - marginLeft - marginRight,\n deco: {},\n indent: 0,\n thematicBreak,\n definition: definition,\n footnote,\n orderedId: numbering.createId,\n };\n\n const sections: DocxContent[][] = [[]];\n for (const n of node.children) {\n const r = renderNode(n, ctx);\n if (r) {\n if (!r.length) {\n // thematicBreak\n sections.push([]);\n } else {\n const lastSection = sections[sections.length - 1]!;\n lastSection.push(...r);\n }\n }\n }\n\n const orderedLevels = buildLevels(\n orderedListFormat ?? [\n { text: \"%1.\", format: \"DECIMAL\" },\n { text: \"%2.\", format: \"DECIMAL\" },\n { text: \"%3.\", format: \"DECIMAL\" },\n { text: \"%4.\", format: \"DECIMAL\" },\n { text: \"%5.\", format: \"DECIMAL\" },\n { text: \"%6.\", format: \"DECIMAL\" },\n ],\n );\n\n const sectionProperties: ISectionPropertiesOptions = {\n page: {\n size: { width: pageWidth, height: pageHeight },\n margin: {\n top: marginTop,\n left: marginLeft,\n bottom: marginBottom,\n right: marginRight,\n },\n },\n };\n\n const doc = new Document({\n title,\n subject,\n creator,\n keywords,\n description,\n styles: styles,\n background,\n sections: sections\n .filter((s) => s.length)\n .map((s) => ({\n properties: sectionProperties,\n children: s as DocxChild[],\n })),\n footnotes: footnote.toConfig(),\n numbering: {\n config: [\n {\n reference: BULLET_LIST_REF,\n levels: buildLevels([\n { text: \"\\u25CF\", format: \"BULLET\" },\n { text: \"\\u25CB\", format: \"BULLET\" },\n { text: \"\\u25A0\", format: \"BULLET\" },\n { text: \"\\u25CF\", format: \"BULLET\" },\n { text: \"\\u25CB\", format: \"BULLET\" },\n { text: \"\\u25A0\", format: \"BULLET\" },\n ]),\n },\n ...numbering.getIds().map((ref) => ({\n reference: ref,\n levels: orderedLevels,\n })),\n {\n reference: COMPLETE_TASK_LIST_REF,\n levels: buildLevels([\n { text: \"\\u2611\", format: \"BULLET\" },\n { text: \"\\u2611\", format: \"BULLET\" },\n { text: \"\\u2611\", format: \"BULLET\" },\n { text: \"\\u2611\", format: \"BULLET\" },\n { text: \"\\u2611\", format: \"BULLET\" },\n { text: \"\\u2611\", format: \"BULLET\" },\n ]),\n },\n {\n reference: INCOMPLETE_TASK_LIST_REF,\n levels: buildLevels([\n { text: \"\\u2610\", format: \"BULLET\" },\n { text: \"\\u2610\", format: \"BULLET\" },\n { text: \"\\u2610\", format: \"BULLET\" },\n { text: \"\\u2610\", format: \"BULLET\" },\n { text: \"\\u2610\", format: \"BULLET\" },\n { text: \"\\u2610\", format: \"BULLET\" },\n ]),\n },\n ],\n },\n });\n\n // HACK: docx.js has no way to remove default numberings styles from .docx. So do it here for now.\n // https://github.com/dolanmiu/docx/blob/master/src/file/numbering/numbering.ts\n const defaultBulletKey = \"default-bullet-numbering\";\n const _numbering = (doc as any).numbering;\n _numbering.abstractNumberingMap.delete(defaultBulletKey);\n _numbering.concreteNumberingMap.delete(defaultBulletKey);\n\n return Packer.toArrayBuffer(doc);\n};\n\nconst buildParagraph: NodeBuilder<\"paragraph\"> = ({ children }, ctx) => {\n const list = ctx.list;\n const nodes = ctx.render(children);\n\n const options: Writeable<IParagraphOptions> = {\n children: nodes,\n };\n\n if (ctx.indent > 0) {\n options.indent = {\n start: convertInchesToTwip(INDENT * ctx.indent),\n };\n }\n\n if (list) {\n const { level, meta } = list;\n if (meta.type === \"task\") {\n options.numbering = {\n reference: meta.checked\n ? COMPLETE_TASK_LIST_REF\n : INCOMPLETE_TASK_LIST_REF,\n level,\n };\n } else if (meta.type === \"ordered\") {\n options.numbering = {\n reference: meta.reference,\n level,\n };\n } else {\n options.numbering = {\n reference: BULLET_LIST_REF,\n level,\n };\n }\n }\n\n return new Paragraph(options);\n};\n\nconst buildHeading: NodeBuilder<\"heading\"> = ({ children, depth }, ctx) => {\n let level: keyof typeof HeadingLevel;\n switch (depth) {\n case 1:\n level = \"TITLE\";\n break;\n case 2:\n level = \"HEADING_1\";\n break;\n case 3:\n level = \"HEADING_2\";\n break;\n case 4:\n level = \"HEADING_3\";\n break;\n case 5:\n level = \"HEADING_4\";\n break;\n case 6:\n level = \"HEADING_5\";\n break;\n }\n return new Paragraph({\n heading: HeadingLevel[level],\n children: ctx.render(children),\n });\n};\n\nconst buildThematicBreak: NodeBuilder<\"thematicBreak\"> = (_, ctx) => {\n if (ctx.thematicBreak === \"section\") {\n // Returning empty array at toplevel means section insertion.\n return [];\n }\n return new Paragraph({ children: [new PageBreak()] });\n};\n\nconst buildBlockquote: NodeBuilder<\"blockquote\"> = ({ children }, ctx) => {\n return ctx.render(children, {\n ...ctx,\n indent: ctx.indent + 1,\n });\n};\n\nconst buildList: NodeBuilder<\"list\"> = ({ children, ordered }, ctx) => {\n const parentList = ctx.list;\n\n let meta: ListContext[\"meta\"];\n if (ordered) {\n meta = {\n type: \"ordered\",\n reference:\n parentList && parentList.meta.type === \"ordered\"\n ? parentList.meta.reference\n : ctx.orderedId(),\n };\n } else {\n meta = { type: \"bullet\" };\n }\n\n return ctx.render(children, {\n ...ctx,\n list: {\n level: !parentList ? 0 : parentList.level + 1,\n meta,\n },\n });\n};\n\nconst buildListItem: NodeBuilder<\"listItem\"> = ({ children, checked }, ctx) => {\n let list = ctx.list;\n if (list) {\n // listItem must be the child of list\n if (checked != null) {\n list = {\n level: list.level,\n meta: {\n type: \"task\",\n checked,\n },\n };\n }\n }\n return ctx.render(children, {\n ...ctx,\n list,\n });\n};\n\nconst buildTable: NodeBuilder<\"table\"> = ({ children, align }, ctx) => {\n const textAlign = align?.map((a): keyof typeof AlignmentType => {\n switch (a) {\n case \"left\":\n return \"LEFT\";\n case \"right\":\n return \"RIGHT\";\n case \"center\":\n return \"CENTER\";\n default:\n return \"LEFT\";\n }\n });\n\n const columnLength = children[0]!.children.length;\n const columnWidth = ctx.width / columnLength;\n\n return new Table({\n columnWidths: Array.from({ length: columnLength }).map(() => columnWidth),\n rows: children.map((r) => {\n return new TableRow({\n children: r.children.map((c, i) => {\n return new TableCell({\n width: { size: columnWidth, type: \"dxa\" },\n children: [\n new Paragraph({\n alignment: AlignmentType[textAlign?.[i] ?? \"LEFT\"],\n children: ctx.render(c.children),\n }),\n ],\n });\n }),\n });\n }),\n });\n};\n\nconst buildText: NodeBuilder<\"text\"> = ({ value }, { deco }) => {\n const options: Writeable<IRunOptions> = {\n text: value,\n bold: deco.bold,\n italics: deco.italic,\n strike: deco.strike,\n };\n if (deco.inlineCode) {\n options.highlight = \"lightGray\";\n }\n if (deco.link) {\n // https://docx.js.org/#/usage/hyperlinks?id=styling-hyperlinks\n options.style = HYPERLINK_STYLE_ID;\n }\n return new TextRun(options);\n};\n\nconst buildEmphasis: NodeBuilder<\"emphasis\"> = ({ children }, ctx) => {\n return ctx.render(children, {\n ...ctx,\n deco: { ...ctx.deco, italic: true },\n });\n};\n\nconst buildStrong: NodeBuilder<\"strong\"> = ({ children }, ctx) => {\n return ctx.render(children, {\n ...ctx,\n deco: { ...ctx.deco, bold: true },\n });\n};\n\nconst buildDelete: NodeBuilder<\"delete\"> = ({ children }, ctx) => {\n return ctx.render(children, {\n ...ctx,\n deco: { ...ctx.deco, strike: true },\n });\n};\n\nconst buildInlineCode: NodeBuilder<\"inlineCode\"> = ({ value }, ctx) => {\n return buildText(\n { type: \"text\", value },\n {\n ...ctx,\n deco: { ...ctx.deco, inlineCode: true },\n },\n );\n};\n\nconst buildBreak: NodeBuilder<\"break\"> = () => {\n return new TextRun({ text: \"\", break: 1 });\n};\n\nconst buildLink: NodeBuilder<\"link\"> = ({ children, url }, ctx) => {\n if (url.startsWith(\"#\")) {\n // TODO support anchor link\n return ctx.render(children);\n }\n return new ExternalHyperlink({\n link: url,\n children: ctx.render(children, {\n ...ctx,\n deco: { ...ctx.deco, link: true },\n }),\n });\n};\n\nconst buildLinkReference: NodeBuilder<\"linkReference\"> = (\n { children, identifier },\n ctx,\n) => {\n const def = ctx.definition(identifier);\n if (def == null) {\n return ctx.render(children);\n }\n return buildLink({ type: \"link\", children, url: def.url }, ctx);\n};\n\nconst buildFootnoteDefinition: NodeBuilder<\"footnoteDefinition\"> = (\n { children, identifier },\n ctx,\n) => {\n const contents = ctx.render(children).filter((c) => c instanceof Paragraph);\n ctx.footnote.set(ctx.footnote.id(identifier), contents);\n return null;\n};\n\nconst buildFootnoteReference: NodeBuilder<\"footnoteReference\"> = (\n { identifier },\n ctx,\n) => {\n return new FootnoteReferenceRun(ctx.footnote.id(identifier));\n};\n\nconst noop = () => {\n return null;\n};\n\nconst fallbackText = (node: { type: string; value: string }, ctx: Context) => {\n warnOnce(\n `${node.type} node is not supported without plugins, falling back to text.`,\n );\n return buildText({ type: \"text\", value: node.value }, ctx);\n};\n","import type { Plugin } from \"unified\";\nimport type { Root } from \"mdast\";\nimport { mdastToDocx, type DocxOptions } from \"./mdast-util-to-docx\";\n\nexport type { DocxOptions };\n\ndeclare module \"unified\" {\n interface CompileResultMap {\n docx: Promise<ArrayBuffer>;\n }\n}\n\nconst plugin: Plugin<[DocxOptions?], Root, Promise<ArrayBuffer>> = function (\n opts,\n) {\n this.compiler = (node) => {\n return mdastToDocx(node as Root, opts);\n };\n};\nexport default plugin;\n"],"names":[],"mappings":";;;AAAA,MAAM,aAAa,GAAmC,EAAE;AAExD;;AAEG;SACa,QAAQ,CAAC,OAAe,EAAE,OAAgB,KAAK,EAAA;IAC7D,IAAI,CAAC,IAAI,IAAI,CAAC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AM,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,YAAY,SAAS,CAAC;AAC3E,IAAA,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC;AACvD,IAAA,OAAO,IAAI;AACb,CAAC;AAED,MAAM,sBAAsB,GAAqC,CAC/D,EAAE,UAAU,EAAE,EACd,GAAG,KACD;AACF,IAAA,OAAO,IAAI,oBAAoB,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC;AAC9D,CAAC;AAED,MAAM,IAAI,GAAG,MAAK;AAChB,IAAA,OAAO,IAAI;AACb,CAAC;AAED,MAAM,YAAY,GAAG,CAAC,IAAqC,EAAE,GAAY,KAAI;AAC3E,IAAA,QAAQ,CACN,CAAA,EAAG,IAAI,CAAC,IAAI,CAAA,6DAAA,CAA+D,CAC5E;AACD,IAAA,OAAO,SAAS,CAAC,EAAgB,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,EAAE,GAAG,CAAC;AAC5D,CAAC;;AC3pBD,MAAM,MAAM,GAAuD,UACjE,IAAI,EAAA;AAEJ,IAAA,IAAI,CAAC,QAAQ,GAAG,CAAC,IAAI,KAAI;AACvB,QAAA,OAAO,WAAW,CAAC,IAAY,EAAE,IAAI,CAAC;AACxC,IAAA,CAAC;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/mdast-util-to-docx.ts","../src/plugin.ts"],"sourcesContent":["import {\n Packer,\n Document,\n Paragraph,\n Table,\n TableRow,\n TableCell,\n TextRun,\n ExternalHyperlink,\n HeadingLevel,\n LevelFormat,\n AlignmentType,\n type ILevelsOptions,\n FootnoteReferenceRun,\n type IPropertiesOptions,\n sectionPageSizeDefaults,\n sectionMarginDefaults,\n type IRunOptions,\n type IParagraphOptions,\n PageBreak,\n type ISectionPropertiesOptions,\n type IIndentAttributesProperties,\n type IStylesOptions,\n type ITableOptions,\n} from \"docx\";\nimport type * as mdast from \"mdast\";\nimport { warnOnce } from \"./utils\";\nimport { definitions } from \"mdast-util-definitions\";\nimport deepmerge from \"deepmerge\";\nimport type {\n Context,\n DocxChild,\n DocxContent,\n FootnoteRegistry,\n ListContext,\n NodeBuilder,\n NodeBuilders,\n RemarkDocxPlugin,\n ThematicBreakType,\n Writeable,\n} from \"./types\";\n\nconst BULLET_LIST_REF = \"bullet\";\nconst ORDERED_LIST_REF = \"ordered\";\nconst COMPLETE_TASK_LIST_REF = \"task-complete\";\nconst INCOMPLETE_TASK_LIST_REF = \"task-incomplete\";\nconst HYPERLINK_STYLE_ID = \"Hyperlink\";\n\nconst calcIndent = (i: number): IIndentAttributesProperties => {\n const INDENT_UNIT = 10 * 40;\n return { hanging: INDENT_UNIT, left: INDENT_UNIT * (i + 1) };\n};\n\nconst createFootnoteRegistry = (): FootnoteRegistry => {\n const idToInternalId = new Map<string, number>();\n const defs = new Map<number, Paragraph[]>();\n\n return {\n id: (id) => {\n let internalId = idToInternalId.get(id);\n if (internalId == null) {\n idToInternalId.set(id, (internalId = idToInternalId.size + 1));\n }\n return internalId;\n },\n set: (id, def) => {\n defs.set(id, def);\n },\n toConfig: () => {\n return defs.entries().reduce(\n (acc, [key, def]) => {\n acc[key] = { children: def };\n return acc;\n },\n {} as {\n [key: string]: { children: Paragraph[] };\n },\n );\n },\n };\n};\n\ntype ListFormat = {\n format: keyof typeof LevelFormat;\n text: string;\n};\n\ntype OrderedListRegistry = {\n createId: () => string;\n getIds: () => string[];\n};\nconst createOrderedListRegistry = (): OrderedListRegistry => {\n let counter = 1;\n\n const ids: string[] = [];\n\n return {\n createId: () => {\n const id = `${ORDERED_LIST_REF}-${counter++}`;\n ids.push(id);\n return id;\n },\n getIds: () => {\n return ids;\n },\n };\n};\n\nconst composeBuilders = (\n pluginsBuilders: readonly NodeBuilders[],\n defaultBuilders: NodeBuilders,\n): NodeBuilders => {\n return pluginsBuilders.reduceRight<NodeBuilders>((acc, p) => {\n type Key = keyof typeof p;\n for (const [k, cur] of Object.entries(p)) {\n const prev = acc[k as Key];\n acc[k as Key] = (\n prev\n ? (n, c) => {\n const r = cur(n as any, c);\n if (r) {\n return r;\n }\n return prev(n as any, c);\n }\n : cur\n ) as NodeBuilder<any>;\n }\n return acc;\n }, defaultBuilders);\n};\n\nconst buildLevels = (formats: readonly ListFormat[]): ILevelsOptions[] => {\n return formats.map(({ format, text }, i) => {\n return {\n level: i,\n format: LevelFormat[format],\n text: text,\n alignment: AlignmentType.LEFT,\n style: {\n paragraph: {\n indent: calcIndent(i),\n },\n },\n };\n });\n};\n\nconst docxParagraph = (\n options: Writeable<IParagraphOptions>,\n ctx: Context,\n): Paragraph => {\n if (ctx.quote != null) {\n options.indent = calcIndent(ctx.quote + 1);\n }\n\n if (ctx.list) {\n const { level, meta } = ctx.list;\n if (meta.type === \"task\") {\n options.numbering = {\n reference: meta.checked\n ? COMPLETE_TASK_LIST_REF\n : INCOMPLETE_TASK_LIST_REF,\n level,\n };\n } else if (meta.type === \"ordered\") {\n options.numbering = {\n reference: meta.reference,\n level,\n };\n } else {\n options.numbering = {\n reference: BULLET_LIST_REF,\n level,\n };\n }\n }\n\n if (ctx.rtl) {\n options.bidirectional = true;\n }\n\n return new Paragraph(options);\n};\n\nexport interface DocxOptions extends Pick<\n IPropertiesOptions,\n | \"title\"\n | \"subject\"\n | \"creator\"\n | \"keywords\"\n | \"description\"\n | \"styles\"\n | \"background\"\n> {\n /**\n * Page size defined in twip (1 twip == 1/1440 inch).\n * @default A4 ({@link sectionPageSizeDefaults})\n */\n size?: { width?: number; height?: number };\n /**\n * Page margin defined in twip (1 twip == 1/1440 inch).\n * @default 1 inch ({@link sectionMarginDefaults})\n */\n margin?: { top?: number; left?: number; bottom?: number; right?: number };\n /**\n * Page orientation.\n * @default \"portrait\"\n */\n orientation?: \"portrait\" | \"landscape\";\n /**\n * Spacing after Paragraphs in twip (1 twip == 1/1440 inch).\n * @default 0\n */\n spacing?: number;\n /**\n * Direction of texts.\n * @default \"ltr\"\n */\n direction?: \"ltr\" | \"rtl\";\n /**\n * An option to override the text format of ordered list.\n * See https://docx.js.org/#/usage/numbering?id=level-options for more details.\n */\n orderedListFormat?: ListFormat[];\n /**\n * An option to select how thematicBreak works.\n *\n * - \"page\": Page Break\n * - \"section\": Section Break\n * - \"line\": Horizontal line\n * @default \"page\"\n */\n thematicBreak?: ThematicBreakType;\n /**\n * Plugins to customize how mdast nodes are compiled.\n */\n plugins?: RemarkDocxPlugin[];\n}\n\nexport const mdastToDocx = async (\n node: mdast.Root,\n {\n plugins = [],\n title,\n subject,\n creator,\n keywords,\n description,\n styles,\n size,\n margin,\n orientation,\n spacing,\n direction,\n background,\n thematicBreak = \"page\",\n orderedListFormat,\n }: DocxOptions = {},\n): Promise<ArrayBuffer> => {\n const definition = definitions(node);\n\n const ordered = createOrderedListRegistry();\n const footnote = createFootnoteRegistry();\n\n const pluginCtx = { root: node, definition };\n\n const builders = composeBuilders(\n await Promise.all(plugins.map((p) => p(pluginCtx))),\n {\n paragraph: buildParagraph,\n heading: buildHeading,\n thematicBreak: buildThematicBreak,\n blockquote: buildBlockquote,\n list: buildList,\n listItem: buildListItem,\n table: buildTable,\n tableRow: noop,\n tableCell: noop,\n html: fallbackText,\n code: fallbackText,\n definition: noop,\n footnoteDefinition: buildFootnoteDefinition,\n text: buildText,\n emphasis: buildEmphasis,\n strong: buildStrong,\n delete: buildDelete,\n inlineCode: buildInlineCode,\n break: buildBreak,\n link: buildLink,\n linkReference: buildLinkReference,\n // image: warnImage,\n // imageReference: warnImage,\n footnoteReference: buildFootnoteReference,\n math: fallbackText,\n inlineMath: fallbackText,\n },\n );\n\n const renderNode = (\n node: mdast.RootContent,\n c: Context,\n ): DocxContent[] | null => {\n const builder = builders[node.type];\n if (!builder) {\n warnOnce(`${node.type} node is not supported without plugins.`);\n return null;\n }\n const r = builder(node as any, c);\n if (r) {\n if (Array.isArray(r)) {\n return r;\n } else {\n return [r];\n }\n }\n return null;\n };\n\n let { WIDTH: pageWidth, HEIGHT: pageHeight } = sectionPageSizeDefaults;\n if (size) {\n if (size.width != null) {\n pageWidth = size.width;\n }\n if (size.height != null) {\n pageHeight = size.height;\n }\n }\n let {\n TOP: marginTop,\n LEFT: marginLeft,\n BOTTOM: marginBottom,\n RIGHT: marginRight,\n } = sectionMarginDefaults;\n if (margin) {\n if (margin.top != null) {\n marginTop = margin.top;\n }\n if (margin.left != null) {\n marginLeft = margin.left;\n }\n if (margin.bottom != null) {\n marginBottom = margin.bottom;\n }\n if (margin.right != null) {\n marginRight = margin.right;\n }\n }\n\n const ctx: Context = {\n render(nodes, c) {\n const results: DocxContent[] = [];\n for (const node of nodes) {\n const r = renderNode(node, c ?? this);\n if (r) {\n results.push(...r);\n }\n }\n return results;\n },\n width: pageWidth - marginLeft - marginRight,\n deco: {},\n thematicBreak,\n rtl: direction === \"rtl\",\n definition: definition,\n footnote,\n orderedId: ordered.createId,\n };\n\n const sections: DocxContent[][] = [[]];\n for (const n of node.children) {\n const r = renderNode(n, ctx);\n if (r) {\n if (!r.length) {\n // thematicBreak\n sections.push([]);\n } else {\n const lastSection = sections[sections.length - 1]!;\n lastSection.push(...r);\n }\n }\n }\n\n const orderedLevels = buildLevels(\n orderedListFormat ?? [\n { text: \"%1.\", format: \"DECIMAL\" },\n { text: \"%2.\", format: \"DECIMAL\" },\n { text: \"%3.\", format: \"DECIMAL\" },\n { text: \"%4.\", format: \"DECIMAL\" },\n { text: \"%5.\", format: \"DECIMAL\" },\n { text: \"%6.\", format: \"DECIMAL\" },\n ],\n );\n\n const sectionProperties: ISectionPropertiesOptions = {\n page: {\n size: { width: pageWidth, height: pageHeight, orientation },\n margin: {\n top: marginTop,\n left: marginLeft,\n bottom: marginBottom,\n right: marginRight,\n },\n },\n };\n\n const doc = new Document({\n title,\n subject,\n creator,\n keywords,\n description,\n styles: deepmerge<IStylesOptions>(\n {\n default: {\n document: {\n paragraph: {\n spacing: spacing ? { after: spacing } : undefined,\n },\n },\n },\n },\n styles || {},\n ),\n background,\n sections: sections\n .filter((s) => s.length)\n .map((s) => ({\n properties: sectionProperties,\n children: s as DocxChild[],\n })),\n footnotes: footnote.toConfig(),\n numbering: {\n config: [\n {\n reference: BULLET_LIST_REF,\n levels: buildLevels([\n { text: \"\\u25CF\", format: \"BULLET\" },\n { text: \"\\u25CB\", format: \"BULLET\" },\n { text: \"\\u25A0\", format: \"BULLET\" },\n { text: \"\\u25CF\", format: \"BULLET\" },\n { text: \"\\u25CB\", format: \"BULLET\" },\n { text: \"\\u25A0\", format: \"BULLET\" },\n ]),\n },\n ...ordered.getIds().map((ref) => ({\n reference: ref,\n levels: orderedLevels,\n })),\n {\n reference: COMPLETE_TASK_LIST_REF,\n levels: buildLevels([\n { text: \"\\u2611\", format: \"BULLET\" },\n { text: \"\\u2611\", format: \"BULLET\" },\n { text: \"\\u2611\", format: \"BULLET\" },\n { text: \"\\u2611\", format: \"BULLET\" },\n { text: \"\\u2611\", format: \"BULLET\" },\n { text: \"\\u2611\", format: \"BULLET\" },\n ]),\n },\n {\n reference: INCOMPLETE_TASK_LIST_REF,\n levels: buildLevels([\n { text: \"\\u2610\", format: \"BULLET\" },\n { text: \"\\u2610\", format: \"BULLET\" },\n { text: \"\\u2610\", format: \"BULLET\" },\n { text: \"\\u2610\", format: \"BULLET\" },\n { text: \"\\u2610\", format: \"BULLET\" },\n { text: \"\\u2610\", format: \"BULLET\" },\n ]),\n },\n ],\n },\n });\n\n // HACK: docx.js has no option to remove default numbering definitions from .docx. So do it here for now.\n // https://github.com/dolanmiu/docx/blob/master/src/file/numbering/numbering.ts\n const defaultBulletKey = \"default-bullet-numbering\";\n const _numbering = (doc as any).numbering;\n _numbering.abstractNumberingMap.delete(defaultBulletKey);\n _numbering.concreteNumberingMap.delete(defaultBulletKey);\n\n return Packer.toArrayBuffer(doc);\n};\n\nconst buildParagraph: NodeBuilder<\"paragraph\"> = ({ children }, ctx) => {\n return docxParagraph(\n {\n children: ctx.render(children),\n },\n ctx,\n );\n};\n\nconst buildHeading: NodeBuilder<\"heading\"> = ({ children, depth }, ctx) => {\n let level: keyof typeof HeadingLevel;\n switch (depth) {\n case 1:\n level = \"TITLE\";\n break;\n case 2:\n level = \"HEADING_1\";\n break;\n case 3:\n level = \"HEADING_2\";\n break;\n case 4:\n level = \"HEADING_3\";\n break;\n case 5:\n level = \"HEADING_4\";\n break;\n case 6:\n level = \"HEADING_5\";\n break;\n }\n return docxParagraph(\n {\n heading: HeadingLevel[level],\n children: ctx.render(children),\n },\n ctx,\n );\n};\n\nconst buildThematicBreak: NodeBuilder<\"thematicBreak\"> = (_, ctx) => {\n switch (ctx.thematicBreak) {\n case \"page\": {\n return new Paragraph({ children: [new PageBreak()] });\n }\n case \"section\": {\n // Returning empty array at toplevel means section insertion.\n return [];\n }\n case \"line\": {\n return new Paragraph({ thematicBreak: true });\n }\n }\n};\n\nconst buildBlockquote: NodeBuilder<\"blockquote\"> = ({ children }, ctx) => {\n return ctx.render(children, {\n ...ctx,\n quote: ctx.quote == null ? 0 : ctx.quote + 1,\n });\n};\n\nconst buildList: NodeBuilder<\"list\"> = ({ children, ordered }, ctx) => {\n const parentList = ctx.list;\n\n let meta: ListContext[\"meta\"];\n if (ordered) {\n meta = {\n type: \"ordered\",\n reference:\n parentList && parentList.meta.type === \"ordered\"\n ? parentList.meta.reference\n : ctx.orderedId(),\n };\n } else {\n meta = { type: \"bullet\" };\n }\n\n return ctx.render(children, {\n ...ctx,\n list: {\n level: !parentList ? 0 : parentList.level + 1,\n meta,\n },\n });\n};\n\nconst buildListItem: NodeBuilder<\"listItem\"> = ({ children, checked }, ctx) => {\n let list = ctx.list;\n if (list) {\n // listItem must be the child of list\n if (checked != null) {\n list = {\n level: list.level,\n meta: {\n type: \"task\",\n checked,\n },\n };\n }\n }\n return ctx.render(children, {\n ...ctx,\n list,\n });\n};\n\nconst buildTable: NodeBuilder<\"table\"> = ({ children, align }, ctx) => {\n const textAlign = align?.map((a): keyof typeof AlignmentType => {\n switch (a) {\n case \"left\":\n return \"LEFT\";\n case \"right\":\n return \"RIGHT\";\n case \"center\":\n return \"CENTER\";\n default:\n return \"LEFT\";\n }\n });\n\n const columnLength = children[0]!.children.length;\n const columnWidth = ctx.width / columnLength;\n\n const options: Writeable<ITableOptions> = {\n columnWidths: Array.from({ length: columnLength }).map(() => columnWidth),\n rows: children.map((r) => {\n return new TableRow({\n children: r.children.map((c, i) => {\n return new TableCell({\n width: { size: columnWidth, type: \"dxa\" },\n children: [\n new Paragraph({\n alignment: AlignmentType[textAlign?.[i] ?? \"LEFT\"],\n children: ctx.render(c.children, {\n ...ctx,\n // https://github.com/dolanmiu/docx/blob/master/demo/22-right-to-left-text.ts\n rtl: undefined,\n }),\n }),\n ],\n });\n }),\n });\n }),\n };\n\n if (ctx.rtl) {\n options.visuallyRightToLeft = true;\n }\n\n return new Table(options);\n};\n\nconst buildText: NodeBuilder<\"text\"> = ({ value }, { deco, rtl }) => {\n const options: Writeable<IRunOptions> = {\n text: value,\n bold: deco.bold,\n italics: deco.italic,\n strike: deco.strike,\n };\n if (deco.inlineCode) {\n options.highlight = \"lightGray\";\n }\n if (deco.link) {\n // https://docx.js.org/#/usage/hyperlinks?id=styling-hyperlinks\n options.style = HYPERLINK_STYLE_ID;\n }\n if (rtl) {\n options.rightToLeft = true;\n }\n\n return new TextRun(options);\n};\n\nconst buildEmphasis: NodeBuilder<\"emphasis\"> = ({ children }, ctx) => {\n return ctx.render(children, {\n ...ctx,\n deco: { ...ctx.deco, italic: true },\n });\n};\n\nconst buildStrong: NodeBuilder<\"strong\"> = ({ children }, ctx) => {\n return ctx.render(children, {\n ...ctx,\n deco: { ...ctx.deco, bold: true },\n });\n};\n\nconst buildDelete: NodeBuilder<\"delete\"> = ({ children }, ctx) => {\n return ctx.render(children, {\n ...ctx,\n deco: { ...ctx.deco, strike: true },\n });\n};\n\nconst buildInlineCode: NodeBuilder<\"inlineCode\"> = ({ value }, ctx) => {\n return buildText(\n { type: \"text\", value },\n {\n ...ctx,\n deco: { ...ctx.deco, inlineCode: true },\n },\n );\n};\n\nconst buildBreak: NodeBuilder<\"break\"> = () => {\n return new TextRun({ text: \"\", break: 1 });\n};\n\nconst buildLink: NodeBuilder<\"link\"> = ({ children, url }, ctx) => {\n if (url.startsWith(\"#\")) {\n // TODO support anchor link\n return ctx.render(children);\n }\n return new ExternalHyperlink({\n link: url,\n children: ctx.render(children, {\n ...ctx,\n deco: { ...ctx.deco, link: true },\n }),\n });\n};\n\nconst buildLinkReference: NodeBuilder<\"linkReference\"> = (\n { children, identifier },\n ctx,\n) => {\n const def = ctx.definition(identifier);\n if (def == null) {\n return ctx.render(children);\n }\n return buildLink({ type: \"link\", children, url: def.url }, ctx);\n};\n\nconst buildFootnoteDefinition: NodeBuilder<\"footnoteDefinition\"> = (\n { children, identifier },\n ctx,\n) => {\n const contents = ctx.render(children).filter((c) => c instanceof Paragraph);\n ctx.footnote.set(ctx.footnote.id(identifier), contents);\n return null;\n};\n\nconst buildFootnoteReference: NodeBuilder<\"footnoteReference\"> = (\n { identifier },\n ctx,\n) => {\n return new FootnoteReferenceRun(ctx.footnote.id(identifier));\n};\n\nconst noop = () => {\n return null;\n};\n\nconst fallbackText = (node: { type: string; value: string }, ctx: Context) => {\n warnOnce(\n `${node.type} node is not supported without plugins, falling back to text.`,\n );\n return buildText({ type: \"text\", value: node.value }, ctx);\n};\n","import type { Plugin } from \"unified\";\nimport type { Root } from \"mdast\";\nimport { mdastToDocx, type DocxOptions } from \"./mdast-util-to-docx\";\n\nexport type { DocxOptions };\n\ndeclare module \"unified\" {\n interface CompileResultMap {\n docx: Promise<ArrayBuffer>;\n }\n}\n\nconst plugin: Plugin<[DocxOptions?], Root, Promise<ArrayBuffer>> = function (\n opts,\n) {\n this.compiler = (node) => {\n return mdastToDocx(node as Root, opts);\n };\n};\nexport default plugin;\n"],"names":[],"mappings":";;;;;AA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,CAAA,EAAG,IAAI,CAAC,IAAI,CAAA,6DAAA,CAA+D,CAC5E;AACD,IAAA,OAAO,SAAS,CAAC,EAAgB,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,EAAE,GAAG,CAAC;AAC5D,CAAC;;AC7tBD,MAAM,MAAM,GAAuD,UACjE,IAAI,EAAA;AAEJ,IAAA,IAAI,CAAC,QAAQ,GAAG,CAAC,IAAI,KAAI;AACvB,QAAA,OAAO,WAAW,CAAC,IAAY,EAAE,IAAI,CAAC;AACxC,IAAA,CAAC;AACH;;;;"}
|
|
@@ -24,13 +24,32 @@ export interface DocxOptions extends Pick<IPropertiesOptions, "title" | "subject
|
|
|
24
24
|
bottom?: number;
|
|
25
25
|
right?: number;
|
|
26
26
|
};
|
|
27
|
+
/**
|
|
28
|
+
* Page orientation.
|
|
29
|
+
* @default "portrait"
|
|
30
|
+
*/
|
|
31
|
+
orientation?: "portrait" | "landscape";
|
|
32
|
+
/**
|
|
33
|
+
* Spacing after Paragraphs in twip (1 twip == 1/1440 inch).
|
|
34
|
+
* @default 0
|
|
35
|
+
*/
|
|
36
|
+
spacing?: number;
|
|
37
|
+
/**
|
|
38
|
+
* Direction of texts.
|
|
39
|
+
* @default "ltr"
|
|
40
|
+
*/
|
|
41
|
+
direction?: "ltr" | "rtl";
|
|
27
42
|
/**
|
|
28
43
|
* An option to override the text format of ordered list.
|
|
29
44
|
* See https://docx.js.org/#/usage/numbering?id=level-options for more details.
|
|
30
45
|
*/
|
|
31
46
|
orderedListFormat?: ListFormat[];
|
|
32
47
|
/**
|
|
33
|
-
* An option to select how thematicBreak works.
|
|
48
|
+
* An option to select how thematicBreak works.
|
|
49
|
+
*
|
|
50
|
+
* - "page": Page Break
|
|
51
|
+
* - "section": Section Break
|
|
52
|
+
* - "line": Horizontal line
|
|
34
53
|
* @default "page"
|
|
35
54
|
*/
|
|
36
55
|
thematicBreak?: ThematicBreakType;
|
|
@@ -39,5 +58,5 @@ export interface DocxOptions extends Pick<IPropertiesOptions, "title" | "subject
|
|
|
39
58
|
*/
|
|
40
59
|
plugins?: RemarkDocxPlugin[];
|
|
41
60
|
}
|
|
42
|
-
export declare const mdastToDocx: (node: mdast.Root, { plugins, title, subject, creator, keywords, description, styles, size, margin, background, thematicBreak, orderedListFormat, }?: DocxOptions) => Promise<ArrayBuffer>;
|
|
61
|
+
export declare const mdastToDocx: (node: mdast.Root, { plugins, title, subject, creator, keywords, description, styles, size, margin, orientation, spacing, direction, background, thematicBreak, orderedListFormat, }?: DocxOptions) => Promise<ArrayBuffer>;
|
|
43
62
|
export {};
|
|
@@ -100,7 +100,7 @@ const imagePlugin = ({ load = loadWithFetch, fallbackSvg = browserSvgToPng, } =
|
|
|
100
100
|
promises.set(url, (async () => {
|
|
101
101
|
let data;
|
|
102
102
|
try {
|
|
103
|
-
data = await load(url);
|
|
103
|
+
data = (await load(url));
|
|
104
104
|
}
|
|
105
105
|
catch (e) {
|
|
106
106
|
utils.warnOnce(`Failed to load image: ${url} ${e}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../../src/plugins/image/index.ts"],"sourcesContent":["import { warnOnce } from \"../../utils\";\nimport type { RemarkDocxPlugin } from \"../../types\";\nimport type * as mdast from \"mdast\";\nimport { ImageRun } from \"docx\";\nimport { visit } from \"unist-util-visit\";\nimport { imageSize } from \"image-size\";\n\nconst supportedTypes = [\"png\", \"jpg\", \"gif\", \"bmp\", \"svg\"] as const;\n\ntype SupportedImageType = (typeof supportedTypes)[number];\n\ntype ImageData = Readonly<\n {\n data: ArrayBuffer;\n width: number;\n height: number;\n } & (\n | { type: Exclude<SupportedImageType, \"svg\"> }\n | {\n type: Extract<SupportedImageType, \"svg\">;\n fallback: ArrayBuffer;\n }\n )\n>;\n\nconst buildImage = (\n image: ImageData,\n node: { alt?: string | null; title?: string | null },\n) => {\n const altText =\n node.alt || node.title\n ? {\n name: \"\",\n description: node.alt ?? undefined,\n title: node.title ?? undefined,\n }\n : undefined;\n\n if (image.type === \"svg\") {\n const { type, data, width, height, fallback } = image;\n return new ImageRun({\n type: type,\n data: data,\n transformation: {\n width,\n height,\n },\n // https://github.com/dolanmiu/docx/issues/1162#issuecomment-3228368003\n fallback: { type: \"png\", data: fallback },\n altText,\n });\n }\n\n const { type, data, width, height } = image;\n return new ImageRun({\n type: type,\n data: data,\n transformation: {\n width,\n height,\n },\n altText,\n });\n};\n\nconst 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\ntype LoadFn = (url: string) => Promise<ArrayBuffer>;\n\ntype SvgToPngFn = (options: {\n buffer: ArrayBuffer;\n width: number;\n height: number;\n}) => Promise<ArrayBufferLike>;\n\nconst loadWithFetch: LoadFn = async (url) => {\n const res = await fetch(url);\n return res.arrayBuffer();\n};\n\nconst browserSvgToPng: SvgToPngFn = async ({ buffer, width, height }) => {\n const svgBlob = new Blob([buffer], { type: \"image/svg+xml\" });\n const url = URL.createObjectURL(svgBlob);\n\n try {\n const img = new Image();\n img.src = url;\n await img.decode();\n\n const dpr = window.devicePixelRatio;\n\n const canvas = document.createElement(\"canvas\");\n const scaledWidth = width * dpr;\n const scaledHeight = height * dpr;\n canvas.width = scaledWidth;\n canvas.height = scaledHeight;\n const ctx = canvas.getContext(\"2d\")!;\n ctx.drawImage(img, 0, 0, scaledWidth, scaledHeight);\n\n return new Promise<ArrayBuffer>((resolve) => {\n canvas.toBlob((blob) => {\n blob!.arrayBuffer().then(resolve);\n }, \"image/png\");\n });\n } finally {\n URL.revokeObjectURL(url);\n }\n};\n\nexport interface ImagePluginOptions {\n /**\n * A function to resolve image data from url.\n * @default {@link loadWithFetch}\n */\n load?: LoadFn;\n /**\n * A function to convert SVG to PNG. According to the docx specifications, embedding SVG images also requires including PNG.\n * @default {@link browserSvgToPng}, which handles conversion only on browser\n */\n fallbackSvg?: SvgToPngFn;\n}\n\n/**\n * A plugin to render \"image\" nodes\n */\nexport const imagePlugin = ({\n load = loadWithFetch,\n fallbackSvg = browserSvgToPng,\n}: ImagePluginOptions = {}): RemarkDocxPlugin => {\n const images = new Map<string, ImageData>();\n\n return async ({ root, definition }) => {\n const imageList: (mdast.Image | mdast.Definition)[] = [];\n visit(root, \"image\", (node) => {\n imageList.push(node);\n });\n visit(root, \"imageReference\", (node) => {\n const maybeImage = definition(node.identifier)!;\n if (maybeImage) {\n imageList.push(maybeImage);\n }\n });\n\n if (imageList.length !== 0) {\n const promises = new Map<string, Promise<void>>();\n imageList.forEach(({ url }) => {\n if (!images.has(url) && !promises.has(url)) {\n promises.set(\n url,\n (async () => {\n let data: ArrayBuffer;\n try {\n data = await load(url);\n } catch (e) {\n warnOnce(`Failed to load image: ${url} ${e}`);\n return;\n }\n\n const { width, height, type } = imageSize(new Uint8Array(data));\n if (!isSupportedType(type)) {\n warnOnce(`Not supported image type: ${type}`);\n return;\n }\n\n if (type === \"svg\") {\n try {\n const fallback = await fallbackSvg({\n buffer: data,\n width,\n height,\n });\n images.set(url, {\n type,\n width,\n height,\n data,\n fallback: fallback as ArrayBuffer,\n });\n } catch (e) {\n warnOnce(`Failed to create fallback image: ${url} ${e}`);\n return;\n }\n } else {\n images.set(url, { type, width, height, data });\n }\n })(),\n );\n }\n });\n\n await Promise.all(promises.values());\n }\n\n return {\n image: (node) => {\n const data = images.get(node.url);\n if (!data) {\n return null;\n }\n return buildImage(data, node);\n },\n imageReference: (node) => {\n const def = definition(node.identifier);\n if (def == null) {\n return null;\n }\n const data = images.get(def.url);\n if (!data) {\n return null;\n }\n return buildImage(data, { alt: node.alt, title: def.title });\n },\n };\n };\n};\n"],"names":["ImageRun","visit","warnOnce","imageSize"],"mappings":";;;;;;;AAOA,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAU;AAkBnE,MAAM,UAAU,GAAG,CACjB,KAAgB,EAChB,IAAoD,KAClD;;IACF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;gBACvB,MAAM,GAAG,GAAG,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC;AACvC,gBAAA,IAAI,GAAG,IAAI,IAAI,EAAE;AACf,oBAAA,OAAO,IAAI;gBACb;gBACA,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC;gBAChC,IAAI,CAAC,IAAI,EAAE;AACT,oBAAA,OAAO,IAAI;gBACb;AACA,gBAAA,OAAO,UAAU,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,CAAC;YAC9D,CAAC;SACF;AACH,IAAA,CAAC;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../../src/plugins/image/index.ts"],"sourcesContent":["import { warnOnce } from \"../../utils\";\nimport type { RemarkDocxPlugin } from \"../../types\";\nimport type * as mdast from \"mdast\";\nimport { ImageRun } from \"docx\";\nimport { visit } from \"unist-util-visit\";\nimport { imageSize } from \"image-size\";\n\nconst supportedTypes = [\"png\", \"jpg\", \"gif\", \"bmp\", \"svg\"] as const;\n\ntype SupportedImageType = (typeof supportedTypes)[number];\n\ntype ImageData = Readonly<\n {\n data: ArrayBuffer;\n width: number;\n height: number;\n } & (\n | { type: Exclude<SupportedImageType, \"svg\"> }\n | {\n type: Extract<SupportedImageType, \"svg\">;\n fallback: ArrayBuffer;\n }\n )\n>;\n\nconst buildImage = (\n image: ImageData,\n node: { alt?: string | null; title?: string | null },\n) => {\n const altText =\n node.alt || node.title\n ? {\n name: \"\",\n description: node.alt ?? undefined,\n title: node.title ?? undefined,\n }\n : undefined;\n\n if (image.type === \"svg\") {\n const { type, data, width, height, fallback } = image;\n return new ImageRun({\n type: type,\n data: data,\n transformation: {\n width,\n height,\n },\n // https://github.com/dolanmiu/docx/issues/1162#issuecomment-3228368003\n fallback: { type: \"png\", data: fallback },\n altText,\n });\n }\n\n const { type, data, width, height } = image;\n return new ImageRun({\n type: type,\n data: data,\n transformation: {\n width,\n height,\n },\n altText,\n });\n};\n\nconst 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\ntype LoadFn = (url: string) => Promise<ArrayBufferLike>;\n\ntype SvgToPngFn = (options: {\n buffer: ArrayBuffer;\n width: number;\n height: number;\n}) => Promise<ArrayBufferLike>;\n\nconst loadWithFetch: LoadFn = async (url) => {\n const res = await fetch(url);\n return res.arrayBuffer();\n};\n\nconst browserSvgToPng: SvgToPngFn = async ({ buffer, width, height }) => {\n const svgBlob = new Blob([buffer], { type: \"image/svg+xml\" });\n const url = URL.createObjectURL(svgBlob);\n\n try {\n const img = new Image();\n img.src = url;\n await img.decode();\n\n const dpr = window.devicePixelRatio;\n\n const canvas = document.createElement(\"canvas\");\n const scaledWidth = width * dpr;\n const scaledHeight = height * dpr;\n canvas.width = scaledWidth;\n canvas.height = scaledHeight;\n const ctx = canvas.getContext(\"2d\")!;\n ctx.drawImage(img, 0, 0, scaledWidth, scaledHeight);\n\n return new Promise<ArrayBuffer>((resolve) => {\n canvas.toBlob((blob) => {\n blob!.arrayBuffer().then(resolve);\n }, \"image/png\");\n });\n } finally {\n URL.revokeObjectURL(url);\n }\n};\n\nexport interface ImagePluginOptions {\n /**\n * A function to resolve image data from url.\n * @default {@link loadWithFetch}\n */\n load?: LoadFn;\n /**\n * A function to convert SVG to PNG. According to the docx specifications, embedding SVG images also requires including PNG.\n * @default {@link browserSvgToPng}, which handles conversion only on browser\n */\n fallbackSvg?: SvgToPngFn;\n}\n\n/**\n * A plugin to render \"image\" nodes\n */\nexport const imagePlugin = ({\n load = loadWithFetch,\n fallbackSvg = browserSvgToPng,\n}: ImagePluginOptions = {}): RemarkDocxPlugin => {\n const images = new Map<string, ImageData>();\n\n return async ({ root, definition }) => {\n const imageList: (mdast.Image | mdast.Definition)[] = [];\n visit(root, \"image\", (node) => {\n imageList.push(node);\n });\n visit(root, \"imageReference\", (node) => {\n const maybeImage = definition(node.identifier)!;\n if (maybeImage) {\n imageList.push(maybeImage);\n }\n });\n\n if (imageList.length !== 0) {\n const promises = new Map<string, Promise<void>>();\n imageList.forEach(({ url }) => {\n if (!images.has(url) && !promises.has(url)) {\n promises.set(\n url,\n (async () => {\n let data: ArrayBuffer;\n try {\n data = (await load(url)) as ArrayBuffer;\n } catch (e) {\n warnOnce(`Failed to load image: ${url} ${e}`);\n return;\n }\n\n const { width, height, type } = imageSize(new Uint8Array(data));\n if (!isSupportedType(type)) {\n warnOnce(`Not supported image type: ${type}`);\n return;\n }\n\n if (type === \"svg\") {\n try {\n const fallback = await fallbackSvg({\n buffer: data,\n width,\n height,\n });\n images.set(url, {\n type,\n width,\n height,\n data,\n fallback: fallback as ArrayBuffer,\n });\n } catch (e) {\n warnOnce(`Failed to create fallback image: ${url} ${e}`);\n return;\n }\n } else {\n images.set(url, { type, width, height, data });\n }\n })(),\n );\n }\n });\n\n await Promise.all(promises.values());\n }\n\n return {\n image: (node) => {\n const data = images.get(node.url);\n if (!data) {\n return null;\n }\n return buildImage(data, node);\n },\n imageReference: (node) => {\n const def = definition(node.identifier);\n if (def == null) {\n return null;\n }\n const data = images.get(def.url);\n if (!data) {\n return null;\n }\n return buildImage(data, { alt: node.alt, title: def.title });\n },\n };\n };\n};\n"],"names":["ImageRun","visit","warnOnce","imageSize"],"mappings":";;;;;;;AAOA,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAU;AAkBnE,MAAM,UAAU,GAAG,CACjB,KAAgB,EAChB,IAAoD,KAClD;;IACF,MAAM,OAAO,GACX,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC;AACf,UAAE;AACE,YAAA,IAAI,EAAE,EAAE;AACR,YAAA,WAAW,EAAE,CAAA,EAAA,GAAA,IAAI,CAAC,GAAG,mCAAI,SAAS;AAClC,YAAA,KAAK,E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GAAG,CAAC,GAAG,CAAC;gBAChC,IAAI,CAAC,IAAI,EAAE;AACT,oBAAA,OAAO,IAAI;gBACb;AACA,gBAAA,OAAO,UAAU,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,CAAC;YAC9D,CAAC;SACF;AACH,IAAA,CAAC;AACH;;;;"}
|
|
@@ -98,7 +98,7 @@ const imagePlugin = ({ load = loadWithFetch, fallbackSvg = browserSvgToPng, } =
|
|
|
98
98
|
promises.set(url, (async () => {
|
|
99
99
|
let data;
|
|
100
100
|
try {
|
|
101
|
-
data = await load(url);
|
|
101
|
+
data = (await load(url));
|
|
102
102
|
}
|
|
103
103
|
catch (e) {
|
|
104
104
|
warnOnce(`Failed to load image: ${url} ${e}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/plugins/image/index.ts"],"sourcesContent":["import { warnOnce } from \"../../utils\";\nimport type { RemarkDocxPlugin } from \"../../types\";\nimport type * as mdast from \"mdast\";\nimport { ImageRun } from \"docx\";\nimport { visit } from \"unist-util-visit\";\nimport { imageSize } from \"image-size\";\n\nconst supportedTypes = [\"png\", \"jpg\", \"gif\", \"bmp\", \"svg\"] as const;\n\ntype SupportedImageType = (typeof supportedTypes)[number];\n\ntype ImageData = Readonly<\n {\n data: ArrayBuffer;\n width: number;\n height: number;\n } & (\n | { type: Exclude<SupportedImageType, \"svg\"> }\n | {\n type: Extract<SupportedImageType, \"svg\">;\n fallback: ArrayBuffer;\n }\n )\n>;\n\nconst buildImage = (\n image: ImageData,\n node: { alt?: string | null; title?: string | null },\n) => {\n const altText =\n node.alt || node.title\n ? {\n name: \"\",\n description: node.alt ?? undefined,\n title: node.title ?? undefined,\n }\n : undefined;\n\n if (image.type === \"svg\") {\n const { type, data, width, height, fallback } = image;\n return new ImageRun({\n type: type,\n data: data,\n transformation: {\n width,\n height,\n },\n // https://github.com/dolanmiu/docx/issues/1162#issuecomment-3228368003\n fallback: { type: \"png\", data: fallback },\n altText,\n });\n }\n\n const { type, data, width, height } = image;\n return new ImageRun({\n type: type,\n data: data,\n transformation: {\n width,\n height,\n },\n altText,\n });\n};\n\nconst 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\ntype LoadFn = (url: string) => Promise<ArrayBuffer>;\n\ntype SvgToPngFn = (options: {\n buffer: ArrayBuffer;\n width: number;\n height: number;\n}) => Promise<ArrayBufferLike>;\n\nconst loadWithFetch: LoadFn = async (url) => {\n const res = await fetch(url);\n return res.arrayBuffer();\n};\n\nconst browserSvgToPng: SvgToPngFn = async ({ buffer, width, height }) => {\n const svgBlob = new Blob([buffer], { type: \"image/svg+xml\" });\n const url = URL.createObjectURL(svgBlob);\n\n try {\n const img = new Image();\n img.src = url;\n await img.decode();\n\n const dpr = window.devicePixelRatio;\n\n const canvas = document.createElement(\"canvas\");\n const scaledWidth = width * dpr;\n const scaledHeight = height * dpr;\n canvas.width = scaledWidth;\n canvas.height = scaledHeight;\n const ctx = canvas.getContext(\"2d\")!;\n ctx.drawImage(img, 0, 0, scaledWidth, scaledHeight);\n\n return new Promise<ArrayBuffer>((resolve) => {\n canvas.toBlob((blob) => {\n blob!.arrayBuffer().then(resolve);\n }, \"image/png\");\n });\n } finally {\n URL.revokeObjectURL(url);\n }\n};\n\nexport interface ImagePluginOptions {\n /**\n * A function to resolve image data from url.\n * @default {@link loadWithFetch}\n */\n load?: LoadFn;\n /**\n * A function to convert SVG to PNG. According to the docx specifications, embedding SVG images also requires including PNG.\n * @default {@link browserSvgToPng}, which handles conversion only on browser\n */\n fallbackSvg?: SvgToPngFn;\n}\n\n/**\n * A plugin to render \"image\" nodes\n */\nexport const imagePlugin = ({\n load = loadWithFetch,\n fallbackSvg = browserSvgToPng,\n}: ImagePluginOptions = {}): RemarkDocxPlugin => {\n const images = new Map<string, ImageData>();\n\n return async ({ root, definition }) => {\n const imageList: (mdast.Image | mdast.Definition)[] = [];\n visit(root, \"image\", (node) => {\n imageList.push(node);\n });\n visit(root, \"imageReference\", (node) => {\n const maybeImage = definition(node.identifier)!;\n if (maybeImage) {\n imageList.push(maybeImage);\n }\n });\n\n if (imageList.length !== 0) {\n const promises = new Map<string, Promise<void>>();\n imageList.forEach(({ url }) => {\n if (!images.has(url) && !promises.has(url)) {\n promises.set(\n url,\n (async () => {\n let data: ArrayBuffer;\n try {\n data = await load(url);\n } catch (e) {\n warnOnce(`Failed to load image: ${url} ${e}`);\n return;\n }\n\n const { width, height, type } = imageSize(new Uint8Array(data));\n if (!isSupportedType(type)) {\n warnOnce(`Not supported image type: ${type}`);\n return;\n }\n\n if (type === \"svg\") {\n try {\n const fallback = await fallbackSvg({\n buffer: data,\n width,\n height,\n });\n images.set(url, {\n type,\n width,\n height,\n data,\n fallback: fallback as ArrayBuffer,\n });\n } catch (e) {\n warnOnce(`Failed to create fallback image: ${url} ${e}`);\n return;\n }\n } else {\n images.set(url, { type, width, height, data });\n }\n })(),\n );\n }\n });\n\n await Promise.all(promises.values());\n }\n\n return {\n image: (node) => {\n const data = images.get(node.url);\n if (!data) {\n return null;\n }\n return buildImage(data, node);\n },\n imageReference: (node) => {\n const def = definition(node.identifier);\n if (def == null) {\n return null;\n }\n const data = images.get(def.url);\n if (!data) {\n return null;\n }\n return buildImage(data, { alt: node.alt, title: def.title });\n },\n };\n };\n};\n"],"names":[],"mappings":";;;;;AAOA,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAU;AAkBnE,MAAM,UAAU,GAAG,CACjB,KAAgB,EAChB,IAAoD,KAClD;;IACF,MAAM,OAAO,GACX,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC;AACf,UAAE;AACE,YAAA,IAAI,EAAE,EAAE;AACR,YAAA,WAAW,EAAE,CAAA,EAAA,GAAA,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IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC;gBAChC,IAAI,CAAC,IAAI,EAAE;AACT,oBAAA,OAAO,IAAI;gBACb;AACA,gBAAA,OAAO,UAAU,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,CAAC;YAC9D,CAAC;SACF;AACH,IAAA,CAAC;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/plugins/image/index.ts"],"sourcesContent":["import { warnOnce } from \"../../utils\";\nimport type { RemarkDocxPlugin } from \"../../types\";\nimport type * as mdast from \"mdast\";\nimport { ImageRun } from \"docx\";\nimport { visit } from \"unist-util-visit\";\nimport { imageSize } from \"image-size\";\n\nconst supportedTypes = [\"png\", \"jpg\", \"gif\", \"bmp\", \"svg\"] as const;\n\ntype SupportedImageType = (typeof supportedTypes)[number];\n\ntype ImageData = Readonly<\n {\n data: ArrayBuffer;\n width: number;\n height: number;\n } & (\n | { type: Exclude<SupportedImageType, \"svg\"> }\n | {\n type: Extract<SupportedImageType, \"svg\">;\n fallback: ArrayBuffer;\n }\n )\n>;\n\nconst buildImage = (\n image: ImageData,\n node: { alt?: string | null; title?: string | null },\n) => {\n const altText =\n node.alt || node.title\n ? {\n name: \"\",\n description: node.alt ?? undefined,\n title: node.title ?? undefined,\n }\n : undefined;\n\n if (image.type === \"svg\") {\n const { type, data, width, height, fallback } = image;\n return new ImageRun({\n type: type,\n data: data,\n transformation: {\n width,\n height,\n },\n // https://github.com/dolanmiu/docx/issues/1162#issuecomment-3228368003\n fallback: { type: \"png\", data: fallback },\n altText,\n });\n }\n\n const { type, data, width, height } = image;\n return new ImageRun({\n type: type,\n data: data,\n transformation: {\n width,\n height,\n },\n altText,\n });\n};\n\nconst 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\ntype LoadFn = (url: string) => Promise<ArrayBufferLike>;\n\ntype SvgToPngFn = (options: {\n buffer: ArrayBuffer;\n width: number;\n height: number;\n}) => Promise<ArrayBufferLike>;\n\nconst loadWithFetch: LoadFn = async (url) => {\n const res = await fetch(url);\n return res.arrayBuffer();\n};\n\nconst browserSvgToPng: SvgToPngFn = async ({ buffer, width, height }) => {\n const svgBlob = new Blob([buffer], { type: \"image/svg+xml\" });\n const url = URL.createObjectURL(svgBlob);\n\n try {\n const img = new Image();\n img.src = url;\n await img.decode();\n\n const dpr = window.devicePixelRatio;\n\n const canvas = document.createElement(\"canvas\");\n const scaledWidth = width * dpr;\n const scaledHeight = height * dpr;\n canvas.width = scaledWidth;\n canvas.height = scaledHeight;\n const ctx = canvas.getContext(\"2d\")!;\n ctx.drawImage(img, 0, 0, scaledWidth, scaledHeight);\n\n return new Promise<ArrayBuffer>((resolve) => {\n canvas.toBlob((blob) => {\n blob!.arrayBuffer().then(resolve);\n }, \"image/png\");\n });\n } finally {\n URL.revokeObjectURL(url);\n }\n};\n\nexport interface ImagePluginOptions {\n /**\n * A function to resolve image data from url.\n * @default {@link loadWithFetch}\n */\n load?: LoadFn;\n /**\n * A function to convert SVG to PNG. According to the docx specifications, embedding SVG images also requires including PNG.\n * @default {@link browserSvgToPng}, which handles conversion only on browser\n */\n fallbackSvg?: SvgToPngFn;\n}\n\n/**\n * A plugin to render \"image\" nodes\n */\nexport const imagePlugin = ({\n load = loadWithFetch,\n fallbackSvg = browserSvgToPng,\n}: ImagePluginOptions = {}): RemarkDocxPlugin => {\n const images = new Map<string, ImageData>();\n\n return async ({ root, definition }) => {\n const imageList: (mdast.Image | mdast.Definition)[] = [];\n visit(root, \"image\", (node) => {\n imageList.push(node);\n });\n visit(root, \"imageReference\", (node) => {\n const maybeImage = definition(node.identifier)!;\n if (maybeImage) {\n imageList.push(maybeImage);\n }\n });\n\n if (imageList.length !== 0) {\n const promises = new Map<string, Promise<void>>();\n imageList.forEach(({ url }) => {\n if (!images.has(url) && !promises.has(url)) {\n promises.set(\n url,\n (async () => {\n let data: ArrayBuffer;\n try {\n data = (await load(url)) as ArrayBuffer;\n } catch (e) {\n warnOnce(`Failed to load image: ${url} ${e}`);\n return;\n }\n\n const { width, height, type } = imageSize(new Uint8Array(data));\n if (!isSupportedType(type)) {\n warnOnce(`Not supported image type: ${type}`);\n return;\n }\n\n if (type === \"svg\") {\n try {\n const fallback = await fallbackSvg({\n buffer: data,\n width,\n height,\n });\n images.set(url, {\n type,\n width,\n height,\n data,\n fallback: fallback as ArrayBuffer,\n });\n } catch (e) {\n warnOnce(`Failed to create fallback image: ${url} ${e}`);\n return;\n }\n } else {\n images.set(url, { type, width, height, data });\n }\n })(),\n );\n }\n });\n\n await Promise.all(promises.values());\n }\n\n return {\n image: (node) => {\n const data = images.get(node.url);\n if (!data) {\n return null;\n }\n return buildImage(data, node);\n },\n imageReference: (node) => {\n const def = definition(node.identifier);\n if (def == null) {\n return null;\n }\n const data = images.get(def.url);\n if (!data) {\n return null;\n }\n return buildImage(data, { alt: node.alt, title: def.title });\n },\n };\n };\n};\n"],"names":[],"mappings":";;;;;AAOA,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAU;AAkBnE,MAAM,UAAU,GAAG,CACjB,KAAgB,EAChB,IAAoD,KAClD;;IACF,MAAM,OAAO,GACX,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC;AACf,UAAE;AACE,YAAA,IAAI,EAAE,EAAE;AACR,YAAA,WAAW,EAAE,CAAA,EAAA,GAAA,IAAI,CAAC,GAAG,mCAAI,SAAS;AAClC,YAAA,KAAK,EAAE,CAAA,EAAA,GAAA,IAAI,CAAC,KAAK,mCAAI,SAAS;AAC/B;UACD,SAAS;AAEf,IAAA,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,EAAE;AACxB,QAAA,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,KA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AC,KAAK,EAAE,CAAC;YAC9D,CAAC;SACF;AACH,IAAA,CAAC;AACH;;;;"}
|
package/lib/types.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export type FootnoteRegistry = {
|
|
|
28
28
|
};
|
|
29
29
|
};
|
|
30
30
|
};
|
|
31
|
-
export type ThematicBreakType = "page" | "section";
|
|
31
|
+
export type ThematicBreakType = "page" | "section" | "line";
|
|
32
32
|
export type Context = Readonly<{
|
|
33
33
|
render: (node: readonly mdast.RootContent[], ctx?: Context) => DocxContent[];
|
|
34
34
|
}>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "remark-docx",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.21",
|
|
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",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@mathjax/src": "^4.0.0",
|
|
37
|
+
"deepmerge": "^4.3.1",
|
|
37
38
|
"docx": "9.5.1",
|
|
38
39
|
"fast-xml-parser": "^5.3.2",
|
|
39
40
|
"hast-util-from-html": "^2.0.3",
|
|
@@ -49,6 +50,7 @@
|
|
|
49
50
|
"@rollup/plugin-typescript": "^12.0.0",
|
|
50
51
|
"@storybook/react-vite": "^10.1.4",
|
|
51
52
|
"@types/adm-zip": "^0.5.0",
|
|
53
|
+
"@types/deepmerge": "^2.1.0",
|
|
52
54
|
"@types/file-saver": "^2.0.7",
|
|
53
55
|
"@types/lodash.debounce": "^4.0.9",
|
|
54
56
|
"@types/mdast": "^4.0.3",
|