remark-docx 0.0.4 → 0.0.5
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 +13 -5
- package/lib/index.js +54 -45
- package/lib/index.mjs +54 -45
- package/lib/transformer.d.ts +2 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -62,8 +62,16 @@ const text = "# hello world";
|
|
|
62
62
|
|
|
63
63
|
## Options
|
|
64
64
|
|
|
65
|
-
| Key
|
|
66
|
-
|
|
|
67
|
-
| output
|
|
68
|
-
|
|
|
69
|
-
|
|
|
65
|
+
| Key | Default | Type | Description |
|
|
66
|
+
| -------------- | --------- | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
67
|
+
| output | "buffer" | `"buffer"` `"blob"` `"raw"` | Set output type of `VFile.result`. `buffer` is `Promise<ArrayBuffer>`. `blob` is `Promise<Blob>`. `raw` is internal data for testing. |
|
|
68
|
+
| imageResolver | undefined | ImageResolver? | **You must set** if your markdown includes images. See example for [browser](https://github.com/inokawa/remark-docx/blob/main/stories/playground.stories.tsx) and [Node.js](https://github.com/inokawa/remark-docx/blob/main/src/index.spec.ts). |
|
|
69
|
+
| title | undefined | string? | |
|
|
70
|
+
| subject | undefined | string? | |
|
|
71
|
+
| creator | undefined | string? | |
|
|
72
|
+
| keywords | undefined | string? | |
|
|
73
|
+
| description | undefined | string? | |
|
|
74
|
+
| lastModifiedBy | undefined | string? | |
|
|
75
|
+
| revision | undefined | string? | |
|
|
76
|
+
| styles | undefined | IStylesOptions? | |
|
|
77
|
+
| background | undefined | IDocumentBackgroundOptions? | |
|
package/lib/index.js
CHANGED
|
@@ -155,56 +155,65 @@ var DEFAULT_NUMBERINGS = [
|
|
|
155
155
|
var error = function (message) {
|
|
156
156
|
throw new Error(message);
|
|
157
157
|
};
|
|
158
|
-
function mdastToDocx(node,
|
|
159
|
-
var _a;
|
|
160
|
-
var doc = buildDocxRoot(node, opts, images);
|
|
161
|
-
switch ((_a = opts.output) !== null && _a !== void 0 ? _a : "buffer") {
|
|
162
|
-
case "buffer":
|
|
163
|
-
return docx.Packer.toBuffer(doc);
|
|
164
|
-
case "blob":
|
|
165
|
-
return docx.Packer.toBlob(doc);
|
|
166
|
-
case "raw":
|
|
167
|
-
return doc;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
function buildDocxRoot(root, opts, images) {
|
|
158
|
+
function mdastToDocx(node, _a, images) {
|
|
159
|
+
var output = _a.output, title = _a.title, subject = _a.subject, creator = _a.creator, keywords = _a.keywords, description = _a.description, lastModifiedBy = _a.lastModifiedBy, revision = _a.revision, styles = _a.styles, background = _a.background;
|
|
171
160
|
var ctx = { deco: {}, images: images };
|
|
172
|
-
var nodes = convertNodes(
|
|
173
|
-
|
|
161
|
+
var nodes = convertNodes(node.children, ctx);
|
|
162
|
+
var doc = new docx__namespace.Document({
|
|
163
|
+
title: title,
|
|
164
|
+
subject: subject,
|
|
165
|
+
creator: creator,
|
|
166
|
+
keywords: keywords,
|
|
167
|
+
description: description,
|
|
168
|
+
lastModifiedBy: lastModifiedBy,
|
|
169
|
+
revision: revision,
|
|
170
|
+
styles: styles,
|
|
171
|
+
background: background,
|
|
172
|
+
sections: [{ children: nodes }],
|
|
173
|
+
numbering: {
|
|
174
174
|
config: [
|
|
175
175
|
{
|
|
176
176
|
reference: ORDERED_LIST_REF,
|
|
177
177
|
levels: DEFAULT_NUMBERINGS,
|
|
178
178
|
},
|
|
179
179
|
],
|
|
180
|
-
}
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
switch (output !== null && output !== void 0 ? output : "buffer") {
|
|
183
|
+
case "buffer":
|
|
184
|
+
return docx.Packer.toBuffer(doc);
|
|
185
|
+
case "blob":
|
|
186
|
+
return docx.Packer.toBlob(doc);
|
|
187
|
+
case "raw":
|
|
188
|
+
return doc;
|
|
189
|
+
}
|
|
181
190
|
}
|
|
182
|
-
function convertNodes(nodes, ctx
|
|
191
|
+
function convertNodes(nodes, ctx) {
|
|
183
192
|
var _a;
|
|
184
193
|
var results = [];
|
|
185
194
|
for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
|
|
186
195
|
var node = nodes_1[_i];
|
|
187
196
|
switch (node.type) {
|
|
188
197
|
case "paragraph":
|
|
189
|
-
results.push(buildParagraph(node, ctx
|
|
198
|
+
results.push(buildParagraph(node, ctx));
|
|
190
199
|
break;
|
|
191
200
|
case "heading":
|
|
192
|
-
results.push(buildHeading(node, ctx
|
|
201
|
+
results.push(buildHeading(node, ctx));
|
|
193
202
|
break;
|
|
194
203
|
case "thematicBreak":
|
|
195
204
|
results.push(buildThematicBreak(node));
|
|
196
205
|
break;
|
|
197
206
|
case "blockquote":
|
|
198
|
-
results.push.apply(results, buildBlockquote(node, ctx
|
|
207
|
+
results.push.apply(results, buildBlockquote(node, ctx));
|
|
199
208
|
break;
|
|
200
209
|
case "list":
|
|
201
|
-
results.push.apply(results, buildList(node, ctx
|
|
210
|
+
results.push.apply(results, buildList(node, ctx));
|
|
202
211
|
break;
|
|
203
212
|
case "listItem":
|
|
204
213
|
error("unreachable");
|
|
205
214
|
break;
|
|
206
215
|
case "table":
|
|
207
|
-
results.push(buildTable(node, ctx
|
|
216
|
+
results.push(buildTable(node, ctx));
|
|
208
217
|
break;
|
|
209
218
|
case "tableRow":
|
|
210
219
|
error("unreachable");
|
|
@@ -237,7 +246,7 @@ function convertNodes(nodes, ctx, opts) {
|
|
|
237
246
|
case "strong":
|
|
238
247
|
case "delete": {
|
|
239
248
|
var type = node.type, children = node.children;
|
|
240
|
-
results.push.apply(results, convertNodes(children, __assign(__assign({}, ctx), { deco: __assign(__assign({}, ctx.deco), (_a = {}, _a[type] = true, _a)) })
|
|
249
|
+
results.push.apply(results, convertNodes(children, __assign(__assign({}, ctx), { deco: __assign(__assign({}, ctx.deco), (_a = {}, _a[type] = true, _a)) })));
|
|
241
250
|
break;
|
|
242
251
|
}
|
|
243
252
|
case "inlineCode":
|
|
@@ -248,7 +257,7 @@ function convertNodes(nodes, ctx, opts) {
|
|
|
248
257
|
results.push(buildBreak(node));
|
|
249
258
|
break;
|
|
250
259
|
case "link":
|
|
251
|
-
results.push(buildLink(node, ctx
|
|
260
|
+
results.push(buildLink(node, ctx));
|
|
252
261
|
break;
|
|
253
262
|
case "image":
|
|
254
263
|
results.push(buildImage(node, ctx.images));
|
|
@@ -260,7 +269,7 @@ function convertNodes(nodes, ctx, opts) {
|
|
|
260
269
|
// FIXME: unimplemented
|
|
261
270
|
break;
|
|
262
271
|
case "footnote":
|
|
263
|
-
results.push(buildFootnote(node, ctx
|
|
272
|
+
results.push(buildFootnote(node, ctx));
|
|
264
273
|
break;
|
|
265
274
|
case "footnoteReference":
|
|
266
275
|
// FIXME: unimplemented
|
|
@@ -275,10 +284,10 @@ function convertNodes(nodes, ctx, opts) {
|
|
|
275
284
|
}
|
|
276
285
|
return results;
|
|
277
286
|
}
|
|
278
|
-
function buildParagraph(_a, ctx
|
|
287
|
+
function buildParagraph(_a, ctx) {
|
|
279
288
|
_a.type; var children = _a.children;
|
|
280
289
|
var list = ctx.list;
|
|
281
|
-
return new docx__namespace.Paragraph(__assign({ children: convertNodes(children, ctx
|
|
290
|
+
return new docx__namespace.Paragraph(__assign({ children: convertNodes(children, ctx) }, (list &&
|
|
282
291
|
(list.ordered
|
|
283
292
|
? {
|
|
284
293
|
numbering: {
|
|
@@ -292,7 +301,7 @@ function buildParagraph(_a, ctx, opts) {
|
|
|
292
301
|
},
|
|
293
302
|
}))));
|
|
294
303
|
}
|
|
295
|
-
function buildHeading(_a, ctx
|
|
304
|
+
function buildHeading(_a, ctx) {
|
|
296
305
|
_a.type; var children = _a.children, depth = _a.depth;
|
|
297
306
|
var heading;
|
|
298
307
|
switch (depth) {
|
|
@@ -317,7 +326,7 @@ function buildHeading(_a, ctx, opts) {
|
|
|
317
326
|
}
|
|
318
327
|
return new docx__namespace.Paragraph({
|
|
319
328
|
heading: heading,
|
|
320
|
-
children: convertNodes(children, ctx
|
|
329
|
+
children: convertNodes(children, ctx),
|
|
321
330
|
});
|
|
322
331
|
}
|
|
323
332
|
function buildThematicBreak(_a) {
|
|
@@ -326,27 +335,27 @@ function buildThematicBreak(_a) {
|
|
|
326
335
|
thematicBreak: true,
|
|
327
336
|
});
|
|
328
337
|
}
|
|
329
|
-
function buildBlockquote(_a, ctx
|
|
338
|
+
function buildBlockquote(_a, ctx) {
|
|
330
339
|
_a.type; var children = _a.children;
|
|
331
340
|
// FIXME: do nothing for now
|
|
332
|
-
return convertNodes(children, ctx
|
|
341
|
+
return convertNodes(children, ctx);
|
|
333
342
|
}
|
|
334
|
-
function buildList(_a, ctx
|
|
343
|
+
function buildList(_a, ctx) {
|
|
335
344
|
_a.type; var children = _a.children, ordered = _a.ordered; _a.start; _a.spread;
|
|
336
345
|
var list = {
|
|
337
346
|
level: ctx.list ? ctx.list.level + 1 : 0,
|
|
338
347
|
ordered: !!ordered,
|
|
339
348
|
};
|
|
340
349
|
return children.reduce(function (acc, item) {
|
|
341
|
-
acc.push.apply(acc, buildListItem(item, __assign(__assign({}, ctx), { list: list })
|
|
350
|
+
acc.push.apply(acc, buildListItem(item, __assign(__assign({}, ctx), { list: list })));
|
|
342
351
|
return acc;
|
|
343
352
|
}, []);
|
|
344
353
|
}
|
|
345
|
-
function buildListItem(_a, ctx
|
|
354
|
+
function buildListItem(_a, ctx) {
|
|
346
355
|
_a.type; var children = _a.children; _a.checked; _a.spread;
|
|
347
|
-
return convertNodes(children, ctx
|
|
356
|
+
return convertNodes(children, ctx);
|
|
348
357
|
}
|
|
349
|
-
function buildTable(_a, ctx
|
|
358
|
+
function buildTable(_a, ctx) {
|
|
350
359
|
_a.type; var children = _a.children, align = _a.align;
|
|
351
360
|
var cellAligns = align === null || align === void 0 ? void 0 : align.map(function (a) {
|
|
352
361
|
switch (a) {
|
|
@@ -362,25 +371,25 @@ function buildTable(_a, ctx, opts) {
|
|
|
362
371
|
});
|
|
363
372
|
return new docx__namespace.Table({
|
|
364
373
|
rows: children.map(function (r) {
|
|
365
|
-
return buildTableRow(r, ctx,
|
|
374
|
+
return buildTableRow(r, ctx, cellAligns);
|
|
366
375
|
}),
|
|
367
376
|
});
|
|
368
377
|
}
|
|
369
|
-
function buildTableRow(_a, ctx,
|
|
378
|
+
function buildTableRow(_a, ctx, cellAligns) {
|
|
370
379
|
_a.type; var children = _a.children;
|
|
371
380
|
return new docx__namespace.TableRow({
|
|
372
381
|
children: children.map(function (c, i) {
|
|
373
|
-
return buildTableCell(c, ctx,
|
|
382
|
+
return buildTableCell(c, ctx, cellAligns === null || cellAligns === void 0 ? void 0 : cellAligns[i]);
|
|
374
383
|
}),
|
|
375
384
|
});
|
|
376
385
|
}
|
|
377
|
-
function buildTableCell(_a, ctx,
|
|
386
|
+
function buildTableCell(_a, ctx, align) {
|
|
378
387
|
_a.type; var children = _a.children;
|
|
379
388
|
return new docx__namespace.TableCell({
|
|
380
389
|
children: [
|
|
381
390
|
new docx__namespace.Paragraph({
|
|
382
391
|
alignment: align,
|
|
383
|
-
children: convertNodes(children, ctx
|
|
392
|
+
children: convertNodes(children, ctx),
|
|
384
393
|
}),
|
|
385
394
|
],
|
|
386
395
|
});
|
|
@@ -423,11 +432,11 @@ function buildBreak(_a) {
|
|
|
423
432
|
_a.type;
|
|
424
433
|
return new docx__namespace.TextRun({ text: "", break: 1 });
|
|
425
434
|
}
|
|
426
|
-
function buildLink(_a, ctx
|
|
435
|
+
function buildLink(_a, ctx) {
|
|
427
436
|
_a.type; var children = _a.children, url = _a.url; _a.title;
|
|
428
437
|
return new docx__namespace.ExternalHyperlink({
|
|
429
438
|
link: url,
|
|
430
|
-
children: convertNodes(children, ctx
|
|
439
|
+
children: convertNodes(children, ctx),
|
|
431
440
|
});
|
|
432
441
|
}
|
|
433
442
|
function buildImage(_a, images) {
|
|
@@ -444,11 +453,11 @@ function buildImage(_a, images) {
|
|
|
444
453
|
},
|
|
445
454
|
});
|
|
446
455
|
}
|
|
447
|
-
function buildFootnote(_a, ctx
|
|
456
|
+
function buildFootnote(_a, ctx) {
|
|
448
457
|
_a.type; var children = _a.children;
|
|
449
458
|
// FIXME: transform to paragraph for now
|
|
450
459
|
return new docx__namespace.Paragraph({
|
|
451
|
-
children: convertNodes(children, ctx
|
|
460
|
+
children: convertNodes(children, ctx),
|
|
452
461
|
});
|
|
453
462
|
}
|
|
454
463
|
|
package/lib/index.mjs
CHANGED
|
@@ -134,56 +134,65 @@ var DEFAULT_NUMBERINGS = [
|
|
|
134
134
|
var error = function (message) {
|
|
135
135
|
throw new Error(message);
|
|
136
136
|
};
|
|
137
|
-
function mdastToDocx(node,
|
|
138
|
-
var _a;
|
|
139
|
-
var doc = buildDocxRoot(node, opts, images);
|
|
140
|
-
switch ((_a = opts.output) !== null && _a !== void 0 ? _a : "buffer") {
|
|
141
|
-
case "buffer":
|
|
142
|
-
return Packer.toBuffer(doc);
|
|
143
|
-
case "blob":
|
|
144
|
-
return Packer.toBlob(doc);
|
|
145
|
-
case "raw":
|
|
146
|
-
return doc;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
function buildDocxRoot(root, opts, images) {
|
|
137
|
+
function mdastToDocx(node, _a, images) {
|
|
138
|
+
var output = _a.output, title = _a.title, subject = _a.subject, creator = _a.creator, keywords = _a.keywords, description = _a.description, lastModifiedBy = _a.lastModifiedBy, revision = _a.revision, styles = _a.styles, background = _a.background;
|
|
150
139
|
var ctx = { deco: {}, images: images };
|
|
151
|
-
var nodes = convertNodes(
|
|
152
|
-
|
|
140
|
+
var nodes = convertNodes(node.children, ctx);
|
|
141
|
+
var doc = new docx.Document({
|
|
142
|
+
title: title,
|
|
143
|
+
subject: subject,
|
|
144
|
+
creator: creator,
|
|
145
|
+
keywords: keywords,
|
|
146
|
+
description: description,
|
|
147
|
+
lastModifiedBy: lastModifiedBy,
|
|
148
|
+
revision: revision,
|
|
149
|
+
styles: styles,
|
|
150
|
+
background: background,
|
|
151
|
+
sections: [{ children: nodes }],
|
|
152
|
+
numbering: {
|
|
153
153
|
config: [
|
|
154
154
|
{
|
|
155
155
|
reference: ORDERED_LIST_REF,
|
|
156
156
|
levels: DEFAULT_NUMBERINGS,
|
|
157
157
|
},
|
|
158
158
|
],
|
|
159
|
-
}
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
switch (output !== null && output !== void 0 ? output : "buffer") {
|
|
162
|
+
case "buffer":
|
|
163
|
+
return Packer.toBuffer(doc);
|
|
164
|
+
case "blob":
|
|
165
|
+
return Packer.toBlob(doc);
|
|
166
|
+
case "raw":
|
|
167
|
+
return doc;
|
|
168
|
+
}
|
|
160
169
|
}
|
|
161
|
-
function convertNodes(nodes, ctx
|
|
170
|
+
function convertNodes(nodes, ctx) {
|
|
162
171
|
var _a;
|
|
163
172
|
var results = [];
|
|
164
173
|
for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
|
|
165
174
|
var node = nodes_1[_i];
|
|
166
175
|
switch (node.type) {
|
|
167
176
|
case "paragraph":
|
|
168
|
-
results.push(buildParagraph(node, ctx
|
|
177
|
+
results.push(buildParagraph(node, ctx));
|
|
169
178
|
break;
|
|
170
179
|
case "heading":
|
|
171
|
-
results.push(buildHeading(node, ctx
|
|
180
|
+
results.push(buildHeading(node, ctx));
|
|
172
181
|
break;
|
|
173
182
|
case "thematicBreak":
|
|
174
183
|
results.push(buildThematicBreak(node));
|
|
175
184
|
break;
|
|
176
185
|
case "blockquote":
|
|
177
|
-
results.push.apply(results, buildBlockquote(node, ctx
|
|
186
|
+
results.push.apply(results, buildBlockquote(node, ctx));
|
|
178
187
|
break;
|
|
179
188
|
case "list":
|
|
180
|
-
results.push.apply(results, buildList(node, ctx
|
|
189
|
+
results.push.apply(results, buildList(node, ctx));
|
|
181
190
|
break;
|
|
182
191
|
case "listItem":
|
|
183
192
|
error("unreachable");
|
|
184
193
|
break;
|
|
185
194
|
case "table":
|
|
186
|
-
results.push(buildTable(node, ctx
|
|
195
|
+
results.push(buildTable(node, ctx));
|
|
187
196
|
break;
|
|
188
197
|
case "tableRow":
|
|
189
198
|
error("unreachable");
|
|
@@ -216,7 +225,7 @@ function convertNodes(nodes, ctx, opts) {
|
|
|
216
225
|
case "strong":
|
|
217
226
|
case "delete": {
|
|
218
227
|
var type = node.type, children = node.children;
|
|
219
|
-
results.push.apply(results, convertNodes(children, __assign(__assign({}, ctx), { deco: __assign(__assign({}, ctx.deco), (_a = {}, _a[type] = true, _a)) })
|
|
228
|
+
results.push.apply(results, convertNodes(children, __assign(__assign({}, ctx), { deco: __assign(__assign({}, ctx.deco), (_a = {}, _a[type] = true, _a)) })));
|
|
220
229
|
break;
|
|
221
230
|
}
|
|
222
231
|
case "inlineCode":
|
|
@@ -227,7 +236,7 @@ function convertNodes(nodes, ctx, opts) {
|
|
|
227
236
|
results.push(buildBreak(node));
|
|
228
237
|
break;
|
|
229
238
|
case "link":
|
|
230
|
-
results.push(buildLink(node, ctx
|
|
239
|
+
results.push(buildLink(node, ctx));
|
|
231
240
|
break;
|
|
232
241
|
case "image":
|
|
233
242
|
results.push(buildImage(node, ctx.images));
|
|
@@ -239,7 +248,7 @@ function convertNodes(nodes, ctx, opts) {
|
|
|
239
248
|
// FIXME: unimplemented
|
|
240
249
|
break;
|
|
241
250
|
case "footnote":
|
|
242
|
-
results.push(buildFootnote(node, ctx
|
|
251
|
+
results.push(buildFootnote(node, ctx));
|
|
243
252
|
break;
|
|
244
253
|
case "footnoteReference":
|
|
245
254
|
// FIXME: unimplemented
|
|
@@ -254,10 +263,10 @@ function convertNodes(nodes, ctx, opts) {
|
|
|
254
263
|
}
|
|
255
264
|
return results;
|
|
256
265
|
}
|
|
257
|
-
function buildParagraph(_a, ctx
|
|
266
|
+
function buildParagraph(_a, ctx) {
|
|
258
267
|
_a.type; var children = _a.children;
|
|
259
268
|
var list = ctx.list;
|
|
260
|
-
return new docx.Paragraph(__assign({ children: convertNodes(children, ctx
|
|
269
|
+
return new docx.Paragraph(__assign({ children: convertNodes(children, ctx) }, (list &&
|
|
261
270
|
(list.ordered
|
|
262
271
|
? {
|
|
263
272
|
numbering: {
|
|
@@ -271,7 +280,7 @@ function buildParagraph(_a, ctx, opts) {
|
|
|
271
280
|
},
|
|
272
281
|
}))));
|
|
273
282
|
}
|
|
274
|
-
function buildHeading(_a, ctx
|
|
283
|
+
function buildHeading(_a, ctx) {
|
|
275
284
|
_a.type; var children = _a.children, depth = _a.depth;
|
|
276
285
|
var heading;
|
|
277
286
|
switch (depth) {
|
|
@@ -296,7 +305,7 @@ function buildHeading(_a, ctx, opts) {
|
|
|
296
305
|
}
|
|
297
306
|
return new docx.Paragraph({
|
|
298
307
|
heading: heading,
|
|
299
|
-
children: convertNodes(children, ctx
|
|
308
|
+
children: convertNodes(children, ctx),
|
|
300
309
|
});
|
|
301
310
|
}
|
|
302
311
|
function buildThematicBreak(_a) {
|
|
@@ -305,27 +314,27 @@ function buildThematicBreak(_a) {
|
|
|
305
314
|
thematicBreak: true,
|
|
306
315
|
});
|
|
307
316
|
}
|
|
308
|
-
function buildBlockquote(_a, ctx
|
|
317
|
+
function buildBlockquote(_a, ctx) {
|
|
309
318
|
_a.type; var children = _a.children;
|
|
310
319
|
// FIXME: do nothing for now
|
|
311
|
-
return convertNodes(children, ctx
|
|
320
|
+
return convertNodes(children, ctx);
|
|
312
321
|
}
|
|
313
|
-
function buildList(_a, ctx
|
|
322
|
+
function buildList(_a, ctx) {
|
|
314
323
|
_a.type; var children = _a.children, ordered = _a.ordered; _a.start; _a.spread;
|
|
315
324
|
var list = {
|
|
316
325
|
level: ctx.list ? ctx.list.level + 1 : 0,
|
|
317
326
|
ordered: !!ordered,
|
|
318
327
|
};
|
|
319
328
|
return children.reduce(function (acc, item) {
|
|
320
|
-
acc.push.apply(acc, buildListItem(item, __assign(__assign({}, ctx), { list: list })
|
|
329
|
+
acc.push.apply(acc, buildListItem(item, __assign(__assign({}, ctx), { list: list })));
|
|
321
330
|
return acc;
|
|
322
331
|
}, []);
|
|
323
332
|
}
|
|
324
|
-
function buildListItem(_a, ctx
|
|
333
|
+
function buildListItem(_a, ctx) {
|
|
325
334
|
_a.type; var children = _a.children; _a.checked; _a.spread;
|
|
326
|
-
return convertNodes(children, ctx
|
|
335
|
+
return convertNodes(children, ctx);
|
|
327
336
|
}
|
|
328
|
-
function buildTable(_a, ctx
|
|
337
|
+
function buildTable(_a, ctx) {
|
|
329
338
|
_a.type; var children = _a.children, align = _a.align;
|
|
330
339
|
var cellAligns = align === null || align === void 0 ? void 0 : align.map(function (a) {
|
|
331
340
|
switch (a) {
|
|
@@ -341,25 +350,25 @@ function buildTable(_a, ctx, opts) {
|
|
|
341
350
|
});
|
|
342
351
|
return new docx.Table({
|
|
343
352
|
rows: children.map(function (r) {
|
|
344
|
-
return buildTableRow(r, ctx,
|
|
353
|
+
return buildTableRow(r, ctx, cellAligns);
|
|
345
354
|
}),
|
|
346
355
|
});
|
|
347
356
|
}
|
|
348
|
-
function buildTableRow(_a, ctx,
|
|
357
|
+
function buildTableRow(_a, ctx, cellAligns) {
|
|
349
358
|
_a.type; var children = _a.children;
|
|
350
359
|
return new docx.TableRow({
|
|
351
360
|
children: children.map(function (c, i) {
|
|
352
|
-
return buildTableCell(c, ctx,
|
|
361
|
+
return buildTableCell(c, ctx, cellAligns === null || cellAligns === void 0 ? void 0 : cellAligns[i]);
|
|
353
362
|
}),
|
|
354
363
|
});
|
|
355
364
|
}
|
|
356
|
-
function buildTableCell(_a, ctx,
|
|
365
|
+
function buildTableCell(_a, ctx, align) {
|
|
357
366
|
_a.type; var children = _a.children;
|
|
358
367
|
return new docx.TableCell({
|
|
359
368
|
children: [
|
|
360
369
|
new docx.Paragraph({
|
|
361
370
|
alignment: align,
|
|
362
|
-
children: convertNodes(children, ctx
|
|
371
|
+
children: convertNodes(children, ctx),
|
|
363
372
|
}),
|
|
364
373
|
],
|
|
365
374
|
});
|
|
@@ -402,11 +411,11 @@ function buildBreak(_a) {
|
|
|
402
411
|
_a.type;
|
|
403
412
|
return new docx.TextRun({ text: "", break: 1 });
|
|
404
413
|
}
|
|
405
|
-
function buildLink(_a, ctx
|
|
414
|
+
function buildLink(_a, ctx) {
|
|
406
415
|
_a.type; var children = _a.children, url = _a.url; _a.title;
|
|
407
416
|
return new docx.ExternalHyperlink({
|
|
408
417
|
link: url,
|
|
409
|
-
children: convertNodes(children, ctx
|
|
418
|
+
children: convertNodes(children, ctx),
|
|
410
419
|
});
|
|
411
420
|
}
|
|
412
421
|
function buildImage(_a, images) {
|
|
@@ -423,11 +432,11 @@ function buildImage(_a, images) {
|
|
|
423
432
|
},
|
|
424
433
|
});
|
|
425
434
|
}
|
|
426
|
-
function buildFootnote(_a, ctx
|
|
435
|
+
function buildFootnote(_a, ctx) {
|
|
427
436
|
_a.type; var children = _a.children;
|
|
428
437
|
// FIXME: transform to paragraph for now
|
|
429
438
|
return new docx.Paragraph({
|
|
430
|
-
children: convertNodes(children, ctx
|
|
439
|
+
children: convertNodes(children, ctx),
|
|
431
440
|
});
|
|
432
441
|
}
|
|
433
442
|
|
package/lib/transformer.d.ts
CHANGED
|
@@ -12,7 +12,6 @@ export declare type ImageData = {
|
|
|
12
12
|
export declare type ImageResolver = (url: string) => Promise<ImageData> | ImageData;
|
|
13
13
|
export declare type Opts = {
|
|
14
14
|
output?: "buffer" | "blob" | "raw";
|
|
15
|
-
docProperties?: Omit<IPropertiesOptions, "sections" | "numbering">;
|
|
16
15
|
imageResolver?: ImageResolver;
|
|
17
|
-
}
|
|
18
|
-
export declare function mdastToDocx(node: mdast.Root,
|
|
16
|
+
} & Pick<IPropertiesOptions, "title" | "subject" | "creator" | "keywords" | "description" | "lastModifiedBy" | "revision" | "styles" | "background">;
|
|
17
|
+
export declare function mdastToDocx(node: mdast.Root, { output, title, subject, creator, keywords, description, lastModifiedBy, revision, styles, background, }: Opts, images: ImageDataMap): Promise<any> | docx.File;
|