remark-docx 0.3.9 → 0.3.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.cjs +137 -168
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +137 -168
- package/lib/index.js.map +1 -1
- package/lib/{mdast-to-docx.d.ts → mdast-util-to-docx.d.ts} +3 -3
- package/lib/plugin.d.ts +1 -1
- package/lib/plugins/html/index.cjs +2 -2
- package/lib/plugins/html/index.cjs.map +1 -1
- package/lib/plugins/html/index.js +2 -2
- package/lib/plugins/html/index.js.map +1 -1
- package/lib/plugins/image/index.cjs +17 -7
- package/lib/plugins/image/index.cjs.map +1 -1
- package/lib/plugins/image/index.js +14 -4
- package/lib/plugins/image/index.js.map +1 -1
- package/lib/plugins/math/index.cjs +4 -2
- package/lib/plugins/math/index.cjs.map +1 -1
- package/lib/plugins/math/index.js +3 -1
- package/lib/plugins/math/index.js.map +1 -1
- package/lib/types.d.ts +25 -5
- package/package.json +2 -1
- package/lib/mdast.d.ts +0 -2
- package/lib/utils-40yKzkXT.js +0 -19
- package/lib/utils-40yKzkXT.js.map +0 -1
- package/lib/utils-EYEfXxbh.js +0 -22
- package/lib/utils-EYEfXxbh.js.map +0 -1
package/lib/index.js
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { sectionPageSizeDefaults, sectionMarginDefaults, Document, Packer, AlignmentType, LevelFormat, convertInchesToTwip, FootnoteReferenceRun, ExternalHyperlink, TextRun, Paragraph, Table, TableRow, TableCell, HeadingLevel, CheckBox } from 'docx';
|
|
2
2
|
import { definitions } from 'mdast-util-definitions';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* @internal
|
|
6
|
-
*/
|
|
7
|
-
function invariant(cond, message) {
|
|
8
|
-
throw new Error(message);
|
|
9
|
-
}
|
|
10
4
|
const alreadyWarned = {};
|
|
11
5
|
/**
|
|
12
6
|
* @internal
|
|
@@ -43,7 +37,7 @@ const createFootnoteRegistry = () => {
|
|
|
43
37
|
},
|
|
44
38
|
toConfig: () => {
|
|
45
39
|
return defs.entries().reduce((acc, [key, def]) => {
|
|
46
|
-
acc[key] = def;
|
|
40
|
+
acc[key] = { children: def };
|
|
47
41
|
return acc;
|
|
48
42
|
}, {});
|
|
49
43
|
},
|
|
@@ -126,19 +120,92 @@ const createNumberingRegistry = () => {
|
|
|
126
120
|
},
|
|
127
121
|
};
|
|
128
122
|
};
|
|
129
|
-
const mdastToDocx = async (node, { plugins = [], title, subject, creator, keywords, description, lastModifiedBy, revision, styles, background, }) => {
|
|
123
|
+
const mdastToDocx = async (node, { plugins = [], title, subject, creator, keywords, description, lastModifiedBy, revision, styles, background, } = {}) => {
|
|
130
124
|
const definition = definitions(node);
|
|
131
125
|
const footnote = createFootnoteRegistry();
|
|
132
126
|
const numbering = createNumberingRegistry();
|
|
133
127
|
const pluginCtx = { root: node, definition };
|
|
134
|
-
const
|
|
135
|
-
|
|
128
|
+
const builders = (await Promise.all(plugins.map((p) => p(pluginCtx)))).reduceRight((acc, p) => {
|
|
129
|
+
for (const k of Object.keys(p)) {
|
|
130
|
+
acc[k] = p[k];
|
|
131
|
+
}
|
|
132
|
+
return acc;
|
|
133
|
+
}, {
|
|
134
|
+
paragraph: buildParagraph,
|
|
135
|
+
heading: buildHeading,
|
|
136
|
+
thematicBreak: buildThematicBreak,
|
|
137
|
+
blockquote: buildBlockquote,
|
|
138
|
+
list: buildList,
|
|
139
|
+
listItem: buildListItem,
|
|
140
|
+
table: buildTable,
|
|
141
|
+
tableRow: noop,
|
|
142
|
+
tableCell: noop,
|
|
143
|
+
html: fallbackText,
|
|
144
|
+
code: fallbackText,
|
|
145
|
+
definition: noop,
|
|
146
|
+
footnoteDefinition: buildFootnoteDefinition,
|
|
147
|
+
text: buildText,
|
|
148
|
+
emphasis: buildEmphasis,
|
|
149
|
+
strong: buildStrong,
|
|
150
|
+
delete: buildDelete,
|
|
151
|
+
inlineCode: buildInlineCode,
|
|
152
|
+
break: buildBreak,
|
|
153
|
+
link: buildLink,
|
|
154
|
+
linkReference: buildLinkReference,
|
|
155
|
+
// image: warnImage,
|
|
156
|
+
// imageReference: warnImage,
|
|
157
|
+
footnoteReference: buildFootnoteReference,
|
|
158
|
+
math: fallbackText,
|
|
159
|
+
inlineMath: fallbackText,
|
|
160
|
+
});
|
|
161
|
+
const renderNode = (node, c) => {
|
|
162
|
+
const builder = builders[node.type];
|
|
163
|
+
if (!builder) {
|
|
164
|
+
warnOnce(`${node.type} node is not supported without plugins.`);
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
const r = builder(node, c);
|
|
168
|
+
if (r) {
|
|
169
|
+
if (Array.isArray(r)) {
|
|
170
|
+
return r;
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
return [r];
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return null;
|
|
177
|
+
};
|
|
178
|
+
const ctx = {
|
|
179
|
+
render(nodes, c) {
|
|
180
|
+
const results = [];
|
|
181
|
+
for (const node of nodes) {
|
|
182
|
+
const r = renderNode(node, c !== null && c !== void 0 ? c : this);
|
|
183
|
+
if (r) {
|
|
184
|
+
results.push(...r);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return results;
|
|
188
|
+
},
|
|
136
189
|
deco: {},
|
|
137
190
|
indent: 0,
|
|
138
191
|
definition: definition,
|
|
139
192
|
footnote,
|
|
140
193
|
numbering,
|
|
141
|
-
}
|
|
194
|
+
};
|
|
195
|
+
const sections = [[]];
|
|
196
|
+
for (const n of node.children) {
|
|
197
|
+
const r = renderNode(n, ctx);
|
|
198
|
+
if (r) {
|
|
199
|
+
if (!r.length) {
|
|
200
|
+
// thematicBreak
|
|
201
|
+
sections.push([]);
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
const lastSection = sections[sections.length - 1];
|
|
205
|
+
lastSection.push(...r);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
142
209
|
const doc = new Document({
|
|
143
210
|
title,
|
|
144
211
|
subject,
|
|
@@ -149,129 +216,19 @@ const mdastToDocx = async (node, { plugins = [], title, subject, creator, keywor
|
|
|
149
216
|
revision,
|
|
150
217
|
styles,
|
|
151
218
|
background,
|
|
219
|
+
sections: sections
|
|
220
|
+
.filter((s) => s.length)
|
|
221
|
+
.map((s) => ({ children: s })),
|
|
152
222
|
footnotes: footnote.toConfig(),
|
|
153
|
-
sections: [{ children: nodes }],
|
|
154
223
|
numbering: {
|
|
155
224
|
config: numbering.toConfig(),
|
|
156
225
|
},
|
|
157
226
|
});
|
|
158
227
|
return Packer.toArrayBuffer(doc);
|
|
159
228
|
};
|
|
160
|
-
const convertNodes = (nodes, ctx) => {
|
|
161
|
-
var _a, _b;
|
|
162
|
-
const results = [];
|
|
163
|
-
for (const node of nodes) {
|
|
164
|
-
const customNodes = (_b = (_a = ctx.overrides)[node.type]) === null || _b === void 0 ? void 0 : _b.call(_a, node, (children) => convertNodes(children, ctx));
|
|
165
|
-
if (customNodes != null) {
|
|
166
|
-
if (Array.isArray(customNodes)) {
|
|
167
|
-
results.push(...customNodes);
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
results.push(customNodes);
|
|
171
|
-
}
|
|
172
|
-
continue;
|
|
173
|
-
}
|
|
174
|
-
switch (node.type) {
|
|
175
|
-
case "paragraph": {
|
|
176
|
-
results.push(buildParagraph(node, ctx));
|
|
177
|
-
break;
|
|
178
|
-
}
|
|
179
|
-
case "heading": {
|
|
180
|
-
results.push(buildHeading(node, ctx));
|
|
181
|
-
break;
|
|
182
|
-
}
|
|
183
|
-
case "thematicBreak":
|
|
184
|
-
results.push(buildThematicBreak());
|
|
185
|
-
break;
|
|
186
|
-
case "blockquote": {
|
|
187
|
-
results.push(...buildBlockquote(node, ctx));
|
|
188
|
-
break;
|
|
189
|
-
}
|
|
190
|
-
case "list": {
|
|
191
|
-
results.push(...buildList(node, ctx));
|
|
192
|
-
break;
|
|
193
|
-
}
|
|
194
|
-
case "listItem":
|
|
195
|
-
invariant(false, "unreachable");
|
|
196
|
-
case "table":
|
|
197
|
-
results.push(buildTable(node, ctx));
|
|
198
|
-
break;
|
|
199
|
-
case "tableRow":
|
|
200
|
-
invariant(false, "unreachable");
|
|
201
|
-
case "tableCell":
|
|
202
|
-
invariant(false, "unreachable");
|
|
203
|
-
case "html":
|
|
204
|
-
warnOnce(`${node.type} node is not rendered since remark-docx/plugins/html is not provided.`);
|
|
205
|
-
break;
|
|
206
|
-
case "code":
|
|
207
|
-
warnOnce(`${node.type} node is not rendered since remark-docx/plugins/code is not provided.`);
|
|
208
|
-
break;
|
|
209
|
-
// case "yaml":
|
|
210
|
-
// // unimplemented
|
|
211
|
-
// break;
|
|
212
|
-
// case "toml":
|
|
213
|
-
// // unimplemented
|
|
214
|
-
// break;
|
|
215
|
-
case "definition":
|
|
216
|
-
// noop
|
|
217
|
-
break;
|
|
218
|
-
case "footnoteDefinition": {
|
|
219
|
-
registerFootnoteDefinition(node, ctx);
|
|
220
|
-
break;
|
|
221
|
-
}
|
|
222
|
-
case "text":
|
|
223
|
-
results.push(buildText(node.value, ctx.deco));
|
|
224
|
-
break;
|
|
225
|
-
case "emphasis":
|
|
226
|
-
case "strong":
|
|
227
|
-
case "delete": {
|
|
228
|
-
const { type, children } = node;
|
|
229
|
-
const nodes = convertNodes(children, {
|
|
230
|
-
...ctx,
|
|
231
|
-
deco: { ...ctx.deco, [type]: true },
|
|
232
|
-
});
|
|
233
|
-
results.push(...nodes);
|
|
234
|
-
break;
|
|
235
|
-
}
|
|
236
|
-
case "inlineCode":
|
|
237
|
-
results.push(buildInlineCode(node));
|
|
238
|
-
break;
|
|
239
|
-
case "break":
|
|
240
|
-
results.push(buildBreak());
|
|
241
|
-
break;
|
|
242
|
-
case "link": {
|
|
243
|
-
results.push(buildLink(node, ctx));
|
|
244
|
-
break;
|
|
245
|
-
}
|
|
246
|
-
case "linkReference":
|
|
247
|
-
results.push(...buildLinkReference(node, ctx));
|
|
248
|
-
break;
|
|
249
|
-
case "image":
|
|
250
|
-
case "imageReference": {
|
|
251
|
-
warnOnce(`${node.type} node is not rendered since remark-docx/plugins/image is not provided.`);
|
|
252
|
-
break;
|
|
253
|
-
}
|
|
254
|
-
// case "footnote": {
|
|
255
|
-
// // inline footnote was removed in mdast v5
|
|
256
|
-
// break;
|
|
257
|
-
// }
|
|
258
|
-
case "footnoteReference":
|
|
259
|
-
results.push(buildFootnoteReference(node, ctx));
|
|
260
|
-
break;
|
|
261
|
-
case "math":
|
|
262
|
-
case "inlineMath":
|
|
263
|
-
warnOnce(`${node.type} node is not rendered since remark-docx/plugins/math is not provided.`);
|
|
264
|
-
break;
|
|
265
|
-
default:
|
|
266
|
-
warnOnce(`${node.type} node is not officially supported.`);
|
|
267
|
-
break;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
return results;
|
|
271
|
-
};
|
|
272
229
|
const buildParagraph = ({ children }, ctx) => {
|
|
273
230
|
const list = ctx.list;
|
|
274
|
-
const nodes =
|
|
231
|
+
const nodes = ctx.render(children);
|
|
275
232
|
if (list && list.checked != null) {
|
|
276
233
|
nodes.unshift(new CheckBox({
|
|
277
234
|
checked: list.checked,
|
|
@@ -323,19 +280,18 @@ const buildHeading = ({ children, depth }, ctx) => {
|
|
|
323
280
|
headingLevel = HeadingLevel.HEADING_5;
|
|
324
281
|
break;
|
|
325
282
|
}
|
|
326
|
-
const nodes =
|
|
283
|
+
const nodes = ctx.render(children);
|
|
327
284
|
return new Paragraph({
|
|
328
285
|
heading: headingLevel,
|
|
329
286
|
children: nodes,
|
|
330
287
|
});
|
|
331
288
|
};
|
|
332
|
-
const buildThematicBreak = (
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
});
|
|
289
|
+
const buildThematicBreak = () => {
|
|
290
|
+
// Returning empty array at toplevel means section insertion.
|
|
291
|
+
return [];
|
|
336
292
|
};
|
|
337
293
|
const buildBlockquote = ({ children }, ctx) => {
|
|
338
|
-
return
|
|
294
|
+
return ctx.render(children, {
|
|
339
295
|
...ctx,
|
|
340
296
|
indent: ctx.indent + 1,
|
|
341
297
|
});
|
|
@@ -343,22 +299,20 @@ const buildBlockquote = ({ children }, ctx) => {
|
|
|
343
299
|
const buildList = ({ children, ordered }, ctx) => {
|
|
344
300
|
var _a;
|
|
345
301
|
const isTopLevel = !ctx.list;
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
list,
|
|
357
|
-
});
|
|
302
|
+
const reference = isTopLevel && ordered
|
|
303
|
+
? ctx.numbering.create()
|
|
304
|
+
: ((_a = ctx.list) === null || _a === void 0 ? void 0 : _a.reference) || ORDERED_LIST_REF;
|
|
305
|
+
return ctx.render(children, {
|
|
306
|
+
...ctx,
|
|
307
|
+
list: {
|
|
308
|
+
level: isTopLevel ? 0 : ctx.list.level + 1,
|
|
309
|
+
ordered: !!ordered,
|
|
310
|
+
reference,
|
|
311
|
+
},
|
|
358
312
|
});
|
|
359
313
|
};
|
|
360
314
|
const buildListItem = ({ children, checked }, ctx) => {
|
|
361
|
-
return
|
|
315
|
+
return ctx.render(children, {
|
|
362
316
|
...ctx,
|
|
363
317
|
...(ctx.list && { list: { ...ctx.list, checked: checked !== null && checked !== void 0 ? checked : undefined } }),
|
|
364
318
|
});
|
|
@@ -388,7 +342,7 @@ const buildTable = ({ children, align }, ctx) => {
|
|
|
388
342
|
children: [
|
|
389
343
|
new Paragraph({
|
|
390
344
|
alignment: cellAligns === null || cellAligns === void 0 ? void 0 : cellAligns[i],
|
|
391
|
-
children:
|
|
345
|
+
children: ctx.render(c.children),
|
|
392
346
|
}),
|
|
393
347
|
],
|
|
394
348
|
});
|
|
@@ -397,12 +351,30 @@ const buildTable = ({ children, align }, ctx) => {
|
|
|
397
351
|
}),
|
|
398
352
|
});
|
|
399
353
|
};
|
|
400
|
-
const buildText = (
|
|
354
|
+
const buildText = ({ value }, { deco }) => {
|
|
401
355
|
return new TextRun({
|
|
402
|
-
text,
|
|
403
|
-
bold: deco.
|
|
404
|
-
italics: deco.
|
|
405
|
-
strike: deco.
|
|
356
|
+
text: value,
|
|
357
|
+
bold: deco.bold,
|
|
358
|
+
italics: deco.italic,
|
|
359
|
+
strike: deco.strike,
|
|
360
|
+
});
|
|
361
|
+
};
|
|
362
|
+
const buildEmphasis = ({ children }, ctx) => {
|
|
363
|
+
return ctx.render(children, {
|
|
364
|
+
...ctx,
|
|
365
|
+
deco: { ...ctx.deco, italic: true },
|
|
366
|
+
});
|
|
367
|
+
};
|
|
368
|
+
const buildStrong = ({ children }, ctx) => {
|
|
369
|
+
return ctx.render(children, {
|
|
370
|
+
...ctx,
|
|
371
|
+
deco: { ...ctx.deco, bold: true },
|
|
372
|
+
});
|
|
373
|
+
};
|
|
374
|
+
const buildDelete = ({ children }, ctx) => {
|
|
375
|
+
return ctx.render(children, {
|
|
376
|
+
...ctx,
|
|
377
|
+
deco: { ...ctx.deco, strike: true },
|
|
406
378
|
});
|
|
407
379
|
};
|
|
408
380
|
const buildInlineCode = ({ value }) => {
|
|
@@ -411,11 +383,11 @@ const buildInlineCode = ({ value }) => {
|
|
|
411
383
|
highlight: "lightGray",
|
|
412
384
|
});
|
|
413
385
|
};
|
|
414
|
-
const buildBreak = (
|
|
386
|
+
const buildBreak = () => {
|
|
415
387
|
return new TextRun({ text: "", break: 1 });
|
|
416
388
|
};
|
|
417
389
|
const buildLink = ({ children, url }, ctx) => {
|
|
418
|
-
const nodes =
|
|
390
|
+
const nodes = ctx.render(children);
|
|
419
391
|
return new ExternalHyperlink({
|
|
420
392
|
link: url,
|
|
421
393
|
children: nodes,
|
|
@@ -424,29 +396,26 @@ const buildLink = ({ children, url }, ctx) => {
|
|
|
424
396
|
const buildLinkReference = ({ children, identifier }, ctx) => {
|
|
425
397
|
const def = ctx.definition(identifier);
|
|
426
398
|
if (def == null) {
|
|
427
|
-
return
|
|
399
|
+
return ctx.render(children);
|
|
428
400
|
}
|
|
429
|
-
return
|
|
401
|
+
return buildLink({ children, url: def.url }, ctx);
|
|
430
402
|
};
|
|
431
|
-
const
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
// Convert each node and extract the first result as a paragraph
|
|
435
|
-
const nodes = convertNodes([node], ctx);
|
|
436
|
-
if (nodes[0] instanceof Paragraph) {
|
|
437
|
-
return nodes[0];
|
|
438
|
-
}
|
|
439
|
-
// For non-paragraph content, wrap in a paragraph
|
|
440
|
-
return new Paragraph({ children: nodes });
|
|
441
|
-
}),
|
|
442
|
-
};
|
|
443
|
-
ctx.footnote.def(identifier, definition);
|
|
403
|
+
const buildFootnoteDefinition = ({ children, identifier }, ctx) => {
|
|
404
|
+
ctx.footnote.def(identifier, ctx.render(children).filter((c) => c instanceof Paragraph));
|
|
405
|
+
return null;
|
|
444
406
|
};
|
|
445
407
|
const buildFootnoteReference = ({ identifier }, ctx) => {
|
|
446
408
|
return new FootnoteReferenceRun(ctx.footnote.ref(identifier));
|
|
447
409
|
};
|
|
410
|
+
const noop = () => {
|
|
411
|
+
return null;
|
|
412
|
+
};
|
|
413
|
+
const fallbackText = (node, ctx) => {
|
|
414
|
+
warnOnce(`${node.type} node is not supported without plugins, falling back to text.`);
|
|
415
|
+
return buildText({ value: node.value }, ctx);
|
|
416
|
+
};
|
|
448
417
|
|
|
449
|
-
const plugin = function (opts
|
|
418
|
+
const plugin = function (opts) {
|
|
450
419
|
this.compiler = (node) => {
|
|
451
420
|
return mdastToDocx(node, opts);
|
|
452
421
|
};
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/src/utils.ts","../src/src/mdast-to-docx.ts","../src/src/plugin.ts"],"sourcesContent":["/**\n * @internal\n */\nexport function invariant(cond: any, message: string): asserts cond {\n if (!cond) throw new Error(message);\n}\n\nconst 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 CheckBox,\n type IPropertiesOptions,\n sectionPageSizeDefaults,\n sectionMarginDefaults,\n} from \"docx\";\nimport type * as mdast from \"./mdast\";\nimport { invariant, warnOnce } from \"./utils\";\nimport { definitions, type GetDefinition } from \"mdast-util-definitions\";\nimport type {\n DocxChild,\n DocxContent,\n NodeOverrides,\n RemarkDocxPlugin,\n} from \"./types\";\n\nconst CONTENT_WIDTH =\n sectionPageSizeDefaults.WIDTH -\n sectionMarginDefaults.LEFT -\n sectionMarginDefaults.RIGHT;\nconst ORDERED_LIST_REF = \"ordered\";\nconst INDENT = 0.5;\n\ntype Decoration = Readonly<{\n [key in (mdast.Emphasis | mdast.Strong | mdast.Delete)[\"type\"]]?: true;\n}>;\n\ntype ListInfo = Readonly<{\n level: number;\n ordered: boolean;\n reference: string;\n checked?: boolean;\n}>;\n\ntype FootnoteDefinition = Readonly<{ children: Paragraph[] }>;\ntype FootnoteRegistry = {\n ref: (id: string) => number;\n def: (id: string, def: FootnoteDefinition) => void;\n toConfig: () => {\n [key: string]: FootnoteDefinition;\n };\n};\n\nconst createFootnoteRegistry = (): FootnoteRegistry => {\n const idToInternalId = new Map<string, number>();\n const defs = new Map<number, FootnoteDefinition>();\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 ref: (id) => {\n return getId(id);\n },\n def: (id, def) => {\n const internalId = getId(id);\n defs.set(internalId, def);\n },\n toConfig: () => {\n return defs.entries().reduce(\n (acc, [key, def]) => {\n acc[key] = def;\n return acc;\n },\n {} as {\n [key: string]: FootnoteDefinition;\n },\n );\n },\n };\n};\n\ntype NumberingRegistry = {\n create: () => string;\n toConfig: () => Array<{ reference: string; levels: ILevelsOptions[] }>;\n};\n\nconst createNumberingRegistry = (): NumberingRegistry => {\n let counter = 1;\n\n const DEFAULT_NUMBERINGS: ILevelsOptions[] = [\n {\n level: 0,\n format: LevelFormat.DECIMAL,\n text: \"%1.\",\n alignment: AlignmentType.START,\n },\n {\n level: 1,\n format: LevelFormat.DECIMAL,\n text: \"%2.\",\n alignment: AlignmentType.START,\n style: {\n paragraph: {\n indent: { start: convertInchesToTwip(INDENT * 1) },\n },\n },\n },\n {\n level: 2,\n format: LevelFormat.DECIMAL,\n text: \"%3.\",\n alignment: AlignmentType.START,\n style: {\n paragraph: {\n indent: { start: convertInchesToTwip(INDENT * 2) },\n },\n },\n },\n {\n level: 3,\n format: LevelFormat.DECIMAL,\n text: \"%4.\",\n alignment: AlignmentType.START,\n style: {\n paragraph: {\n indent: { start: convertInchesToTwip(INDENT * 3) },\n },\n },\n },\n {\n level: 4,\n format: LevelFormat.DECIMAL,\n text: \"%5.\",\n alignment: AlignmentType.START,\n style: {\n paragraph: {\n indent: { start: convertInchesToTwip(INDENT * 4) },\n },\n },\n },\n {\n level: 5,\n format: LevelFormat.DECIMAL,\n text: \"%6.\",\n alignment: AlignmentType.START,\n style: {\n paragraph: {\n indent: { start: convertInchesToTwip(INDENT * 5) },\n },\n },\n },\n ];\n\n return {\n create: () => {\n return `${ORDERED_LIST_REF}-${counter++}`;\n },\n toConfig: () => {\n return Array.from({ length: counter }, (_, i) => ({\n reference: `${ORDERED_LIST_REF}-${i}`,\n levels: DEFAULT_NUMBERINGS,\n }));\n },\n };\n};\n\ntype Context = Readonly<{\n overrides: NodeOverrides;\n deco: Decoration;\n indent: number;\n list?: ListInfo;\n definition: GetDefinition;\n footnote: FootnoteRegistry;\n numbering: NumberingRegistry;\n}>;\n\nexport interface DocxOptions extends Pick<\n IPropertiesOptions,\n | \"title\"\n | \"subject\"\n | \"creator\"\n | \"keywords\"\n | \"description\"\n | \"lastModifiedBy\"\n | \"revision\"\n | \"styles\"\n | \"background\"\n> {\n /**\n * Plugins to customize how mdast nodes are transformed.\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 lastModifiedBy,\n revision,\n styles,\n background,\n }: DocxOptions,\n): Promise<ArrayBuffer> => {\n const definition = definitions(node);\n\n const footnote = createFootnoteRegistry();\n const numbering = createNumberingRegistry();\n\n const pluginCtx = { root: node, definition };\n const nodes = convertNodes(node.children, {\n overrides: (\n await Promise.all(plugins.map((p) => p(pluginCtx)))\n ).reduceRight((acc, p) => ({ ...acc, ...p }), {}),\n deco: {},\n indent: 0,\n definition: definition,\n footnote,\n numbering,\n });\n\n const doc = new Document({\n title,\n subject,\n creator,\n keywords,\n description,\n lastModifiedBy,\n revision,\n styles,\n background,\n footnotes: footnote.toConfig(),\n sections: [{ children: nodes as DocxChild[] }],\n numbering: {\n config: numbering.toConfig(),\n },\n });\n\n return Packer.toArrayBuffer(doc);\n};\n\nconst convertNodes = (\n nodes: mdast.RootContent[],\n ctx: Context,\n): DocxContent[] => {\n const results: DocxContent[] = [];\n for (const node of nodes) {\n const customNodes = ctx.overrides[node.type]?.(node as any, (children) =>\n convertNodes(children, ctx),\n );\n if (customNodes != null) {\n if (Array.isArray(customNodes)) {\n results.push(...customNodes);\n } else {\n results.push(customNodes);\n }\n continue;\n }\n\n switch (node.type) {\n case \"paragraph\": {\n results.push(buildParagraph(node, ctx));\n break;\n }\n case \"heading\": {\n results.push(buildHeading(node, ctx));\n break;\n }\n case \"thematicBreak\":\n results.push(buildThematicBreak(node));\n break;\n case \"blockquote\": {\n results.push(...buildBlockquote(node, ctx));\n break;\n }\n case \"list\": {\n results.push(...buildList(node, ctx));\n break;\n }\n case \"listItem\":\n invariant(false, \"unreachable\");\n case \"table\":\n results.push(buildTable(node, ctx));\n break;\n case \"tableRow\":\n invariant(false, \"unreachable\");\n case \"tableCell\":\n invariant(false, \"unreachable\");\n case \"html\":\n warnOnce(\n `${node.type} node is not rendered since remark-docx/plugins/html is not provided.`,\n );\n break;\n case \"code\":\n warnOnce(\n `${node.type} node is not rendered since remark-docx/plugins/code is not provided.`,\n );\n break;\n // case \"yaml\":\n // // unimplemented\n // break;\n // case \"toml\":\n // // unimplemented\n // break;\n case \"definition\":\n // noop\n break;\n case \"footnoteDefinition\": {\n registerFootnoteDefinition(node, ctx);\n break;\n }\n case \"text\":\n results.push(buildText(node.value, ctx.deco));\n break;\n case \"emphasis\":\n case \"strong\":\n case \"delete\": {\n const { type, children } = node;\n const nodes = convertNodes(children, {\n ...ctx,\n deco: { ...ctx.deco, [type]: true },\n });\n results.push(...nodes);\n break;\n }\n case \"inlineCode\":\n results.push(buildInlineCode(node));\n break;\n case \"break\":\n results.push(buildBreak(node));\n break;\n case \"link\": {\n results.push(buildLink(node, ctx));\n break;\n }\n case \"linkReference\":\n results.push(...buildLinkReference(node, ctx));\n break;\n case \"image\":\n case \"imageReference\": {\n warnOnce(\n `${node.type} node is not rendered since remark-docx/plugins/image is not provided.`,\n );\n break;\n }\n // case \"footnote\": {\n // // inline footnote was removed in mdast v5\n // break;\n // }\n case \"footnoteReference\":\n results.push(buildFootnoteReference(node, ctx));\n break;\n case \"math\":\n case \"inlineMath\":\n warnOnce(\n `${node.type} node is not rendered since remark-docx/plugins/math is not provided.`,\n );\n break;\n default:\n warnOnce(`${node.type} node is not officially supported.`);\n break;\n }\n }\n return results;\n};\n\nconst buildParagraph = (\n { children }: mdast.Paragraph,\n ctx: Context,\n): DocxContent => {\n const list = ctx.list;\n const nodes = convertNodes(children, ctx);\n\n if (list && list.checked != null) {\n nodes.unshift(\n new CheckBox({\n checked: list.checked,\n checkedState: { value: \"2611\" },\n uncheckedState: { value: \"2610\" },\n }),\n );\n }\n return new Paragraph({\n children: nodes,\n indent:\n ctx.indent > 0\n ? {\n start: convertInchesToTwip(INDENT * ctx.indent),\n }\n : undefined,\n ...(list &&\n (list.ordered\n ? {\n numbering: {\n reference: list.reference,\n level: list.level,\n },\n }\n : {\n bullet: {\n level: list.level,\n },\n })),\n });\n};\n\nconst buildHeading = (\n { children, depth }: mdast.Heading,\n ctx: Context,\n): DocxContent => {\n let headingLevel: (typeof HeadingLevel)[keyof typeof HeadingLevel];\n switch (depth) {\n case 1:\n headingLevel = HeadingLevel.TITLE;\n break;\n case 2:\n headingLevel = HeadingLevel.HEADING_1;\n break;\n case 3:\n headingLevel = HeadingLevel.HEADING_2;\n break;\n case 4:\n headingLevel = HeadingLevel.HEADING_3;\n break;\n case 5:\n headingLevel = HeadingLevel.HEADING_4;\n break;\n case 6:\n headingLevel = HeadingLevel.HEADING_5;\n break;\n }\n const nodes = convertNodes(children, ctx);\n return new Paragraph({\n heading: headingLevel,\n children: nodes,\n });\n};\n\nconst buildThematicBreak = (_: mdast.ThematicBreak): DocxContent => {\n return new Paragraph({\n thematicBreak: true,\n });\n};\n\nconst buildBlockquote = (\n { children }: mdast.Blockquote,\n ctx: Context,\n): DocxContent[] => {\n return convertNodes(children, {\n ...ctx,\n indent: ctx.indent + 1,\n });\n};\n\nconst buildList = (\n { children, ordered }: mdast.List,\n ctx: Context,\n): DocxContent[] => {\n const isTopLevel = !ctx.list;\n const list: ListInfo = {\n level: ctx.list ? ctx.list.level + 1 : 0,\n ordered: !!ordered,\n reference:\n isTopLevel && ordered\n ? ctx.numbering.create()\n : ctx.list?.reference || ORDERED_LIST_REF,\n };\n return children.flatMap((item) => {\n return buildListItem(item, {\n ...ctx,\n list,\n });\n });\n};\n\nconst buildListItem = (\n { children, checked }: mdast.ListItem,\n ctx: Context,\n): DocxContent[] => {\n return convertNodes(children, {\n ...ctx,\n ...(ctx.list && { list: { ...ctx.list, checked: checked ?? undefined } }),\n });\n};\n\nconst buildTable = (\n { children, align }: mdast.Table,\n ctx: Context,\n): DocxContent => {\n const cellAligns:\n | (typeof AlignmentType)[keyof typeof AlignmentType][]\n | undefined = align?.map((a) => {\n switch (a) {\n case \"left\":\n return AlignmentType.LEFT;\n case \"right\":\n return AlignmentType.RIGHT;\n case \"center\":\n return AlignmentType.CENTER;\n default:\n return AlignmentType.LEFT;\n }\n });\n\n const columnLength = children[0]!.children.length;\n const columnWidth = CONTENT_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: cellAligns?.[i],\n children: convertNodes(c.children, ctx),\n }),\n ],\n });\n }),\n });\n }),\n });\n};\n\nconst buildText = (text: string, deco: Decoration): DocxContent => {\n return new TextRun({\n text,\n bold: deco.strong,\n italics: deco.emphasis,\n strike: deco.delete,\n });\n};\n\nconst buildInlineCode = ({ value }: mdast.InlineCode): DocxContent => {\n return new TextRun({\n text: value,\n highlight: \"lightGray\",\n });\n};\n\nconst buildBreak = (_: mdast.Break): DocxContent => {\n return new TextRun({ text: \"\", break: 1 });\n};\n\nconst buildLink = (\n { children, url }: Pick<mdast.Link, \"children\" | \"url\">,\n ctx: Context,\n): DocxContent => {\n const nodes = convertNodes(children, ctx);\n return new ExternalHyperlink({\n link: url,\n children: nodes,\n });\n};\n\nconst buildLinkReference = (\n { children, identifier }: mdast.LinkReference,\n ctx: Context,\n): DocxContent[] => {\n const def = ctx.definition(identifier);\n if (def == null) {\n return convertNodes(children, ctx);\n }\n return [buildLink({ children, url: def.url }, ctx)];\n};\n\nconst registerFootnoteDefinition = (\n { children, identifier }: mdast.FootnoteDefinition,\n ctx: Context,\n): void => {\n const definition: FootnoteDefinition = {\n children: children.map((node) => {\n // Convert each node and extract the first result as a paragraph\n const nodes = convertNodes([node], ctx);\n if (nodes[0] instanceof Paragraph) {\n return nodes[0] as Paragraph;\n }\n // For non-paragraph content, wrap in a paragraph\n return new Paragraph({ children: nodes });\n }),\n };\n ctx.footnote.def(identifier, definition);\n};\n\nconst buildFootnoteReference = (\n { identifier }: mdast.FootnoteReference,\n ctx: Context,\n): DocxContent => {\n return new FootnoteReferenceRun(ctx.footnote.ref(identifier));\n};\n","import type { Plugin } from \"unified\";\nimport type { Root } from \"mdast\";\nimport { mdastToDocx, type DocxOptions } from \"./mdast-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;;AAEG;AACG,SAAU,SAAS,CAAC,IAAS,EAAE,OAAe,EAAA;AAClD,IAAW,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC;AACrC;AAEA,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;;ACaA,MAAM,aAAa,GACjB,uBAAuB,CAAC,KAAK;AAC7B,IAAA,qBAAqB,CAAC,IAAI;IAC1B,qBAAqB,CAAC,KAAK;AAC7B,MAAM,gBAAgB,GAAG,SAAS;AAClC,MAAM,MAAM,GAAG,GAAG;AAsBlB,MAAM,sBAAsB,GAAG,MAAuB;AACpD,IAAA,MAAM,cAAc,GAAG,IAAI,GAAG,EAAkB;AAChD,IAAA,MAAM,IAAI,GAAG,IAAI,GAAG,EAA8B;AAElD,IAAA,MAAM,KAAK,GAAG,CAAC,EAAU,KAAY;QACnC,IAAI,UAAU,GA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CAAC,CAAC,YAAY,SAAS,EAAE;AACjC,gBAAA,OAAO,KAAK,CAAC,CAAC,CAAc;YAC9B;;YAEA,OAAO,IAAI,SAAS,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;AAC3C,QAAA,CAAC,CAAC;KACH;IACD,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,EAAE,UAAU,CAAC;AAC1C,CAAC;AAED,MAAM,sBAAsB,GAAG,CAC7B,EAAE,UAAU,EAA2B,EACvC,GAAY,KACG;AACf,IAAA,OAAO,IAAI,oBAAoB,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;AAC/D,CAAC;;ACnlBD,MAAM,MAAM,GAAuD,UACjE,IAAI,GAAG,EAAE,EAAA;AAET,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/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 CheckBox,\n type IPropertiesOptions,\n sectionPageSizeDefaults,\n sectionMarginDefaults,\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 NodeBuilder,\n NodeBuilders,\n NumberingRegistry,\n RemarkDocxPlugin,\n} from \"./types\";\n\nconst CONTENT_WIDTH =\n sectionPageSizeDefaults.WIDTH -\n sectionMarginDefaults.LEFT -\n sectionMarginDefaults.RIGHT;\nconst ORDERED_LIST_REF = \"ordered\";\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 ref: (id) => {\n return getId(id);\n },\n def: (id, def) => {\n const internalId = getId(id);\n defs.set(internalId, 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\nconst createNumberingRegistry = (): NumberingRegistry => {\n let counter = 1;\n\n const DEFAULT_NUMBERINGS: ILevelsOptions[] = [\n {\n level: 0,\n format: LevelFormat.DECIMAL,\n text: \"%1.\",\n alignment: AlignmentType.START,\n },\n {\n level: 1,\n format: LevelFormat.DECIMAL,\n text: \"%2.\",\n alignment: AlignmentType.START,\n style: {\n paragraph: {\n indent: { start: convertInchesToTwip(INDENT * 1) },\n },\n },\n },\n {\n level: 2,\n format: LevelFormat.DECIMAL,\n text: \"%3.\",\n alignment: AlignmentType.START,\n style: {\n paragraph: {\n indent: { start: convertInchesToTwip(INDENT * 2) },\n },\n },\n },\n {\n level: 3,\n format: LevelFormat.DECIMAL,\n text: \"%4.\",\n alignment: AlignmentType.START,\n style: {\n paragraph: {\n indent: { start: convertInchesToTwip(INDENT * 3) },\n },\n },\n },\n {\n level: 4,\n format: LevelFormat.DECIMAL,\n text: \"%5.\",\n alignment: AlignmentType.START,\n style: {\n paragraph: {\n indent: { start: convertInchesToTwip(INDENT * 4) },\n },\n },\n },\n {\n level: 5,\n format: LevelFormat.DECIMAL,\n text: \"%6.\",\n alignment: AlignmentType.START,\n style: {\n paragraph: {\n indent: { start: convertInchesToTwip(INDENT * 5) },\n },\n },\n },\n ];\n\n return {\n create: () => {\n return `${ORDERED_LIST_REF}-${counter++}`;\n },\n toConfig: () => {\n return Array.from({ length: counter }, (_, i) => ({\n reference: `${ORDERED_LIST_REF}-${i}`,\n levels: DEFAULT_NUMBERINGS,\n }));\n },\n };\n};\n\nexport interface DocxOptions extends Pick<\n IPropertiesOptions,\n | \"title\"\n | \"subject\"\n | \"creator\"\n | \"keywords\"\n | \"description\"\n | \"lastModifiedBy\"\n | \"revision\"\n | \"styles\"\n | \"background\"\n> {\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 lastModifiedBy,\n revision,\n styles,\n background,\n }: DocxOptions = {},\n): Promise<ArrayBuffer> => {\n const definition = definitions(node);\n\n const footnote = createFootnoteRegistry();\n const numbering = createNumberingRegistry();\n\n const pluginCtx = { root: node, definition };\n\n const builders = (\n await Promise.all(plugins.map((p) => p(pluginCtx)))\n ).reduceRight<NodeBuilders>(\n (acc, p) => {\n type Key = keyof typeof p;\n for (const k of Object.keys(p)) {\n acc[k as Key] = p[k as Key] as any;\n }\n return acc;\n },\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 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 deco: {},\n indent: 0,\n definition: definition,\n footnote,\n numbering,\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 doc = new Document({\n title,\n subject,\n creator,\n keywords,\n description,\n lastModifiedBy,\n revision,\n styles,\n background,\n sections: sections\n .filter((s) => s.length)\n .map((s) => ({ children: s as DocxChild[] })),\n footnotes: footnote.toConfig(),\n numbering: {\n config: numbering.toConfig(),\n },\n });\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 if (list && list.checked != null) {\n nodes.unshift(\n new CheckBox({\n checked: list.checked,\n checkedState: { value: \"2611\" },\n uncheckedState: { value: \"2610\" },\n }),\n );\n }\n return new Paragraph({\n children: nodes,\n indent:\n ctx.indent > 0\n ? {\n start: convertInchesToTwip(INDENT * ctx.indent),\n }\n : undefined,\n ...(list &&\n (list.ordered\n ? {\n numbering: {\n reference: list.reference,\n level: list.level,\n },\n }\n : {\n bullet: {\n level: list.level,\n },\n })),\n });\n};\n\nconst buildHeading: NodeBuilder<\"heading\"> = ({ children, depth }, ctx) => {\n let headingLevel: (typeof HeadingLevel)[keyof typeof HeadingLevel];\n switch (depth) {\n case 1:\n headingLevel = HeadingLevel.TITLE;\n break;\n case 2:\n headingLevel = HeadingLevel.HEADING_1;\n break;\n case 3:\n headingLevel = HeadingLevel.HEADING_2;\n break;\n case 4:\n headingLevel = HeadingLevel.HEADING_3;\n break;\n case 5:\n headingLevel = HeadingLevel.HEADING_4;\n break;\n case 6:\n headingLevel = HeadingLevel.HEADING_5;\n break;\n }\n const nodes = ctx.render(children);\n return new Paragraph({\n heading: headingLevel,\n children: nodes,\n });\n};\n\nconst buildThematicBreak: NodeBuilder<\"thematicBreak\"> = () => {\n // Returning empty array at toplevel means section insertion.\n return [];\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 isTopLevel = !ctx.list;\n const reference =\n isTopLevel && ordered\n ? ctx.numbering.create()\n : ctx.list?.reference || ORDERED_LIST_REF;\n\n return ctx.render(children, {\n ...ctx,\n list: {\n level: isTopLevel ? 0 : ctx.list.level + 1,\n ordered: !!ordered,\n reference,\n },\n });\n};\n\nconst buildListItem: NodeBuilder<\"listItem\"> = ({ children, checked }, ctx) => {\n return ctx.render(children, {\n ...ctx,\n ...(ctx.list && { list: { ...ctx.list, checked: checked ?? undefined } }),\n });\n};\n\nconst buildTable: NodeBuilder<\"table\"> = ({ children, align }, ctx) => {\n const cellAligns:\n | (typeof AlignmentType)[keyof typeof AlignmentType][]\n | undefined = align?.map((a) => {\n switch (a) {\n case \"left\":\n return AlignmentType.LEFT;\n case \"right\":\n return AlignmentType.RIGHT;\n case \"center\":\n return AlignmentType.CENTER;\n default:\n return AlignmentType.LEFT;\n }\n });\n\n const columnLength = children[0]!.children.length;\n const columnWidth = CONTENT_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: cellAligns?.[i],\n children: ctx.render(c.children),\n }),\n ],\n });\n }),\n });\n }),\n });\n};\n\nconst buildText: NodeBuilder<\"text\"> = ({ value }, { deco }) => {\n return new TextRun({\n text: value,\n bold: deco.bold,\n italics: deco.italic,\n strike: deco.strike,\n });\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 }) => {\n return new TextRun({\n text: value,\n highlight: \"lightGray\",\n });\n};\n\nconst buildBreak: NodeBuilder<\"break\"> = () => {\n return new TextRun({ text: \"\", break: 1 });\n};\n\nconst buildLink: NodeBuilder<\"link\"> = ({ children, url }, ctx) => {\n const nodes = ctx.render(children);\n return new ExternalHyperlink({\n link: url,\n children: nodes,\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 ctx.footnote.def(\n identifier,\n ctx.render(children).filter((c) => c instanceof Paragraph),\n );\n return null;\n};\n\nconst buildFootnoteReference: NodeBuilder<\"footnoteReference\"> = (\n { identifier },\n ctx,\n) => {\n return new FootnoteReferenceRun(ctx.footnote.ref(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,aAAa,CAAC,OAAO,CAAC,EAAE;AACpC,QAAA,aAAa,CAAC,OAAO,CAAC,GAAG,IAAI;AAC7B,QAAA,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC;IACvB;AACF;;ACwBA,MAAM,aAAa,GACjB,uBAAuB,CAAC,KAAK;AAC7B,IAAA,qBAAqB,CAAC,IAAI;IAC1B,qBAAqB,CAAC,KAAK;AAC7B,MAAM,gBAAgB,GAAG,SAAS;AAClC,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,UA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,CAAC;AAC5D,CAAC;;AC7gBD,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,10 +1,10 @@
|
|
|
1
1
|
import { type IPropertiesOptions } from "docx";
|
|
2
|
-
import type * as mdast from "
|
|
2
|
+
import type * as mdast from "mdast";
|
|
3
3
|
import type { RemarkDocxPlugin } from "./types";
|
|
4
4
|
export interface DocxOptions extends Pick<IPropertiesOptions, "title" | "subject" | "creator" | "keywords" | "description" | "lastModifiedBy" | "revision" | "styles" | "background"> {
|
|
5
5
|
/**
|
|
6
|
-
* Plugins to customize how mdast nodes are
|
|
6
|
+
* Plugins to customize how mdast nodes are compiled.
|
|
7
7
|
*/
|
|
8
8
|
plugins?: RemarkDocxPlugin[];
|
|
9
9
|
}
|
|
10
|
-
export declare const mdastToDocx: (node: mdast.Root, { plugins, title, subject, creator, keywords, description, lastModifiedBy, revision, styles, background, }
|
|
10
|
+
export declare const mdastToDocx: (node: mdast.Root, { plugins, title, subject, creator, keywords, description, lastModifiedBy, revision, styles, background, }?: DocxOptions) => Promise<ArrayBuffer>;
|
package/lib/plugin.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Plugin } from "unified";
|
|
2
2
|
import type { Root } from "mdast";
|
|
3
|
-
import { type DocxOptions } from "./mdast-to-docx";
|
|
3
|
+
import { type DocxOptions } from "./mdast-util-to-docx";
|
|
4
4
|
export type { DocxOptions };
|
|
5
5
|
declare module "unified" {
|
|
6
6
|
interface CompileResultMap {
|
|
@@ -9,7 +9,7 @@ var hastUtilToMdast = require('hast-util-to-mdast');
|
|
|
9
9
|
const htmlPlugin = () => {
|
|
10
10
|
return async () => {
|
|
11
11
|
return {
|
|
12
|
-
html: ({ value },
|
|
12
|
+
html: ({ value }, ctx) => {
|
|
13
13
|
const hast = hastUtilFromHtml.fromHtml(value, { fragment: true });
|
|
14
14
|
const mdast = hastUtilToMdast.toMdast(hast, {
|
|
15
15
|
nodeHandlers: {
|
|
@@ -18,7 +18,7 @@ const htmlPlugin = () => {
|
|
|
18
18
|
},
|
|
19
19
|
},
|
|
20
20
|
});
|
|
21
|
-
return
|
|
21
|
+
return ctx.render(mdast.children);
|
|
22
22
|
},
|
|
23
23
|
};
|
|
24
24
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../../src/plugins/html/index.ts"],"sourcesContent":["import type { RemarkDocxPlugin } from \"../../types\";\nimport { fromHtml } from \"hast-util-from-html\";\nimport { toMdast } from \"hast-util-to-mdast\";\nimport type { Root } from \"mdast\";\n\n/**\n * A plugin to render \"html\" node.\n */\nexport const htmlPlugin = (): RemarkDocxPlugin => {\n return async () => {\n return {\n html: ({ value },
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../../src/plugins/html/index.ts"],"sourcesContent":["import type { RemarkDocxPlugin } from \"../../types\";\nimport { fromHtml } from \"hast-util-from-html\";\nimport { toMdast } from \"hast-util-to-mdast\";\nimport type { Root } from \"mdast\";\n\n/**\n * A plugin to render \"html\" node.\n */\nexport const htmlPlugin = (): RemarkDocxPlugin => {\n return async () => {\n return {\n html: ({ value }, ctx) => {\n const hast = fromHtml(value, { fragment: true });\n const mdast = toMdast(hast, {\n nodeHandlers: {\n comment: () => {\n // Ignore comment node to avoid \"RangeError: Maximum call stack size exceeded\"\n },\n },\n });\n return ctx.render((mdast as Root).children);\n },\n };\n };\n};\n"],"names":["fromHtml","toMdast"],"mappings":";;;;;AAKA;;AAEG;AACI,MAAM,UAAU,GAAG,MAAuB;IAC/C,OAAO,YAAW;QAChB,OAAO;YACL,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,GAAG,KAAI;AACvB,gBAAA,MAAM,IAAI,GAAGA,yBAAQ,CAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;AAChD,gBAAA,MAAM,KAAK,GAAGC,uBAAO,CAAC,IAAI,EAAE;AAC1B,oBAAA,YAAY,EAAE;wBACZ,OAAO,EAAE,MAAK;;wBAEd,CAAC;AACF,qBAAA;AACF,iBAAA,CAAC;gBACF,OAAO,GAAG,CAAC,MAAM,CAAE,KAAc,CAAC,QAAQ,CAAC;YAC7C,CAAC;SACF;AACH,IAAA,CAAC;AACH;;;;"}
|
|
@@ -7,7 +7,7 @@ import { toMdast } from 'hast-util-to-mdast';
|
|
|
7
7
|
const htmlPlugin = () => {
|
|
8
8
|
return async () => {
|
|
9
9
|
return {
|
|
10
|
-
html: ({ value },
|
|
10
|
+
html: ({ value }, ctx) => {
|
|
11
11
|
const hast = fromHtml(value, { fragment: true });
|
|
12
12
|
const mdast = toMdast(hast, {
|
|
13
13
|
nodeHandlers: {
|
|
@@ -16,7 +16,7 @@ const htmlPlugin = () => {
|
|
|
16
16
|
},
|
|
17
17
|
},
|
|
18
18
|
});
|
|
19
|
-
return
|
|
19
|
+
return ctx.render(mdast.children);
|
|
20
20
|
},
|
|
21
21
|
};
|
|
22
22
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/plugins/html/index.ts"],"sourcesContent":["import type { RemarkDocxPlugin } from \"../../types\";\nimport { fromHtml } from \"hast-util-from-html\";\nimport { toMdast } from \"hast-util-to-mdast\";\nimport type { Root } from \"mdast\";\n\n/**\n * A plugin to render \"html\" node.\n */\nexport const htmlPlugin = (): RemarkDocxPlugin => {\n return async () => {\n return {\n html: ({ value },
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/plugins/html/index.ts"],"sourcesContent":["import type { RemarkDocxPlugin } from \"../../types\";\nimport { fromHtml } from \"hast-util-from-html\";\nimport { toMdast } from \"hast-util-to-mdast\";\nimport type { Root } from \"mdast\";\n\n/**\n * A plugin to render \"html\" node.\n */\nexport const htmlPlugin = (): RemarkDocxPlugin => {\n return async () => {\n return {\n html: ({ value }, ctx) => {\n const hast = fromHtml(value, { fragment: true });\n const mdast = toMdast(hast, {\n nodeHandlers: {\n comment: () => {\n // Ignore comment node to avoid \"RangeError: Maximum call stack size exceeded\"\n },\n },\n });\n return ctx.render((mdast as Root).children);\n },\n };\n };\n};\n"],"names":[],"mappings":";;;AAKA;;AAEG;AACI,MAAM,UAAU,GAAG,MAAuB;IAC/C,OAAO,YAAW;QAChB,OAAO;YACL,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,GAAG,KAAI;AACvB,gBAAA,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;AAChD,gBAAA,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,EAAE;AAC1B,oBAAA,YAAY,EAAE;wBACZ,OAAO,EAAE,MAAK;;wBAEd,CAAC;AACF,qBAAA;AACF,iBAAA,CAAC;gBACF,OAAO,GAAG,CAAC,MAAM,CAAE,KAAc,CAAC,QAAQ,CAAC;YAC7C,CAAC;SACF;AACH,IAAA,CAAC;AACH;;;;"}
|