remark-docx 0.3.30 → 0.4.0

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
@@ -48,7 +48,7 @@ npm install remark-docx
48
48
 
49
49
  ### Browser
50
50
 
51
- ```javascript
51
+ ```ts
52
52
  import { unified } from "unified";
53
53
  import markdown from "remark-parse";
54
54
  import docx from "remark-docx";
@@ -60,14 +60,14 @@ const text = "# hello world";
60
60
 
61
61
  (async () => {
62
62
  const doc = await processor.process(text);
63
- const arrayBuffer = await doc.result;
64
- saveAs(new Blob([arrayBuffer]), "example.docx");
63
+ const uint8Array = doc.value;
64
+ saveAs(new Blob([uint8Array as BlobPart]), "example.docx");
65
65
  })();
66
66
  ```
67
67
 
68
68
  ### Node.js
69
69
 
70
- ```javascript
70
+ ```ts
71
71
  import { unified } from "unified";
72
72
  import markdown from "remark-parse";
73
73
  import docx from "remark-docx";
@@ -79,11 +79,20 @@ const text = "# hello world";
79
79
 
80
80
  (async () => {
81
81
  const doc = await processor.process(text);
82
- const arrayBuffer = await doc.result;
83
- fs.writeFileSync("example.docx", Buffer.from(arrayBuffer));
82
+ const uint8Array = doc.value;
83
+ fs.writeFileSync("example.docx", uint8Array);
84
84
  })();
85
85
  ```
86
86
 
