mdast2docx 0.0.0-beta.0 → 0.0.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
@@ -1,170 +1,203 @@
1
- # **MDAST (Markdown Abstract Syntax Tree) to DOCX** <img src="https://raw.githubusercontent.com/mayank1513/mayank1513/main/popper.png" style="height: 40px"/>
2
-
3
- 🚀 **Effortlessly convert Markdown Abstract Syntax Trees (MDAST) to DOCX.**
4
-
5
- [![Test](https://github.com/tiny-md/mdast2docx/actions/workflows/test.yml/badge.svg)](https://github.com/tiny-md/mdast2docx/actions/workflows/test.yml) [![Maintainability](https://api.codeclimate.com/v1/badges/aa896ec14c570f3bb274/maintainability)](https://codeclimate.com/github/tiny-md/mdast2docx/maintainability) [![Code Coverage](https://codecov.io/gh/tiny-md/mdast2docx/graph/badge.svg)](https://codecov.io/gh/tiny-md/mdast2docx) [![Version](https://img.shields.io/npm/v/mdast2docx.svg?colorB=green)](https://www.npmjs.com/package/mdast2docx) [![Downloads](https://img.shields.io/npm/d18m/mdast2docx)](https://www.npmjs.com/package/mdast2docx) ![Bundle Size](https://img.shields.io/bundlephobia/minzip/mdast2docx)
6
-
7
- ---
8
-
9
- ## **✨ Features**
10
-
11
- ✅ **MDAST to DOCX conversion** — Supports standard Markdown elements
12
- ✅ **Footnotes handling** — Converts Markdown footnotes to DOCX format
13
- ✅ **Customizable image handling** — Fine-tune image rendering in DOCX
14
- ✅ **Hyperlink support** — Converts external links, internal links [WIP]
15
- ✅ **Configurable sections** — Customize document structure & styling
16
-
17
- ---
18
-
19
- ## **📦 Installation**
20
-
21
- Install the package using `pnpm`, `npm`, or `yarn`:
22
-
23
- ```bash
24
- pnpm add mdast2docx
25
- ```
26
-
27
- **_or_**
28
-
29
- ```bash
30
- npm install mdast2docx
31
- ```
32
-
33
- **_or_**
34
-
35
- ```bash
36
- yarn add mdast2docx
37
- ```
38
-
39
- ---
40
-
41
- ## **🚀 Usage**
42
-
43
- ### **Basic Example**
44
-
45
- ```typescript
46
- import { toDocx } from "mdast2docx";
47
- import { unified } from "unified";
48
- import remarkParse from "remark-parse";
49
- import remarkMmd from "remark-mmd"; // Assumed MMD plugin
50
-
51
- const markdown = `
52
- # Sample Document
53
- This is a **bold** text and _italic_ text.
54
-
55
- > A blockquote example
56
-
57
- - List Item 1
58
- - List Item 2
59
-
60
- [Click Here](https://example.com)
61
-
62
- ![Sample Image](https://example.com/image.png)
63
-
64
- This is a footnote reference[^1].
65
-
66
- [^1]: This is the footnote content.
67
- `;
68
-
69
- const mdast = unified().use(remarkParse).use(remarkMmd).parse(markdown);
70
-
71
- (async () => {
72
- const docxBlob = await toDocx(mdast, { title: "My Document" }, {});
73
- const url = URL.createObjectURL(docxBlob as Blob);
74
- const link = document.createElement("a");
75
- link.href = url;
76
- link.download = "document.docx";
77
- link.click();
78
- URL.revokeObjectURL(url);
79
- })();
80
- ```
81
-
82
- ---
83
-
84
- ## **🛠 API Reference**
85
-
86
- ### **`toDocx(astInputs, docxProps, defaultSectionProps, outputType?)`**
87
-
88
- | Parameter | Type | Description |
89
- | ------------------------- | -------------------------------------------------- | ---------------------------------------------------------------- |
90
- | `astInputs` | `Root` \| `{ ast: Root; props?: ISectionProps }[]` | Single or multiple MDAST trees with optional section properties. |
91
- | `docxProps` | `IDocxProps` | General document properties (title, styles, metadata). |
92
- | `defaultSectionProps` | `ISectionProps` | Default properties for document sections. |
93
- | `outputType` _(optional)_ | `"blob"` (default) \| `"buffer"` \| `"base64"` | Format of the generated DOCX document. |
94
-
95
- 📌 **Returns:** A `Promise` resolving to a DOCX document in the chosen format.
96
-
97
- ---
98
-
99
- ## **📜 Supported Markdown Elements**
100
-
101
- | Markdown Syntax | Supported in DOCX |
102
- | ---------------------------------- | ---------------------- |
103
- | Headings `# H1` to `###### H6` | ✅ |
104
- | Paragraphs | ✅ |
105
- | Bold `**text**` & Italics `_text_` | ✅ |
106
- | Blockquotes `> quote` | ✅ |
107
- | Lists (ordered & unordered) | ✅ |
108
- | Links `[text](url)` | ✅ |
109
- | Images `![alt](url)` | ✅ |
110
- | Code Blocks `` `code` `` | ✅ |
111
- | Footnotes `[^1]` | ✅ |
112
- | Tables | 🚧 _(Coming soon)_ |
113
- | HTML Tags | 🚧 _(Partial support)_ |
114
-
115
- ---
116
-
117
- ## **🔧 Configuration**
118
-
119
- You can customize the DOCX output using `ISectionProps` and `IDocxProps`.
120
-
121
- ### **Example: Customizing Styles**
122
-
123
- ```typescript
124
- const docxProps = {
125
- title: "Styled Document",
126
- author: "John Doe",
127
- };
128
-
129
- const sectionProps = {
130
- page: { margin: { top: 1000, bottom: 1000, left: 1200, right: 1200 } },
131
- };
132
-
133
- const docxBlob = await toDocx(mdast, docxProps, sectionProps);
134
- ```
135
-
136
- 📖 **More details:**
137
-
138
- - [DOCX.js Document Properties](https://docx.js.org/#/usage/document)
139
- - [DOCX.js Section Options](https://docx.js.org/#/usage/sections)
140
-
141
- ---
142
-
143
- ## **📝 Contributing**
144
-
145
- We welcome contributions! To get started:
146
-
147
- 1. **Fork** the repository
148
- 2. **Create a feature branch** (`git checkout -b feature-new`)
149
- 3. **Commit your changes** (`git commit -m "Add new feature"`)
150
- 4. **Push to GitHub** (`git push origin feature-new`)
151
- 5. **Open a Pull Request** 🚀
152
-
153
- ---
154
-
155
- ## **📄 License**
156
-
157
- This project is **licensed under MPL-2.0**. See the [LICENSE](./LICENSE) file for details.
158
-
159
- ---
160
-
161
- ## **🙌 Acknowledgments**
162
-
163
- Thanks to the **docx.js** and **unified.js** ecosystems for making this possible.
164
-
165
- > ⭐ **Star this repository** if you find it useful!
166
- > ❤️ Support our work by [sponsoring](https://github.com/sponsors/mayank1513).
167
-
168
- ---
169
-
170
- <p align="center">Made with 💖 by <a href="https://mayank-chaudhari.vercel.app" target="_blank">Mayank Kumar Chaudhari</a></p>
1
+ # **MDAST (Markdown Abstract Syntax Tree) to DOCX** <img src="https://raw.githubusercontent.com/mayank1513/mayank1513/main/popper.png" style="height: 40px"/>
2
+
3
+ 🚀 **Effortlessly convert Markdown Abstract Syntax Trees (MDAST) to DOCX.**
4
+
5
+ [![Test](https://github.com/tiny-md/mdast2docx/actions/workflows/test.yml/badge.svg)](https://github.com/tiny-md/mdast2docx/actions/workflows/test.yml) [![Maintainability](https://api.codeclimate.com/v1/badges/aa896ec14c570f3bb274/maintainability)](https://codeclimate.com/github/tiny-md/mdast2docx/maintainability) [![Code Coverage](https://codecov.io/gh/tiny-md/mdast2docx/graph/badge.svg)](https://codecov.io/gh/tiny-md/mdast2docx) [![Version](https://img.shields.io/npm/v/mdast2docx.svg?colorB=green)](https://www.npmjs.com/package/mdast2docx) [![Downloads](https://img.shields.io/npm/d18m/mdast2docx)](https://www.npmjs.com/package/mdast2docx) ![Bundle Size](https://img.shields.io/bundlephobia/minzip/mdast2docx)
6
+
7
+ ---
8
+
9
+ ## **✨ Features**
10
+
11
+ ✅ **MDAST to DOCX conversion** — Supports standard Markdown elements
12
+ ✅ **Footnotes handling** — Converts Markdown footnotes to DOCX format
13
+ ✅ **Tables support** — Converts Markdown tables into DOCX tables
14
+ ✅ **Hyperlink support** — External and internal hyperlinks are now fully functional
15
+ ✅ **New Plugin Architecture** — Extend and customize DOCX output with plugins
16
+ ✅ **Customizable image handling** — Images are now supported via `imagePlugin`
17
+
18
+ > **Note:** Images are no longer supported by default. To enable image support, use the `imagePlugin` explicitly.
19
+ >
20
+ > This change helps us keep the library lean and extensible by community via plugins.
21
+
22
+ ---
23
+
24
+ ## **📦 Installation**
25
+
26
+ Install the package using `pnpm`, `npm`, or `yarn`:
27
+
28
+ ```bash
29
+ pnpm add mdast2docx
30
+ ```
31
+
32
+ **_or_**
33
+
34
+ ```bash
35
+ npm install mdast2docx
36
+ ```
37
+
38
+ **_or_**
39
+
40
+ ```bash
41
+ yarn add mdast2docx
42
+ ```
43
+
44
+ ---
45
+
46
+ ## **🚀 Usage**
47
+
48
+ ### **Basic Example**
49
+
50
+ ```typescript
51
+ import { toDocx } from "mdast2docx";
52
+ import { unified } from "unified";
53
+ import remarkParse from "remark-parse";
54
+ import remarkMmd from "remark-mmd"; // Assumed MMD plugin
55
+
56
+ const markdown = `
57
+ # Sample Document
58
+ This is a **bold** text and _italic_ text.
59
+
60
+ > A blockquote example
61
+
62
+ - List Item 1
63
+ - List Item 2
64
+
65
+ [Click Here](https://example.com)
66
+
67
+ This is a footnote reference[^1].
68
+
69
+ [^1]: This is the footnote content.
70
+ `;
71
+
72
+ const mdast = unified().use(remarkParse).use(remarkMmd).parse(markdown);
73
+
74
+ (async () => {
75
+ const docxBlob = await toDocx(mdast, { title: "My Document" }, {});
76
+ const url = URL.createObjectURL(docxBlob as Blob);
77
+ const link = document.createElement("a");
78
+ link.href = url;
79
+ link.download = "document.docx";
80
+ link.click();
81
+ URL.revokeObjectURL(url);
82
+ })();
83
+ ```
84
+
85
+ ---
86
+
87
+ ## **📜 API Reference**
88
+
89
+ ### **`toDocx(astInputs, docxProps, defaultSectionProps, outputType?)`**
90
+
91
+ | Parameter | Type | Description |
92
+ | ------------------------- | -------------------------------------------------- | ---------------------------------------------------------------- |
93
+ | `astInputs` | `Root` \| `{ ast: Root; props?: ISectionProps }[]` | Single or multiple MDAST trees with optional section properties. |
94
+ | `docxProps` | `IDocxProps` | General document properties (title, styles, metadata). |
95
+ | `defaultSectionProps` | `ISectionProps` | Default properties for document sections. |
96
+ | `outputType` _(optional)_ | `"blob"` (default) \| `"buffer"` \| `"base64"` | Format of the generated DOCX document. |
97
+
98
+ 📌 **Returns:** A `Promise` resolving to a DOCX document in the chosen format.
99
+
100
+ ---
101
+
102
+ ## **📜 Supported Markdown Elements**
103
+
104
+ | Markdown Syntax | Supported in DOCX |
105
+ | ---------------------------------- | ------------------------------------- |
106
+ | Headings `# H1` to `###### H6` | ✅ |
107
+ | Paragraphs | ✅ |
108
+ | Bold `**text**` & Italics `_text_` | ✅ |
109
+ | Blockquotes `> quote` | ✅ |
110
+ | Lists (ordered & unordered) | ✅ _(ordered lists via `listPlugin`)_ |
111
+ | Links `[text](url)` | ✅ |
112
+ | Images `![alt](url)` | ✅ _(via `imagePlugin`)_ |
113
+ | Code Blocks `` `code` `` | ✅ |
114
+ | Footnotes `[^1]` | ✅ |
115
+ | Tables | ✅ _(via `tablePlugin`)_ |
116
+ | Hyperlinks (external & internal) | ✅ |
117
+ | HTML Tags | 🚧 _(Work in progress)_ |
118
+
119
+ ---
120
+
121
+ ## **🔧 Configuration**
122
+
123
+ You can customize the DOCX output using `ISectionProps` and `IDocxProps`.
124
+
125
+ ### **Example: Customizing Styles**
126
+
127
+ ```typescript
128
+ const docxProps = {
129
+ title: "Styled Document",
130
+ author: "John Doe",
131
+ };
132
+
133
+ const sectionProps = {
134
+ page: { margin: { top: 1000, bottom: 1000, left: 1200, right: 1200 } },
135
+ };
136
+
137
+ const docxBlob = await toDocx(mdast, docxProps, sectionProps);
138
+ ```
139
+
140
+ ### **Use Plugins**
141
+
142
+ Plugins allow extending functionality like adding image or table support.
143
+
144
+ ```typescript
145
+ import { toDocx } from "mdast2docx";
146
+ import { imagePlugin, tablePlugin, listPlugin, mathPlugin } from "mdast2docx/dist/plugins";
147
+
148
+ const downloadDocx = () => {
149
+ toDocx(
150
+ mdast,
151
+ {},
152
+ { plugins: [imagePlugin(), tablePlugin(), listPlugin(), mathPlugin()] },
153
+ "blob",
154
+ ).then(blob => {
155
+ const url = URL.createObjectURL(blob as Blob);
156
+ const link = document.createElement("a");
157
+ link.href = url;
158
+ link.download = "my-document.docx";
159
+ link.click();
160
+ URL.revokeObjectURL(url);
161
+ });
162
+ };
163
+ ```
164
+
165
+ 📖 **More details:**
166
+
167
+ - [DOCX.js Document Properties](https://docx.js.org/#/usage/document)
168
+ - [DOCX.js Section Options](https://docx.js.org/#/usage/sections)
169
+
170
+ ---
171
+
172
+ ## **📝 Contributing**
173
+
174
+ We welcome contributions! To get started:
175
+
176
+ 1. **Fork** the repository
177
+ 2. **Create a feature branch** (`git checkout -b feature-new`)
178
+ 3. **Commit your changes** (`git commit -m "Add new feature"`)
179
+ 4. **Push to GitHub** (`git push origin feature-new`)
180
+ 5. **Open a Pull Request** 🚀
181
+
182
+ ### **Extend Functionality with Plugins**
183
+
184
+ The community can create plugins to extend the functionality of this library. For inspiration, check out the existing plugins in the [`lib/src/plugins`](https://github.com/tiny-md/mdast2docx/tree/main/lib/src/plugins) folder.
185
+
186
+ ---
187
+
188
+ ## **📄 License**
189
+
190
+ This project is **licensed under MPL-2.0**. See the [LICENSE](./LICENSE) file for details.
191
+
192
+ ---
193
+
194
+ ## **🙌 Acknowledgments**
195
+
196
+ Thanks to the **docx.js** and **unified.js** ecosystems for making this possible.
197
+
198
+ > ⭐ **Star this repository** if you find it useful!
199
+ > ❤️ Support our work by [sponsoring](https://github.com/sponsors/mayank1513).
200
+
201
+ ---
202
+
203
+ <p align="center">Made with 💖 by <a href="https://mayank-chaudhari.vercel.app" target="_blank">Mayank Kumar Chaudhari</a></p>
@@ -0,0 +1,2 @@
1
+ import{b as C,d as N}from"./chunk-YKZOUIFR.mjs";import{Bookmark as D,BorderStyle as S,ExternalHyperlink as B,FootnoteReferenceRun as R,InternalHyperlink as v,Paragraph as m,TextRun as f}from"@mayank1513/docx";import*as g from"@mayank1513/docx";var T=(w,h,P)=>{let y=async(o,c)=>{var e,l,n;let t=Object.assign({},c),s=(await Promise.all(P.map(r=>{var d,p;return(p=(d=r.inline)==null?void 0:d.call(r,g,o,t,w,h,a))!=null?p:[]}))).flat(),i=(l=o.url)!=null?l:w[(e=o.identifier)==null?void 0:e.toUpperCase()];switch(o.type){case"text":return[...s,new f({text:o.value,...t})];case"break":return[...s,new f({break:1})];case"inlineCode":return[...s,new f({text:o.value,...t,style:"code",font:{name:"Consolas"}})];case"emphasis":return t.italics=!0,[...s,...await a(o,t)];case"strong":return t.bold=!0,[...s,...await a(o,t)];case"delete":return t.strike=!0,[...s,...await a(o,t)];case"link":case"linkReference":return[...s,i.startsWith("#")?new v({anchor:i.slice(1),children:await a(o,t)}):new B({link:i,children:await a(o,t)})];case"footnoteReference":return[...s,new R((n=h[o.identifier].id)!=null?n:0)];default:return[...s]}},a=async(o,c=new Set)=>{var t;return(await Promise.all((t=o.children)==null?void 0:t.map(s=>y(s,c)))).flat()};return a},H=async(w,h,P,y)=>{let{plugins:a,useTitle:o,...c}={...N,...y},t=T(h,P,a),s=async(e,l)=>{var d,p,k,I;let n=Object.assign({},l),r=(await Promise.all(a.map(u=>{var b,x;return(x=(b=u.block)==null?void 0:b.call(u,g,e,n,i,t))!=null?x:[]}))).flat();switch(e.type){case"paragraph":return[...r,new m({...l,children:await t(e)})];case"heading":return[new m({...r,heading:o?e.depth===1?"Title":`Heading${e.depth-1}`:`Heading${e.depth}`,children:[new D({id:C(e).replace(/[. ]+/g,"-").toLowerCase(),children:await t(e)})]})];case"code":return[...r,new m({alignment:"start",style:"blockCode",children:e.value.split(`
2
+ `).map(u=>new f({text:u,break:1,style:"code",font:{name:"Consolas"}}))})];case"list":return e.ordered?(n.bullet={level:((p=(d=n.bullet)==null?void 0:d.level)!=null?p:-1)+1},console.warn("Please add numbering plugin to support ordered lists. For now, we use only bullets for both the ordered and the unordered list.")):n.bullet={level:((I=(k=n.bullet)==null?void 0:k.level)!=null?I:-1)+1},[...r,...await i(e,n)];case"blockquote":return[...r,...await i(e,n)];case"listItem":return[...r,...await i(e,n)];case"thematicBreak":return[...r,new m({border:{top:{style:S.SINGLE,size:6}}})];case"definition":case"footnoteDefinition":return r;case"table":return console.warn("Please add table plugin to support tables."),r;case"":return r;case"yaml":case"html":default:return console.warn(`Unsupported node type: ${e.type}`,e),r}},i=async(e,l)=>{var n;return(await Promise.all((n=e.children)==null?void 0:n.map(r=>s(r,l)))).flat()};return{...c,children:await i(w,{})}};export{H as a};
@@ -0,0 +1 @@
1
+ var r=()=>({inline:async(t,n)=>{var e;return n.type!=="inlineMath"?[]:(console.log("inline math",n.value),[new t.MathRun((e=n.value)!=null?e:"")])},block:async(t,n,e)=>{var a;return n.type!=="math"?[]:[new t.Paragraph({...e,children:[new t.MathRun((a=n.value)!=null?a:"")]})]}});export{r as a};
@@ -0,0 +1 @@
1
+ import{c as g}from"./chunk-YKZOUIFR.mjs";import{AlignmentType as v,convertInchesToTwip as O,LevelFormat as e}from"@mayank1513/docx";var E=[e.DECIMAL,e.DECIMAL,e.DECIMAL,e.DECIMAL,e.UPPER_LETTER,e.LOWER_LETTER,e.LOWER_ROMAN,e.UPPER_ROMAN],b=(c,o=.4,u=.25)=>c.map((i,t)=>({level:t,format:i,text:(i===e.DECIMAL?Array(t+1).fill(`%${t+1}`).join("."):`%${t+1}`)+".",alignment:v.START,style:{paragraph:{indent:{left:O(o+t*u)}}}})),R=b(E),y=["\u25CF","\u25CB","\u25A0","\u25C6","\u25B6","\u25C9","\u2B24","\u2666","\u25E6","\u25AA"],A={levels:R,bullets:y,defaultBullets:!1},x=c=>{let o=g(),u=`numbering-${o}`,i=`bullet-${o}`,{levels:t,bulletLevels:f,bullets:m,defaultBullets:I}={...A,...c};return{block:async(L,l,n,a)=>{var s,p;if(l.type!=="list")return[];let r=((p=(s=n.bullet)==null?void 0:s.level)!=null?p:-1)+1;return n.numbering=I?void 0:{level:r,reference:l.ordered?u:i},n.bullet={level:r},l.type="",await a(l,n)},root:L=>{var l,n;L.numbering={config:[...(n=(l=L.numbering)==null?void 0:l.config)!=null?n:[],{reference:u,levels:t},{reference:i,levels:f!=null?f:t.map((a,r)=>{var s;return{...a,text:(s=m[r])!=null?s:"\u2022",format:e.BULLET}})}]}}}};export{b as a,x as b};
@@ -0,0 +1 @@
1
+ import{BorderStyle as I,ShadingType as C,WidthType as O,AlignmentType as E,VerticalAlign as D,convertMillimetersToTwip as r}from"@mayank1513/docx";var e={style:I.SINGLE,color:"auto",size:1},V={tableProps:{width:{size:100,type:O.PERCENTAGE},margins:{top:r(2),right:r(4),bottom:r(2),left:r(4)},borders:{top:e,right:e,bottom:e,left:e,insideHorizontal:e,insideVertical:e}},rowProps:{},cellProps:{},firstRowProps:{tableHeader:!0},firstRowCellProps:{shading:{type:C.SOLID,fill:"b79c2f"}},alignments:{defaultVerticalAlign:D.CENTER,defaultHorizontalAlign:E.CENTER,preferMdData:!0}},N=s=>({block:async(l,t,z,H,P)=>{var a;if(t.type!=="table")return[];let{Table:c,TableRow:f,TableCell:g,Paragraph:T}=l,{tableProps:b,firstRowProps:u,firstRowCellProps:m,rowProps:w,cellProps:y,alignments:o}={...V,...s},i=(a=t.align)==null?void 0:a.map(n=>{switch(n){case"left":return l.AlignmentType.LEFT;case"right":return l.AlignmentType.RIGHT;case"center":return l.AlignmentType.CENTER;default:return}}),d=async(n,p)=>new f({...w,...p===0?u:{},children:await Promise.all(n.children.map(async(A,h)=>new g({verticalAlign:o.defaultVerticalAlign,...y,...p===0?m:{},children:[new T({children:await P(A),alignment:o.preferMdData?i==null?void 0:i[h]:o.defaultHorizontalAlign})]})))}),R=await Promise.all(t.children.map(d));return t.type="",[new c({...b,rows:R})]}});export{V as a,N as b};
@@ -0,0 +1 @@
1
+ var c=a=>{let e=new Uint8Array(a).slice(0,4);if(e[0]===66&&e[1]===77)return"bmp";switch(e.reduce((r,n)=>r+n.toString(16).padStart(2,"0"),"")){case"89504E47":return"png";case"47494638":return"gif";case"FFD8FFE0":case"FFD8FFE1":case"FFD8FFE2":case"FFD8FFE3":case"FFD8FFE8":return"jpg"}},p=3,u=async(a,e)=>{let t=document.createElement("canvas"),r=t.getContext("2d");if(!r)throw new Error("Canvas context not available");let n=new Image;n.src=a,await new Promise(o=>n.onload=o);let i=n.width*e,s=n.height*e;return t.width=i,t.height=s,r.drawImage(n,0,0,i,s),{data:t.toDataURL("image/png"),type:"png",transformation:{width:i/e,height:s/e}}},h=async a=>{let t=await(await fetch(a)).arrayBuffer(),r=c(t)||"png",n=await createImageBitmap(new Blob([t],{type:r}));return{type:r,data:t,transformation:{width:n.width,height:n.height}}},l=async(a,e)=>{var t;try{return a.startsWith("data:")?await u(a,(t=e==null?void 0:e.scale)!=null?t:p):await h(a)}catch(r){return console.error(`Error resolving image: ${a}`,r),{type:"png",data:Buffer.from([]),transformation:{width:100,height:100}}}},I=a=>({inline:async(e,t,r,n)=>{var i,s,o;if(/^image/.test(t.type)){let g=(s=t.url)!=null?s:n[(i=t.identifier)==null?void 0:i.toUpperCase()],m=(o=t.alt)!=null?o:g==null?void 0:g.split("/").pop();return t.type="",[new e.ImageRun({...await l(g,a),altText:{description:m,name:m,title:m}})]}return[]}});export{c as a,I as b};
@@ -0,0 +1 @@
1
+ import{convertInchesToTwip as d,convertMillimetersToTwip as P}from"@mayank1513/docx";var i=o=>{let t={},n={};return o.forEach(e=>{var r;e.type==="definition"?t[e.identifier.toUpperCase()]=e.url:e.type==="footnoteDefinition"?n[e.identifier.toUpperCase()]={children:e.children}:(r=e.children)!=null&&r.length&&Object.assign(t,i(e.children))}),{definitions:t,footnoteDefinitions:n}},s=o=>{var t,n;return(t=o.children)!=null&&t.length?o.children.map(s).join(""):(n=o.value)!=null?n:""},p=()=>Math.random().toString(16).slice(2),a={useTitle:!0,plugins:[]};export{i as a,s as b,p as c,a as d,d as e,P as f};
package/dist/index.d.ts CHANGED
@@ -1,13 +1,12 @@
1
- import { OutputType, type IPropertiesOptions } from "@mayank1513/docx";
1
+ import { OutputType } from "@mayank1513/docx";
2
2
  import type { Root } from "mdast";
3
3
  import { type ISectionProps } from "./section";
4
+ import { IDocxProps } from "./utils";
4
5
  /**
5
- * Defines document properties, excluding sections and footnotes (which are managed internally).
6
- */
7
- type IDocxProps = Omit<IPropertiesOptions, "sections" | "footnotes">;
8
- /**
9
- * Represents the input MDAST tree(s) for conversion.
10
- * It can be a single root node or an array of objects containing the AST and optional section properties.
6
+ * Represents the input Markdown AST tree(s) for conversion.
7
+ * Supports either:
8
+ * - A single `Root` node (direct conversion)
9
+ * - An array of objects `{ ast: Root, props?: ISectionProps }` for fine-grained section-level control.
11
10
  */
12
11
  type IInputMDAST = Root | {
13
12
  ast: Root;
@@ -21,5 +20,5 @@ type IInputMDAST = Root | {
21
20
  * @param outputType - The desired output format (default: `"blob"`). @see https://docx.js.org/#/usage/packers
22
21
  * @returns A DOCX document in the specified format.
23
22
  */
24
- export declare const toDocx: (astInputs: IInputMDAST, docxProps: IDocxProps, defaultSectionProps: ISectionProps, outputType?: OutputType) => Promise<string | ArrayBuffer | Buffer<ArrayBufferLike> | Uint8Array<ArrayBufferLike> | Blob | readonly number[]>;
23
+ export declare const toDocx: (astInputs: IInputMDAST, docxProps?: IDocxProps, defaultSectionProps?: ISectionProps, outputType?: OutputType) => Promise<string | readonly number[] | ArrayBuffer | Uint8Array<ArrayBufferLike> | Blob | Buffer<ArrayBufferLike>>;
25
24
  export type { ISectionProps, IDocxProps, IInputMDAST };