remark-docx 0.3.22 → 0.3.23

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 CHANGED
@@ -127,6 +127,8 @@ imagePlugin({
127
127
 
128
128
  ### Code
129
129
 
130
+ ### Syntax highlight
131
+
130
132
  Syntax highlighting with [shiki](https://github.com/shikijs/shiki).
131
133
 
132
134
  ```javascript
@@ -140,6 +142,21 @@ const processor = unified()
140
142
  .use(docx, { plugins: [shikiPlugin({ theme: "dark-plus" })] });
141
143
  ```
142
144
 
145
+ ### Mermaid
146
+
147
+ Render [Mermaid](https://mermaid.js.org/) in code blocks with `mermaid` language. It only works in browser for now.
148
+
149
+ ```javascript
150
+ import { unified } from "unified";
151
+ import markdown from "remark-parse";
152
+ import docx from "remark-docx";
153
+ import { mermaidPlugin } from "remark-docx/plugins/mermaid";
154
+
155
+ const processor = unified()
156
+ .use(markdown)
157
+ .use(docx, { plugins: [mermaidPlugin()] });
158
+ ```
159
+
143
160
  ### Math
144
161
 
145
162
  Render LaTeX with [MathJax](https://github.com/mathjax/MathJax).
package/lib/index.cjs CHANGED
@@ -114,11 +114,55 @@ const docxParagraph = (options, ctx) => {
114
114
  }
115
115
  return new docx.Paragraph(options);
116
116
  };
117
+ const docxImage = (image, node, { width: pageWidth }) => {
118
+ var _a, _b;
119
+ let { width, height } = image;
120
+ const pageWidthInch = pageWidth / 1440;
121
+ const DPI = 96;
122
+ const pageWidthPx = pageWidthInch * DPI;
123
+ if (width > pageWidthPx) {
124
+ const scale = pageWidthPx / width;
125
+ width *= scale;
126
+ height *= scale;
127
+ }
128
+ const altText = node.alt || node.title
129
+ ? {
130
+ name: "",
131
+ description: (_a = node.alt) !== null && _a !== void 0 ? _a : undefined,
132
+ title: (_b = node.title) !== null && _b !== void 0 ? _b : undefined,
133
+ }
134
+ : undefined;
135
+ if (image.type === "svg") {
136
+ const { type, data, fallback } = image;
137
+ return new docx.ImageRun({
138
+ type: type,
139
+ data: data,
140
+ transformation: {
141
+ width,
142
+ height,
143
+ },
144
+ // https://github.com/dolanmiu/docx/issues/1162#issuecomment-3228368003
145
+ fallback: { type: "png", data: fallback },
146
+ altText,
147
+ });
148
+ }
149
+ const { type, data } = image;
150
+ return new docx.ImageRun({
151
+ type: type,
152
+ data: data,
153
+ transformation: {
154
+ width,
155
+ height,
156
+ },
157
+ altText,
158
+ });
159
+ };
117
160
  const mdastToDocx = async (node, { plugins = [], title, subject, creator, keywords, description, styles, size, margin, orientation, columns, spacing, direction, background, thematicBreak = "page", orderedListFormat, } = {}) => {
118
161
  const definition = mdastUtilDefinitions.definitions(node);
119
162
  const ordered = createOrderedListRegistry();
120
163
  const footnote = createFootnoteRegistry();
121
- const pluginCtx = { root: node, definition };
164
+ const images = new Map();
165
+ const pluginCtx = { root: node, images, definition };
122
166
  const builders = composeBuilders(await Promise.all(plugins.map((p) => p(pluginCtx))), {
123
167
  paragraph: buildParagraph,
124
168
  heading: buildHeading,
@@ -141,8 +185,8 @@ const mdastToDocx = async (node, { plugins = [], title, subject, creator, keywor
141
185
  break: buildBreak,
142
186
  link: buildLink,
143
187
  linkReference: buildLinkReference,
144
- // image: warnImage,
145
- // imageReference: warnImage,
188
+ image: buildImage,
189
+ imageReference: buildImageReference,
146
190
  footnoteReference: buildFootnoteReference,
147
191
  math: fallbackText,
148
192
  inlineMath: fallbackText,
@@ -200,10 +244,11 @@ const mdastToDocx = async (node, { plugins = [], title, subject, creator, keywor
200
244
  return results;
201
245
  },
202
246
  width: pageWidth - marginLeft - marginRight,
203
- deco: {},
247
+ style: {},
204
248
  thematicBreak,
205
249
  rtl: direction === "rtl",
206
250
  definition: definition,
251
+ images,
207
252
  footnote,
208
253
  orderedId: ordered.createId,
209
254
  };
@@ -451,17 +496,17 @@ const buildTable = ({ children, align }, ctx) => {
451
496
  }
452
497
  return new docx.Table(options);
453
498
  };
454
- const buildText = ({ value }, { deco, rtl }) => {
499
+ const buildText = ({ value }, { style, rtl }) => {
455
500
  const options = {
456
501
  text: value,
457
- bold: deco.bold,
458
- italics: deco.italic,
459
- strike: deco.strike,
502
+ bold: style.bold,
503
+ italics: style.italic,
504
+ strike: style.strike,
460
505
  };
461
- if (deco.inlineCode) {
506
+ if (style.inlineCode) {
462
507
  options.highlight = "lightGray";
463
508
  }
464
- if (deco.link) {
509
+ if (style.link) {
465
510
  // https://docx.js.org/#/usage/hyperlinks?id=styling-hyperlinks
466
511
  options.style = HYPERLINK_STYLE_ID;
467
512
  }
@@ -473,25 +518,25 @@ const buildText = ({ value }, { deco, rtl }) => {
473
518
  const buildEmphasis = ({ children }, ctx) => {
474
519
  return ctx.render(children, {
475
520
  ...ctx,
476
- deco: { ...ctx.deco, italic: true },
521
+ style: { ...ctx.style, italic: true },
477
522
  });
478
523
  };
479
524
  const buildStrong = ({ children }, ctx) => {
480
525
  return ctx.render(children, {
481
526
  ...ctx,
482
- deco: { ...ctx.deco, bold: true },
527
+ style: { ...ctx.style, bold: true },
483
528
  });
484
529
  };
485
530
  const buildDelete = ({ children }, ctx) => {
486
531
  return ctx.render(children, {
487
532
  ...ctx,
488
- deco: { ...ctx.deco, strike: true },
533
+ style: { ...ctx.style, strike: true },
489
534
  });
490
535
  };
491
536
  const buildInlineCode = ({ value }, ctx) => {
492
537
  return buildText({ value }, {
493
538
  ...ctx,
494
- deco: { ...ctx.deco, inlineCode: true },
539
+ style: { ...ctx.style, inlineCode: true },
495
540
  });
496
541
  };
497
542
  const buildBreak = () => {
@@ -506,7 +551,7 @@ const buildLink = ({ children, url }, ctx) => {
506
551
  link: url,
507
552
  children: ctx.render(children, {
508
553
  ...ctx,
509
- deco: { ...ctx.deco, link: true },
554
+ style: { ...ctx.style, link: true },
510
555
  }),
511
556
  });
512
557
  };
@@ -517,6 +562,24 @@ const buildLinkReference = ({ children, identifier }, ctx) => {
517
562
  }
518
563
  return buildLink({ children, url: def.url }, ctx);
519
564
  };
565
+ const buildImage = (node, ctx) => {
566
+ const data = ctx.images.get(node.url);
567
+ if (!data) {
568
+ return null;
569
+ }
570
+ return docxImage(data, node, ctx);
571
+ };
572
+ const buildImageReference = (node, ctx) => {
573
+ const def = ctx.definition(node.identifier);
574
+ if (def == null) {
575
+ return null;
576
+ }
577
+ const data = ctx.images.get(def.url);
578
+ if (!data) {
579
+ return null;
580
+ }
581
+ return docxImage(data, { alt: node.alt, title: def.title }, ctx);
582
+ };
520
583
  const buildFootnoteDefinition = ({ children, identifier }, ctx) => {
521
584
  const contents = ctx.render(children).filter((c) => c instanceof docx.Paragraph);
522
585
  ctx.footnote.set(ctx.footnote.id(identifier), contents);
package/lib/index.cjs.map CHANGED
@@ -1 +1 @@
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 * Number of page columns.\n * @default 1\n */\n columns?: number;\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\" | \"vertical\";\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 columns,\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 column: columns ? { count: columns } : undefined,\n page: {\n textDirection: direction === \"vertical\" ? \"tbRl\" : undefined,\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,EA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B,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,EAAE,GAAG,CAAC;AAC5D,CAAC;;ACruBD,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.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 ImageRun,\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 DocxImageData,\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\nconst docxImage = (\n image: DocxImageData,\n node: { alt?: string | null; title?: string | null },\n { width: pageWidth }: Context,\n) => {\n let { width, height } = image;\n\n const pageWidthInch = pageWidth / 1440;\n const DPI = 96;\n const pageWidthPx = pageWidthInch * DPI;\n if (width > pageWidthPx) {\n const scale = pageWidthPx / width;\n width *= scale;\n height *= scale;\n }\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, 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 } = image;\n return new ImageRun({\n type: type,\n data: data,\n transformation: {\n width,\n height,\n },\n altText,\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 * Page orientation.\n * @default \"portrait\"\n */\n orientation?: \"portrait\" | \"landscape\";\n /**\n * Number of page columns.\n * @default 1\n */\n columns?: number;\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\" | \"vertical\";\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 columns,\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 images = new Map<string, DocxImageData>();\n const pluginCtx = { root: node, images, 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: buildImage,\n imageReference: buildImageReference,\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 style: {},\n thematicBreak,\n rtl: direction === \"rtl\",\n definition: definition,\n images,\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 column: columns ? { count: columns } : undefined,\n page: {\n textDirection: direction === \"vertical\" ? \"tbRl\" : undefined,\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 }, { style, rtl }) => {\n const options: Writeable<IRunOptions> = {\n text: value,\n bold: style.bold,\n italics: style.italic,\n strike: style.strike,\n };\n if (style.inlineCode) {\n options.highlight = \"lightGray\";\n }\n if (style.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 style: { ...ctx.style, italic: true },\n });\n};\n\nconst buildStrong: NodeBuilder<\"strong\"> = ({ children }, ctx) => {\n return ctx.render(children, {\n ...ctx,\n style: { ...ctx.style, bold: true },\n });\n};\n\nconst buildDelete: NodeBuilder<\"delete\"> = ({ children }, ctx) => {\n return ctx.render(children, {\n ...ctx,\n style: { ...ctx.style, strike: true },\n });\n};\n\nconst buildInlineCode: NodeBuilder<\"inlineCode\"> = ({ value }, ctx) => {\n return buildText(\n { type: \"text\", value },\n {\n ...ctx,\n style: { ...ctx.style, 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 style: { ...ctx.style, 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 buildImage: NodeBuilder<\"image\"> = (node, ctx) => {\n const data = ctx.images.get(node.url);\n if (!data) {\n return null;\n }\n return docxImage(data, node, ctx);\n};\n\nconst buildImageReference: NodeBuilder<\"imageReference\"> = (node, ctx) => {\n const def = ctx.definition(node.identifier);\n if (def == null) {\n return null;\n }\n const data = ctx.images.get(def.url);\n if (!data) {\n return null;\n }\n return docxImage(data, { alt: node.alt, title: def.title }, 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","ImageRun","definitions","warnOnce","sectionPageSizeDefaults","sectionMarginDefaults","Document","Packer","HeadingLevel","PageBreak","TableRow","TableCell","Table","TextRun","ExternalHyperlink","FootnoteReferenceRun"],"mappings":";;;;;;;AA4CA,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,GAAG,CAAC,EAAE;YAChE;AACA,YAAA,OAAO,UAAU;QACnB,CAAC;AACD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,CAAC;AACvD,IAAA,OAAO,IAAI;AACb,CAAC;AAED,MAAM,sBAAsB,GAAqC,CAC/D,EAAE,UAAU,EAAE,EACd,GAAG,KACD;AACF,IAAA,OAAO,IAAIe,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;;ACjzBD,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,4 +1,4 @@
1
- import { sectionPageSizeDefaults, sectionMarginDefaults, Document, Packer, AlignmentType, LevelFormat, FootnoteReferenceRun, ExternalHyperlink, TextRun, Paragraph, TableRow, TableCell, Table, PageBreak, HeadingLevel } from 'docx';
1
+ import { sectionPageSizeDefaults, sectionMarginDefaults, Document, Packer, AlignmentType, LevelFormat, FootnoteReferenceRun, ExternalHyperlink, TextRun, Paragraph, TableRow, TableCell, Table, PageBreak, HeadingLevel, ImageRun } from 'docx';
2
2
  import { w as warnOnce } from './utils-BWBt3EKb.js';
3
3
  import { definitions } from 'mdast-util-definitions';
4
4
  import deepmerge from 'deepmerge';
@@ -112,11 +112,55 @@ const docxParagraph = (options, ctx) => {
112
112
  }
113
113
  return new Paragraph(options);
114
114
  };
115
+ const docxImage = (image, node, { width: pageWidth }) => {
116
+ var _a, _b;
117
+ let { width, height } = image;
118
+ const pageWidthInch = pageWidth / 1440;
119
+ const DPI = 96;
120
+ const pageWidthPx = pageWidthInch * DPI;
121
+ if (width > pageWidthPx) {
122
+ const scale = pageWidthPx / width;
123
+ width *= scale;
124
+ height *= scale;
125
+ }
126
+ const altText = node.alt || node.title
127
+ ? {
128
+ name: "",
129
+ description: (_a = node.alt) !== null && _a !== void 0 ? _a : undefined,
130
+ title: (_b = node.title) !== null && _b !== void 0 ? _b : undefined,
131
+ }
132
+ : undefined;
133
+ if (image.type === "svg") {
134
+ const { type, data, fallback } = image;
135
+ return new ImageRun({
136
+ type: type,
137
+ data: data,
138
+ transformation: {
139
+ width,
140
+ height,
141
+ },
142
+ // https://github.com/dolanmiu/docx/issues/1162#issuecomment-3228368003
143
+ fallback: { type: "png", data: fallback },
144
+ altText,
145
+ });
146
+ }
147
+ const { type, data } = image;
148
+ return new ImageRun({
149
+ type: type,
150
+ data: data,
151
+ transformation: {
152
+ width,
153
+ height,
154
+ },
155
+ altText,
156
+ });
157
+ };
115
158
  const mdastToDocx = async (node, { plugins = [], title, subject, creator, keywords, description, styles, size, margin, orientation, columns, spacing, direction, background, thematicBreak = "page", orderedListFormat, } = {}) => {
116
159
  const definition = definitions(node);
117
160
  const ordered = createOrderedListRegistry();
118
161
  const footnote = createFootnoteRegistry();
119
- const pluginCtx = { root: node, definition };
162
+ const images = new Map();
163
+ const pluginCtx = { root: node, images, definition };
120
164
  const builders = composeBuilders(await Promise.all(plugins.map((p) => p(pluginCtx))), {
121
165
  paragraph: buildParagraph,
122
166
  heading: buildHeading,
@@ -139,8 +183,8 @@ const mdastToDocx = async (node, { plugins = [], title, subject, creator, keywor
139
183
  break: buildBreak,
140
184
  link: buildLink,
141
185
  linkReference: buildLinkReference,
142
- // image: warnImage,
143
- // imageReference: warnImage,
186
+ image: buildImage,
187
+ imageReference: buildImageReference,
144
188
  footnoteReference: buildFootnoteReference,
145
189
  math: fallbackText,
146
190
  inlineMath: fallbackText,
@@ -198,10 +242,11 @@ const mdastToDocx = async (node, { plugins = [], title, subject, creator, keywor
198
242
  return results;
199
243
  },
200
244
  width: pageWidth - marginLeft - marginRight,
201
- deco: {},
245
+ style: {},
202
246
  thematicBreak,
203
247
  rtl: direction === "rtl",
204
248
  definition: definition,
249
+ images,
205
250
  footnote,
206
251
  orderedId: ordered.createId,
207
252
  };
@@ -449,17 +494,17 @@ const buildTable = ({ children, align }, ctx) => {
449
494
  }
450
495
  return new Table(options);
451
496
  };
452
- const buildText = ({ value }, { deco, rtl }) => {
497
+ const buildText = ({ value }, { style, rtl }) => {
453
498
  const options = {
454
499
  text: value,
455
- bold: deco.bold,
456
- italics: deco.italic,
457
- strike: deco.strike,
500
+ bold: style.bold,
501
+ italics: style.italic,
502
+ strike: style.strike,
458
503
  };
459
- if (deco.inlineCode) {
504
+ if (style.inlineCode) {
460
505
  options.highlight = "lightGray";
461
506
  }
462
- if (deco.link) {
507
+ if (style.link) {
463
508
  // https://docx.js.org/#/usage/hyperlinks?id=styling-hyperlinks
464
509
  options.style = HYPERLINK_STYLE_ID;
465
510
  }
@@ -471,25 +516,25 @@ const buildText = ({ value }, { deco, rtl }) => {
471
516
  const buildEmphasis = ({ children }, ctx) => {
472
517
  return ctx.render(children, {
473
518
  ...ctx,
474
- deco: { ...ctx.deco, italic: true },
519
+ style: { ...ctx.style, italic: true },
475
520
  });
476
521
  };
477
522
  const buildStrong = ({ children }, ctx) => {
478
523
  return ctx.render(children, {
479
524
  ...ctx,
480
- deco: { ...ctx.deco, bold: true },
525
+ style: { ...ctx.style, bold: true },
481
526
  });
482
527
  };
483
528
  const buildDelete = ({ children }, ctx) => {
484
529
  return ctx.render(children, {
485
530
  ...ctx,
486
- deco: { ...ctx.deco, strike: true },
531
+ style: { ...ctx.style, strike: true },
487
532
  });
488
533
  };
489
534
  const buildInlineCode = ({ value }, ctx) => {
490
535
  return buildText({ value }, {
491
536
  ...ctx,
492
- deco: { ...ctx.deco, inlineCode: true },
537
+ style: { ...ctx.style, inlineCode: true },
493
538
  });
494
539
  };
495
540
  const buildBreak = () => {
@@ -504,7 +549,7 @@ const buildLink = ({ children, url }, ctx) => {
504
549
  link: url,
505
550
  children: ctx.render(children, {
506
551
  ...ctx,
507
- deco: { ...ctx.deco, link: true },
552
+ style: { ...ctx.style, link: true },
508
553
  }),
509
554
  });
510
555
  };
@@ -515,6 +560,24 @@ const buildLinkReference = ({ children, identifier }, ctx) => {
515
560
  }
516
561
  return buildLink({ children, url: def.url }, ctx);
517
562
  };
563
+ const buildImage = (node, ctx) => {
564
+ const data = ctx.images.get(node.url);
565
+ if (!data) {
566
+ return null;
567
+ }
568
+ return docxImage(data, node, ctx);
569
+ };
570
+ const buildImageReference = (node, ctx) => {
571
+ const def = ctx.definition(node.identifier);
572
+ if (def == null) {
573
+ return null;
574
+ }
575
+ const data = ctx.images.get(def.url);
576
+ if (!data) {
577
+ return null;
578
+ }
579
+ return docxImage(data, { alt: node.alt, title: def.title }, ctx);
580
+ };
518
581
  const buildFootnoteDefinition = ({ children, identifier }, ctx) => {
519
582
  const contents = ctx.render(children).filter((c) => c instanceof Paragraph);
520
583
  ctx.footnote.set(ctx.footnote.id(identifier), contents);