87
+ ### CLI
88
+
89
+ See [remark-cli](https://github.com/remarkjs/remark/tree/main/packages/remark-cli) for usage.
90
+
91
+ ```sh
92
+ npm install remark-cli
93
+ npx remark input.md --use remark-docx --output output.docx
94
+ ```
95
+
87
96
  ## Plugins
88
97
 
89
98
  ### Image
package/lib/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- const e=require("./rolldown-runtime-BocRIvOZ.cjs"),t=require("./utils-D_YAYv4R.cjs");let n=require("docx"),r=require("mdast-util-definitions"),i=require("deepmerge");i=e.t(i,1);var a=`bullet`,o=`ordered`,s=`task-complete`,c=`task-incomplete`,l=`Hyperlink`,u=e=>({hanging:400,left:400*(e+1)}),ee=()=>{let e=new Map,t=new Map;return{id:t=>{let n=e.get(t);return n??e.set(t,n=e.size+1),n},set:(e,n)=>{t.set(e,n)},toConfig:()=>t.entries().reduce((e,[t,n])=>(e[t]={children:n},e),{})}},te=()=>{let e=1,t=[];return{createId:()=>{let n=`${o}-${e++}`;return t.push(n),n},getIds:()=>t}},d=(e,t)=>e.reduceRight((e,t)=>{for(let[n,r]of Object.entries(t)){let t=e[n];e[n]=t?(e,n)=>r(e,n)||t(e,n):r}return e},t),f=e=>e.map(({format:e,text:t},r)=>({level:r,format:n.LevelFormat[e],text:t,alignment:n.AlignmentType.LEFT,style:{paragraph:{indent:u(r)}}})),p=(e,t)=>{if(t.quote!=null&&(e.indent=u(t.quote+1)),t.list){let{level:n,meta:r}=t.list;e.numbering=r.type===`task`?{reference:r.checked?s:c,level:n}:r.type===`ordered`?{reference:r.reference,level:n}:{reference:a,level:n}}return t.rtl&&(e.bidirectional=!0),new n.Paragraph(e)},m=async(e,{plugins:o=[],title:l,subject:u,creator:p,keywords:m,description:k,styles:ue,size:A,margin:j,orientation:M,columns:N,spacing:P,direction:F,background:I,thematicBreak:L=`page`,orderedListFormat:R}={})=>{let z=(0,r.definitions)(e),B=te(),V=ee(),H=new Map,de={root:e,images:H,definition:z},fe=d(await Promise.all(o.map(e=>e(de))),{paragraph:h,heading:ne,thematicBreak:re,blockquote:ie,list:ae,listItem:oe,table:g,tableRow:D,tableCell:D,html:O,code:le,definition:D,footnoteDefinition:T,text:_,emphasis:v,strong:y,delete:se,inlineCode:ce,break:b,link:x,linkReference:S,image:C,imageReference:w,footnoteReference:E,math:O,inlineMath:O}),U=(e,n)=>{let r=fe[e.type];if(!r)return t.n(`${e.type} node is not supported without plugins.`),null;let i=r(e,n);return i?Array.isArray(i)?i:[i]:null},{WIDTH:W,HEIGHT:G}=n.sectionPageSizeDefaults;A&&(A.width!=null&&(W=A.width),A.height!=null&&(G=A.height));let{TOP:K,LEFT:q,BOTTOM:J,RIGHT:Y}=n.sectionMarginDefaults;j&&(j.top!=null&&(K=j.top),j.left!=null&&(q=j.left),j.bottom!=null&&(J=j.bottom),j.right!=null&&(Y=j.right));let pe={render(e,t){let n=[];for(let r of e){let e=U(r,t??this);e&&n.push(...e)}return n},width:W-q-Y,style:{},thematicBreak:L,rtl:F===`rtl`,definition:z,images:H,footnote:V,orderedId:B.createId},X=[[]];for(let t of e.children){let e=U(t,pe);e&&(e.length?X[X.length-1].push(...e):X.push([]))}let me=f(R??[{text:`%1.`,format:`DECIMAL`},{text:`%2.`,format:`DECIMAL`},{text:`%3.`,format:`DECIMAL`},{text:`%4.`,format:`DECIMAL`},{text:`%5.`,format:`DECIMAL`},{text:`%6.`,format:`DECIMAL`}]),he={column:N?{count:N}:void 0,page:{textDirection:F===`vertical`?`tbRl`:void 0,size:{width:W,height:G,orientation:M},margin:{top:K,left:q,bottom:J,right:Y}}},Z=new n.Document({title:l,subject:u,creator:p,keywords:m,description:k,styles:(0,i.default)({default:{document:{paragraph:{spacing:P?{after:P}:void 0}}}},ue||{}),background:I,sections:X.filter(e=>e.length).map(e=>({properties:he,children:e})),footnotes:V.toConfig(),numbering:{config:[{reference:a,levels:f([{text:`●`,format:`BULLET`},{text:`○`,format:`BULLET`},{text:`■`,format:`BULLET`},{text:`●`,format:`BULLET`},{text:`○`,format:`BULLET`},{text:`■`,format:`BULLET`}])},...B.getIds().map(e=>({reference:e,levels:me})),{reference:s,levels:f([{text:`☑`,format:`BULLET`},{text:`☑`,format:`BULLET`},{text:`☑`,format:`BULLET`},{text:`☑`,format:`BULLET`},{text:`☑`,format:`BULLET`},{text:`☑`,format:`BULLET`}])},{reference:c,levels:f([{text:`☐`,format:`BULLET`},{text:`☐`,format:`BULLET`},{text:`☐`,format:`BULLET`},{text:`☐`,format:`BULLET`},{text:`☐`,format:`BULLET`},{text:`☐`,format:`BULLET`}])}]}}),Q=`default-bullet-numbering`,$=Z.numbering;return $.abstractNumberingMap.delete(Q),$.concreteNumberingMap.delete(Q),n.Packer.toArrayBuffer(Z)},h=({children:e},t)=>p({children:t.render(e)},t),ne=({children:e,depth:t},r)=>{let i;switch(t){case 1:i=`TITLE`;break;case 2:i=`HEADING_1`;break;case 3:i=`HEADING_2`;break;case 4:i=`HEADING_3`;break;case 5:i=`HEADING_4`;break;case 6:i=`HEADING_5`}return p({heading:n.HeadingLevel[i],outlineLevel:t-1,children:r.render(e)},r)},re=(e,t)=>{switch(t.thematicBreak){case`page`:return new n.Paragraph({children:[new n.PageBreak]});case`section`:return[];case`line`:return new n.Paragraph({thematicBreak:!0})}},ie=({children:e},t)=>t.render(e,{...t,quote:t.quote==null?0:t.quote+1}),ae=({children:e,ordered:t},n)=>{let r=n.list,i;return i=t?{type:`ordered`,reference:r&&r.meta.type===`ordered`?r.meta.reference:n.orderedId()}:{type:`bullet`},n.render(e,{...n,list:{level:r?r.level+1:0,meta:i}})},oe=({children:e,checked:t},n)=>{let r=n.list;return r&&t!=null&&(r={level:r.level,meta:{type:`task`,checked:t}}),n.render(e,{...n,list:r})},g=({children:e,align:t},r)=>{let i=t?.map(e=>{switch(e){case`left`:return`LEFT`;case`right`:return`RIGHT`;case`center`:return`CENTER`;default:return`LEFT`}}),a=e[0].children.length,o=r.width/a,s={columnWidths:Array.from({length:a}).map(()=>o),rows:e.map(e=>new n.TableRow({children:e.children.map((e,t)=>new n.TableCell({width:{size:o,type:`dxa`},children:[new n.Paragraph({alignment:n.AlignmentType[i?.[t]??`LEFT`],children:r.render(e.children,{...r,rtl:void 0})})]}))}))};return r.rtl&&(s.visuallyRightToLeft=!0),new n.Table(s)},_=({value:e},{style:t,rtl:r})=>{let i={text:e,bold:t.bold,italics:t.italic,strike:t.strike};return t.inlineCode&&(i.highlight=`lightGray`),t.link&&(i.style=l),r&&(i.rightToLeft=!0),new n.TextRun(i)},v=({children:e},t)=>t.render(e,{...t,style:{...t.style,italic:!0}}),y=({children:e},t)=>t.render(e,{...t,style:{...t.style,bold:!0}}),se=({children:e},t)=>t.render(e,{...t,style:{...t.style,strike:!0}}),ce=({value:e},t)=>_({type:`text`,value:e},{...t,style:{...t.style,inlineCode:!0}}),b=()=>new n.TextRun({text:``,break:1}),x=({children:e,url:t},r)=>t.startsWith(`#`)?r.render(e):new n.ExternalHyperlink({link:t,children:r.render(e,{...r,style:{...r.style,link:!0}})}),S=({children:e,identifier:t},n)=>{let r=n.definition(t);return r==null?n.render(e):x({type:`link`,children:e,url:r.url},n)},C=(e,t)=>{let r=t.images.get(e.url);if(!r)return null;let{width:i,height:a}=r,o=t.width/1440*96;if(i>o){let e=o/i;i*=e,a*=e}let s=e.alt||e.title?{name:``,description:e.alt??void 0,title:e.title??void 0}:void 0;if(r.type===`svg`){let{type:e,data:t,fallback:o}=r;return new n.ImageRun({type:e,data:t,transformation:{width:i,height:a},fallback:{type:`png`,data:o},altText:s})}let{type:c,data:l}=r;return new n.ImageRun({type:c,data:l,transformation:{width:i,height:a},altText:s})},w=(e,t)=>{let n=t.definition(e.identifier);return n==null?null:C({type:`image`,url:n.url,alt:e.alt,title:n.title},t)},T=({children:e,identifier:t},r)=>{let i=r.render(e).filter(e=>e instanceof n.Paragraph);return r.footnote.set(r.footnote.id(t),i),null},E=({identifier:e},t)=>new n.FootnoteReferenceRun(t.footnote.id(e)),D=()=>null,O=(e,n)=>(t.n(`${e.type} node is not supported without plugins, falling back to text.`),_({type:`text`,value:e.value},n)),le=(e,r)=>(t.n(`${e.type} node is not supported without plugins, falling back to text.`),p({children:e.value.split(/\r?\n/).map((e,t)=>new n.TextRun({text:e,break:t===0?void 0:1}))},r)),k=function(e){this.compiler=t=>m(t,e)};module.exports=k;
1
+ const e=require("./rolldown-runtime-BocRIvOZ.cjs"),t=require("./utils-D_YAYv4R.cjs");let n=require("docx"),r=require("mdast-util-definitions"),i=require("deepmerge");i=e.t(i,1);var a=`bullet`,o=`ordered`,s=`task-complete`,c=`task-incomplete`,l=`Hyperlink`,u=e=>({hanging:400,left:400*(e+1)}),ee=()=>{let e=new Map,t=new Map;return{id:t=>{let n=e.get(t);return n??e.set(t,n=e.size+1),n},set:(e,n)=>{t.set(e,n)},toConfig:()=>t.entries().reduce((e,[t,n])=>(e[t]={children:n},e),{})}},te=()=>{let e=1,t=[];return{createId:()=>{let n=`${o}-${e++}`;return t.push(n),n},getIds:()=>t}},d=(e,t)=>e.reduceRight((e,t)=>{for(let[n,r]of Object.entries(t)){let t=e[n];e[n]=t?(e,n)=>r(e,n)||t(e,n):r}return e},t),f=e=>e.map(({format:e,text:t},r)=>({level:r,format:n.LevelFormat[e],text:t,alignment:n.AlignmentType.LEFT,style:{paragraph:{indent:u(r)}}})),p=(e,t)=>{if(t.quote!=null&&(e.indent=u(t.quote+1)),t.list){let{level:n,meta:r}=t.list;e.numbering=r.type===`task`?{reference:r.checked?s:c,level:n}:r.type===`ordered`?{reference:r.reference,level:n}:{reference:a,level:n}}return t.rtl&&(e.bidirectional=!0),new n.Paragraph(e)},m=async(e,{plugins:o=[],title:l,subject:u,creator:p,keywords:m,description:k,styles:ue,size:A,margin:j,orientation:M,columns:N,spacing:P,direction:F,background:I,thematicBreak:L=`page`,orderedListFormat:R}={})=>{let z=(0,r.definitions)(e),B=te(),V=ee(),H=new Map,de={root:e,images:H,definition:z},fe=d(await Promise.all(o.map(e=>e(de))),{paragraph:h,heading:ne,thematicBreak:re,blockquote:ie,list:ae,listItem:oe,table:g,tableRow:D,tableCell:D,html:O,code:le,definition:D,footnoteDefinition:T,text:_,emphasis:v,strong:y,delete:se,inlineCode:ce,break:b,link:x,linkReference:S,image:C,imageReference:w,footnoteReference:E,math:O,inlineMath:O}),U=(e,n)=>{let r=fe[e.type];if(!r)return t.n(`${e.type} node is not supported without plugins.`),null;let i=r(e,n);return i?Array.isArray(i)?i:[i]:null},{WIDTH:W,HEIGHT:G}=n.sectionPageSizeDefaults;A&&(A.width!=null&&(W=A.width),A.height!=null&&(G=A.height));let{TOP:K,LEFT:q,BOTTOM:J,RIGHT:Y}=n.sectionMarginDefaults;j&&(j.top!=null&&(K=j.top),j.left!=null&&(q=j.left),j.bottom!=null&&(J=j.bottom),j.right!=null&&(Y=j.right));let pe={render(e,t){let n=[];for(let r of e){let e=U(r,t??this);e&&n.push(...e)}return n},width:W-q-Y,style:{},thematicBreak:L,rtl:F===`rtl`,definition:z,images:H,footnote:V,orderedId:B.createId},X=[[]];for(let t of e.children){let e=U(t,pe);e&&(e.length?X[X.length-1].push(...e):X.push([]))}let me=f(R??[{text:`%1.`,format:`DECIMAL`},{text:`%2.`,format:`DECIMAL`},{text:`%3.`,format:`DECIMAL`},{text:`%4.`,format:`DECIMAL`},{text:`%5.`,format:`DECIMAL`},{text:`%6.`,format:`DECIMAL`}]),he={column:N?{count:N}:void 0,page:{textDirection:F===`vertical`?`tbRl`:void 0,size:{width:W,height:G,orientation:M},margin:{top:K,left:q,bottom:J,right:Y}}},Z=new n.Document({title:l,subject:u,creator:p,keywords:m,description:k,styles:(0,i.default)({default:{document:{paragraph:{spacing:P?{after:P}:void 0}}}},ue||{}),background:I,sections:X.filter(e=>e.length).map(e=>({properties:he,children:e})),footnotes:V.toConfig(),numbering:{config:[{reference:a,levels:f([{text:`●`,format:`BULLET`},{text:`○`,format:`BULLET`},{text:`■`,format:`BULLET`},{text:`●`,format:`BULLET`},{text:`○`,format:`BULLET`},{text:`■`,format:`BULLET`}])},...B.getIds().map(e=>({reference:e,levels:me})),{reference:s,levels:f([{text:`☑`,format:`BULLET`},{text:`☑`,format:`BULLET`},{text:`☑`,format:`BULLET`},{text:`☑`,format:`BULLET`},{text:`☑`,format:`BULLET`},{text:`☑`,format:`BULLET`}])},{reference:c,levels:f([{text:`☐`,format:`BULLET`},{text:`☐`,format:`BULLET`},{text:`☐`,format:`BULLET`},{text:`☐`,format:`BULLET`},{text:`☐`,format:`BULLET`},{text:`☐`,format:`BULLET`}])}]}}),Q=`default-bullet-numbering`,$=Z.numbering;return $.abstractNumberingMap.delete(Q),$.concreteNumberingMap.delete(Q),new Uint8Array(await n.Packer.toArrayBuffer(Z))},h=({children:e},t)=>p({children:t.render(e)},t),ne=({children:e,depth:t},r)=>{let i;switch(t){case 1:i=`TITLE`;break;case 2:i=`HEADING_1`;break;case 3:i=`HEADING_2`;break;case 4:i=`HEADING_3`;break;case 5:i=`HEADING_4`;break;case 6:i=`HEADING_5`}return p({heading:n.HeadingLevel[i],outlineLevel:t-1,children:r.render(e)},r)},re=(e,t)=>{switch(t.thematicBreak){case`page`:return new n.Paragraph({children:[new n.PageBreak]});case`section`:return[];case`line`:return new n.Paragraph({thematicBreak:!0})}},ie=({children:e},t)=>t.render(e,{...t,quote:t.quote==null?0:t.quote+1}),ae=({children:e,ordered:t},n)=>{let r=n.list,i;return i=t?{type:`ordered`,reference:r&&r.meta.type===`ordered`?r.meta.reference:n.orderedId()}:{type:`bullet`},n.render(e,{...n,list:{level:r?r.level+1:0,meta:i}})},oe=({children:e,checked:t},n)=>{let r=n.list;return r&&t!=null&&(r={level:r.level,meta:{type:`task`,checked:t}}),n.render(e,{...n,list:r})},g=({children:e,align:t},r)=>{let i=t?.map(e=>{switch(e){case`left`:return`LEFT`;case`right`:return`RIGHT`;case`center`:return`CENTER`;default:return`LEFT`}}),a=e[0].children.length,o=r.width/a,s={columnWidths:Array.from({length:a}).map(()=>o),rows:e.map(e=>new n.TableRow({children:e.children.map((e,t)=>new n.TableCell({width:{size:o,type:`dxa`},children:[new n.Paragraph({alignment:n.AlignmentType[i?.[t]??`LEFT`],children:r.render(e.children,{...r,rtl:void 0})})]}))}))};return r.rtl&&(s.visuallyRightToLeft=!0),new n.Table(s)},_=({value:e},{style:t,rtl:r})=>{let i={text:e,bold:t.bold,italics:t.italic,strike:t.strike};return t.inlineCode&&(i.highlight=`lightGray`),t.link&&(i.style=l),r&&(i.rightToLeft=!0),new n.TextRun(i)},v=({children:e},t)=>t.render(e,{...t,style:{...t.style,italic:!0}}),y=({children:e},t)=>t.render(e,{...t,style:{...t.style,bold:!0}}),se=({children:e},t)=>t.render(e,{...t,style:{...t.style,strike:!0}}),ce=({value:e},t)=>_({type:`text`,value:e},{...t,style:{...t.style,inlineCode:!0}}),b=()=>new n.TextRun({text:``,break:1}),x=({children:e,url:t},r)=>t.startsWith(`#`)?r.render(e):new n.ExternalHyperlink({link:t,children:r.render(e,{...r,style:{...r.style,link:!0}})}),S=({children:e,identifier:t},n)=>{let r=n.definition(t);return r==null?n.render(e):x({type:`link`,children:e,url:r.url},n)},C=(e,t)=>{let r=t.images.get(e.url);if(!r)return null;let{width:i,height:a}=r,o=t.width/1440*96;if(i>o){let e=o/i;i*=e,a*=e}let s=e.alt||e.title?{name:``,description:e.alt??void 0,title:e.title??void 0}:void 0;if(r.type===`svg`){let{type:e,data:t,fallback:o}=r;return new n.ImageRun({type:e,data:t,transformation:{width:i,height:a},fallback:{type:`png`,data:o},altText:s})}let{type:c,data:l}=r;return new n.ImageRun({type:c,data:l,transformation:{width:i,height:a},altText:s})},w=(e,t)=>{let n=t.definition(e.identifier);return n==null?null:C({type:`image`,url:n.url,alt:e.alt,title:n.title},t)},T=({children:e,identifier:t},r)=>{let i=r.render(e).filter(e=>e instanceof n.Paragraph);return r.footnote.set(r.footnote.id(t),i),null},E=({identifier:e},t)=>new n.FootnoteReferenceRun(t.footnote.id(e)),D=()=>null,O=(e,n)=>(t.n(`${e.type} node is not supported without plugins, falling back to text.`),_({type:`text`,value:e.value},n)),le=(e,r)=>(t.n(`${e.type} node is not supported without plugins, falling back to text.`),p({children:e.value.split(/\r?\n/).map((e,t)=>new n.TextRun({text:e,break:t===0?void 0:1}))},r)),k=function(e){return this.compiler=(e,t)=>t.data.docx,async(t,n)=>(n.data.docx=await m(t,e),t)};module.exports=k;
2
2
  //# sourceMappingURL=index.cjs.map
package/lib/index.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":[],"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 type FileChild,\n type ParagraphChild,\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 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\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: fallbackCode,\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 FileChild[],\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) as ParagraphChild[],\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 outlineLevel: depth - 1,\n children: ctx.render(children) as ParagraphChild[],\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 }) as ParagraphChild[],\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 }) as ParagraphChild[],\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 image = ctx.images.get(node.url);\n if (!image) {\n return null;\n }\n\n let { width, height } = image;\n const pageWidthInch = ctx.width / 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\nconst buildImageReference: NodeBuilder<\"imageReference\"> = (node, ctx) => {\n const def = ctx.definition(node.identifier);\n if (def == null) {\n return null;\n }\n return buildImage(\n { type: \"image\", url: def.url, alt: node.alt, title: def.title },\n ctx,\n );\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\nconst fallbackCode = (node: { type: string; value: string }, ctx: Context) => {\n warnOnce(\n `${node.type} node is not supported without plugins, falling back to text.`,\n );\n const children = node.value.split(/\\r?\\n/).map(\n (line, index) =>\n new TextRun({\n text: line,\n break: index === 0 ? undefined : 1,\n }),\n );\n return docxParagraph(\n {\n children,\n },\n ctx,\n );\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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,EAAU,CAAE,KAAM,OAAQ,MAAO,EAAK,KAAM,EAAG,CAAG,GAGrD,IAAgB,EAAuC,KAC3D,EAAA,EACE,GAAG,EAAK,KAAK,8DACf,EAQO,EACL,CACE,SATa,EAAK,MAAM,MAAM,OAAO,CAAC,CAAC,KACxC,EAAM,IACL,IAAI,EAAA,QAAQ,CACV,KAAM,EACN,MAAO,IAAU,EAAI,IAAA,GAAY,CACnC,CAAC,CAID,CACF,EACA,CACF,GC5zBI,EAA6D,SACjE,EACA,CACA,KAAK,SAAY,GACR,EAAY,EAAc,CAAI,CAEzC"}
1
+ {"version":3,"file":"index.cjs","names":[],"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 type FileChild,\n type ParagraphChild,\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 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\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<Uint8Array> => {\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: fallbackCode,\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 FileChild[],\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 new Uint8Array(await Packer.toArrayBuffer(doc));\n};\n\nconst buildParagraph: NodeBuilder<\"paragraph\"> = ({ children }, ctx) => {\n return docxParagraph(\n {\n children: ctx.render(children) as ParagraphChild[],\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 outlineLevel: depth - 1,\n children: ctx.render(children) as ParagraphChild[],\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 }) as ParagraphChild[],\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 }) as ParagraphChild[],\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 image = ctx.images.get(node.url);\n if (!image) {\n return null;\n }\n\n let { width, height } = image;\n const pageWidthInch = ctx.width / 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\nconst buildImageReference: NodeBuilder<\"imageReference\"> = (node, ctx) => {\n const def = ctx.definition(node.identifier);\n if (def == null) {\n return null;\n }\n return buildImage(\n { type: \"image\", url: def.url, alt: node.alt, title: def.title },\n ctx,\n );\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\nconst fallbackCode = (node: { type: string; value: string }, ctx: Context) => {\n warnOnce(\n `${node.type} node is not supported without plugins, falling back to text.`,\n );\n const children = node.value.split(/\\r?\\n/).map(\n (line, index) =>\n new TextRun({\n text: line,\n break: index === 0 ? undefined : 1,\n }),\n );\n return docxParagraph(\n {\n children,\n },\n ctx,\n );\n};\n","import type { Plugin, Transformer } from \"unified\";\nimport type { Root } from \"mdast\";\nimport { mdastToDocx, type DocxOptions } from \"./mdast-util-to-docx\";\n\nexport type { DocxOptions };\n\n/**\n * @internal\n */\ndeclare module \"vfile\" {\n interface DataMap {\n docx: Uint8Array;\n }\n}\n\nconst plugin: Plugin<[DocxOptions?], Root, Uint8Array> = function (opts) {\n this.compiler = (_, file) => {\n // unified compiler must be a synchronous function according to the spec.\n // However this compiler is asynchrounous for a few inevitable reasons.\n // - `jszip` used by `docx` lib doesn't have synchronous zip function\n // - resolving assets such as images is asynchronous\n // So we use it in an async transformer and pass the result to compiler by VFile.data for now.\n return file.data.docx!;\n };\n\n const transformer: Transformer<Root, Root> = async (node, file) => {\n file.data.docx = await mdastToDocx(node as Root, opts);\n return node;\n };\n\n return transformer as any;\n};\nexport default plugin;\n"],"mappings":"iLA6CA,IAAM,EAAkB,SAClB,EAAmB,UACnB,EAAyB,gBACzB,EAA2B,kBAC3B,EAAqB,YAErB,EAAc,IAEX,CAAE,QAAS,IAAa,KAAM,KAAe,EAAI,EAAG,GAGvD,OAAiD,CACrD,IAAM,EAAiB,IAAI,IACrB,EAAO,IAAI,IAEjB,MAAO,CACL,GAAK,GAAO,CACV,IAAI,EAAa,EAAe,IAAI,CAAE,EAItC,OAHI,GACF,EAAe,IAAI,EAAK,EAAa,EAAe,KAAO,CAAE,EAExD,CACT,EACA,KAAM,EAAI,IAAQ,CAChB,EAAK,IAAI,EAAI,CAAG,CAClB,EACA,aACS,EAAK,QAAQ,CAAC,CAAC,QACnB,EAAK,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,CAAI,EAC9C,EAIX"}
package/lib/index.js CHANGED
@@ -265,7 +265,7 @@ var _ = "bullet", v = "ordered", y = "task-complete", b = "task-incomplete", x =
265
265
  }
266
266
  ] }
267
267
  }), Q = "default-bullet-numbering", $ = Z.numbering;
268
- return $.abstractNumberingMap.delete(Q), $.concreteNumberingMap.delete(Q), c.toArrayBuffer(Z);
268
+ return $.abstractNumberingMap.delete(Q), $.concreteNumberingMap.delete(Q), new Uint8Array(await c.toArrayBuffer(Z));
269
269
  }, ae = ({ children: e }, t) => w({ children: t.render(e) }, t), E = ({ children: e, depth: t }, n) => {
270
270
  let r;
271
271
  switch (t) {
@@ -460,7 +460,7 @@ var _ = "bullet", v = "ordered", y = "task-complete", b = "task-incomplete", x =
460
460
  text: e,
461
461
  break: t === 0 ? void 0 : 1
462
462
  })) }, n)), z = function(e) {
463
- this.compiler = (t) => T(t, e);
463
+ return this.compiler = (e, t) => t.data.docx, async (t, n) => (n.data.docx = await T(t, e), t);
464
464
  };
465
465
  //#endregion
466
466
  export { z as default };
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"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 type FileChild,\n type ParagraphChild,\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 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\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: fallbackCode,\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 FileChild[],\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) as ParagraphChild[],\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 outlineLevel: depth - 1,\n children: ctx.render(children) as ParagraphChild[],\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 }) as ParagraphChild[],\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 }) as ParagraphChild[],\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 image = ctx.images.get(node.url);\n if (!image) {\n return null;\n }\n\n let { width, height } = image;\n const pageWidthInch = ctx.width / 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\nconst buildImageReference: NodeBuilder<\"imageReference\"> = (node, ctx) => {\n const def = ctx.definition(node.identifier);\n if (def == null) {\n return null;\n }\n return buildImage(\n { type: \"image\", url: def.url, alt: node.alt, title: def.title },\n ctx,\n );\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\nconst fallbackCode = (node: { type: string; value: string }, ctx: Context) => {\n warnOnce(\n `${node.type} node is not supported without plugins, falling back to text.`,\n );\n const children = node.value.split(/\\r?\\n/).map(\n (line, index) =>\n new TextRun({\n text: line,\n break: index === 0 ? undefined : 1,\n }),\n );\n return docxParagraph(\n {\n children,\n },\n ctx,\n );\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"],"mappings":";;;;;AA6CA,IAAM,IAAkB,UAClB,IAAmB,WACnB,IAAyB,iBACzB,IAA2B,mBAC3B,IAAqB,aAErB,KAAc,OAEX;CAAE,SAAS;CAAa,MAAM,OAAe,IAAI;AAAG,IAGvD,WAAiD;CACrD,IAAM,oBAAiB,IAAI,IAAoB,GACzC,oBAAO,IAAI,IAAyB;CAE1C,OAAO;EACL,KAAK,MAAO;GACV,IAAI,IAAa,EAAe,IAAI,CAAE;GAItC,OAHI,KACF,EAAe,IAAI,GAAK,IAAa,EAAe,OAAO,CAAE,GAExD;EACT;EACA,MAAM,GAAI,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Z;GACA;GACN,gBAAgB;IACd;IACA;GACF;GAEA,UAAU;IAAE,MAAM;IAAO,MAAM;GAAS;GACxC;EACF,CAAC;CACH;CAEA,IAAM,EAAE,SAAM,YAAS;CACvB,OAAO,IAAI,EAAS;EACZ;EACA;EACN,gBAAgB;GACd;GACA;EACF;EACA;CACF,CAAC;AACH,GAEM,KAAsD,GAAM,MAAQ;CACxE,IAAM,IAAM,EAAI,WAAW,EAAK,UAAU;CAI1C,OAHI,KAAO,OACF,OAEF,EACL;EAAE,MAAM;EAAS,KAAK,EAAI;EAAK,KAAK,EAAK;EAAK,OAAO,EAAI;CAAM,GAC/D,CACF;AACF,GAEM,KACJ,EAAE,aAAU,iBACZ,MACG;CACH,IAAM,IAAW,EAAI,OAAO,CAAQ,CAAC,CAAC,QAAQ,MAAM,aAAa,CAAS;CAE1E,OADA,EAAI,SAAS,IAAI,EAAI,SAAS,GAAG,CAAU,GAAG,CAAQ,GAC/C;AACT,GAEM,KACJ,EAAE,iBACF,MAEO,IAAI,EAAqB,EAAI,SAAS,GAAG,CAAU,CAAC,GAGvD,UACG,MAGH,KAAgB,GAAuC,OAC3D,EACE,GAAG,EAAK,KAAK,8DACf,GACO,EAAU;CAAE,MAAM;CAAQ,OAAO,EAAK;AAAM,GAAG,CAAG,IAGrD,KAAgB,GAAuC,OAC3D,EACE,GAAG,EAAK,KAAK,8DACf,GAQO,EACL,EACE,UATa,EAAK,MAAM,MAAM,OAAO,CAAC,CAAC,KACxC,GAAM,MACL,IAAI,EAAQ;CACV,MAAM;CACN,OAAO,MAAU,IAAI,KAAA,IAAY;AACnC,CAAC,CAID,EACF,GACA,CACF,IC5zBI,IAA6D,SACjE,GACA;CACA,KAAK,YAAY,MACR,EAAY,GAAc,CAAI;AAEzC"}
1
+ {"version":3,"file":"index.js","names":[],"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 type FileChild,\n type ParagraphChild,\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 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\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<Uint8Array> => {\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: fallbackCode,\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 FileChild[],\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 new Uint8Array(await Packer.toArrayBuffer(doc));\n};\n\nconst buildParagraph: NodeBuilder<\"paragraph\"> = ({ children }, ctx) => {\n return docxParagraph(\n {\n children: ctx.render(children) as ParagraphChild[],\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 outlineLevel: depth - 1,\n children: ctx.render(children) as ParagraphChild[],\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 }) as ParagraphChild[],\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 }) as ParagraphChild[],\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 image = ctx.images.get(node.url);\n if (!image) {\n return null;\n }\n\n let { width, height } = image;\n const pageWidthInch = ctx.width / 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\nconst buildImageReference: NodeBuilder<\"imageReference\"> = (node, ctx) => {\n const def = ctx.definition(node.identifier);\n if (def == null) {\n return null;\n }\n return buildImage(\n { type: \"image\", url: def.url, alt: node.alt, title: def.title },\n ctx,\n );\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\nconst fallbackCode = (node: { type: string; value: string }, ctx: Context) => {\n warnOnce(\n `${node.type} node is not supported without plugins, falling back to text.`,\n );\n const children = node.value.split(/\\r?\\n/).map(\n (line, index) =>\n new TextRun({\n text: line,\n break: index === 0 ? undefined : 1,\n }),\n );\n return docxParagraph(\n {\n children,\n },\n ctx,\n );\n};\n","import type { Plugin, Transformer } from \"unified\";\nimport type { Root } from \"mdast\";\nimport { mdastToDocx, type DocxOptions } from \"./mdast-util-to-docx\";\n\nexport type { DocxOptions };\n\n/**\n * @internal\n */\ndeclare module \"vfile\" {\n interface DataMap {\n docx: Uint8Array;\n }\n}\n\nconst plugin: Plugin<[DocxOptions?], Root, Uint8Array> = function (opts) {\n this.compiler = (_, file) => {\n // unified compiler must be a synchronous function according to the spec.\n // However this compiler is asynchrounous for a few inevitable reasons.\n // - `jszip` used by `docx` lib doesn't have synchronous zip function\n // - resolving assets such as images is asynchronous\n // So we use it in an async transformer and pass the result to compiler by VFile.data for now.\n return file.data.docx!;\n };\n\n const transformer: Transformer<Root, Root> = async (node, file) => {\n file.data.docx = await mdastToDocx(node as Root, opts);\n return node;\n };\n\n return transformer as any;\n};\nexport default plugin;\n"],"mappings":";;;;;AA6CA,IAAM,IAAkB,UAClB,IAAmB,WACnB,IAAyB,iBACzB,IAA2B,mBAC3B,IAAqB,aAErB,KAAc,OAEX;CAAE,SAAS;CAAa,MAAM,OAAe,IAAI;AAAG,IAGvD,WAAiD;CACrD,IAAM,oBAAiB,IAAI,IAAoB,GACzC,oBAAO,IAAI,IAAyB;CAE1C,OAAO;EACL,KAAK,MAAO;GACV,IAAI,IAAa,EAAe,IAAI,CAAE;GAItC,OAHI,KACF,EAAe,IAAI,GAAK,IAAa,EAAe,OAAO,CAAE,GAExD;EACT;EACA,MAAM,GAAI,MAAQ;GAChB,EAAK,IAAI,GAAI,CAAG;EAClB;EACA,gBACS,EAAK,QAAQ,CAAC,CAAC,QACnB,GAAK,CAAC,GAAK,QACV,EAAI,KAAO,EAAE,UAAU,EAAI,GACpB,IAET,CAAC,CAGH;CAEJ;AACF,GAWM,WAAuD;CAC3D,IAAI,IAAU,GAER,IAAgB,CAAC;CAEvB,OAAO;EACL,gBAAgB;GACd,IAAM,IAAK,GAAG,EAAiB,GAAG;GAElC,OADA,EAAI,KAAK,CAAE,GACJ;EACT;EACA,cACS;CAEX;AACF,GAEM,MACJ,GACA,MAEO,EAAgB,aAA2B,GAAK,MAAM;CAE3D,KAAK,IAAM,CAAC,GAAG,MAAQ,OAAO,QAAQ,CAAC,GAAG;EACxC,IAAM,IAAO,EAAI;EACjB,EAAI,KACF,KACK,GAAG,MACM,EAAI,GAAU,CACpB,KAGG,EAAK,GAAU,CAAC,IAEvB;CAER;CACA,O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AAS,GAAG,CAAU,GAAG,CAAQ,GAC/C;AACT,GAEM,KACJ,EAAE,iBACF,MAEO,IAAI,EAAqB,EAAI,SAAS,GAAG,CAAU,CAAC,GAGvD,UACG,MAGH,KAAgB,GAAuC,OAC3D,EACE,GAAG,EAAK,KAAK,8DACf,GACO,EAAU;CAAE,MAAM;CAAQ,OAAO,EAAK;AAAM,GAAG,CAAG,IAGrD,KAAgB,GAAuC,OAC3D,EACE,GAAG,EAAK,KAAK,8DACf,GAQO,EACL,EACE,UATa,EAAK,MAAM,MAAM,OAAO,CAAC,CAAC,KACxC,GAAM,MACL,IAAI,EAAQ;CACV,MAAM;CACN,OAAO,MAAU,IAAI,KAAA,IAAY;AACnC,CAAC,CAID,EACF,GACA,CACF,ICzzBI,IAAmD,SAAU,GAAM;CAevE,OAdA,KAAK,YAAY,GAAG,MAMX,EAAK,KAAK,MAQZ,OAL6C,GAAM,OACxD,EAAK,KAAK,OAAO,MAAM,EAAY,GAAc,CAAI,GAC9C;AAIX"}
@@ -63,5 +63,5 @@ export interface DocxOptions extends Pick<IPropertiesOptions, "title" | "subject
63
63
  */
64
64
  plugins?: RemarkDocxPlugin[];
65
65
  }
66
- export declare const mdastToDocx: (node: mdast.Root, { plugins, title, subject, creator, keywords, description, styles, size, margin, orientation, columns, spacing, direction, background, thematicBreak, orderedListFormat, }?: DocxOptions) => Promise<ArrayBuffer>;
66
+ export declare const mdastToDocx: (node: mdast.Root, { plugins, title, subject, creator, keywords, description, styles, size, margin, orientation, columns, spacing, direction, background, thematicBreak, orderedListFormat, }?: DocxOptions) => Promise<Uint8Array>;
67
67
  export {};
package/lib/plugin.d.ts CHANGED
@@ -2,10 +2,5 @@ import { Plugin } from 'unified';
2
2
  import { Root } from 'mdast';
3
3
  import { DocxOptions } from './mdast-util-to-docx';
4
4
  export type { DocxOptions };
5
- declare module "unified" {
6
- interface CompileResultMap {
7
- docx: Promise<ArrayBuffer>;
8
- }
9
- }
10
- declare const plugin: Plugin<[DocxOptions?], Root, Promise<ArrayBuffer>>;
5
+ declare const plugin: Plugin<[DocxOptions?], Root, Uint8Array>;
11
6
  export default plugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remark-docx",
3
- "version": "0.3.30",
3
+ "version": "0.4.0",
4
4
  "description": "remark plugin to compile markdown to docx (Microsoft Word, Office Open XML).",
5
5
  "main": "lib/index.cjs",
6
6
  "module": "lib/index.js",
@@ -25,7 +25,8 @@
25
25
  "sideEffects": false,
26
26
  "scripts": {
27
27
  "build": "vite build",
28
- "test": "vitest run",
28
+ "test": "vitest run --project unit",
29
+ "test:cli": "vitest run --project cli",
29
30
  "tsc": "tsc -p . --noEmit",
30
31
  "storybook": "storybook dev -p 6006",
31
32
  "storybook:build": "storybook build",
@@ -66,6 +67,7 @@
66
67
  "react": "^19.2.1",
67
68
  "react-dom": "^19.2.1",
68
69
  "react-is": "^19.2.1",
70
+ "remark-cli": "^12.0.1",
69
71
  "remark-frontmatter": "^5.0.0",
70
72
  "remark-gfm": "^4.0.0",
71
73
  "remark-math": "^6.0.0",