mdast2docx 0.3.0 → 0.3.1

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.
Files changed (46) hide show
  1. package/README.md +242 -242
  2. package/dist/chunk-KWOFOD3W.mjs +31 -0
  3. package/dist/{chunk-M5XHL7AG.mjs → chunk-NMFJ4KIZ.mjs} +2 -2
  4. package/dist/index.d.ts +1 -23
  5. package/dist/index.js +1 -3
  6. package/dist/index.mjs +1 -1
  7. package/dist/{multipart-parser-WKN2UV32.mjs → multipart-parser-I4OTWNXG.mjs} +1 -1
  8. package/dist/plugins/index.d.ts +5 -5
  9. package/dist/plugins/index.js +1 -3
  10. package/dist/plugins/index.mjs +1 -1
  11. package/dist/plugins/node/index.mjs +1 -1
  12. package/dist/plugins/node/node-image.d.ts +1 -1
  13. package/dist/plugins/node/node-image.mjs +1 -1
  14. package/package.json +98 -95
  15. package/dist/chunk-3ZZBJC3M.mjs +0 -1
  16. package/dist/chunk-GP6KO6J3.mjs +0 -3
  17. package/dist/chunk-GS5L4UWU.mjs +0 -1
  18. package/dist/chunk-IW743AEN.mjs +0 -1
  19. package/dist/chunk-LXTXD4UG.mjs +0 -1
  20. package/dist/chunk-Q6Q2NBIZ.mjs +0 -1
  21. package/dist/chunk-QR3NYQYH.mjs +0 -1
  22. package/dist/chunk-YNJKJBFY.mjs +0 -3
  23. package/dist/chunk-Z5DPYROV.mjs +0 -31
  24. package/dist/mdast.d.ts +0 -1076
  25. package/dist/mdast.js +0 -1
  26. package/dist/plugins/html.d.ts +0 -9
  27. package/dist/plugins/html.js +0 -3
  28. package/dist/plugins/html.mjs +0 -1
  29. package/dist/plugins/image.d.ts +0 -41
  30. package/dist/plugins/image.js +0 -1
  31. package/dist/plugins/image.mjs +0 -1
  32. package/dist/plugins/list.d.ts +0 -57
  33. package/dist/plugins/list.js +0 -1
  34. package/dist/plugins/list.mjs +0 -1
  35. package/dist/plugins/math.d.ts +0 -11
  36. package/dist/plugins/math.js +0 -1
  37. package/dist/plugins/math.mjs +0 -1
  38. package/dist/plugins/table.d.ts +0 -26
  39. package/dist/plugins/table.js +0 -1
  40. package/dist/plugins/table.mjs +0 -1
  41. package/dist/section.d.ts +0 -26
  42. package/dist/section.js +0 -3
  43. package/dist/section.mjs +0 -1
  44. package/dist/utils.d.ts +0 -123
  45. package/dist/utils.js +0 -1
  46. package/dist/utils.mjs +0 -1
package/README.md CHANGED
@@ -1,242 +1,242 @@
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
- Got it! Here's an improved version of the **"🚀 Relevance to Generative AI"** section that reflects this process accurately:
25
-
26
- ---
27
-
28
- ## **🚀 Relevance to Generative AI**
29
-
30
- <details open>
31
- <summary>
32
- <i>Converts markdown content/artifacts generated by Generative AI to docx for further processing/record-keeping/sharing.</i>
33
- </summary>
34
-
35
- Modern **Generative AI tools** often produce structured content in **Markdown (MD)** format. However, converting this AI-generated Markdown into **professional DOCX documents** requires an additional transformation step. This is where **MDAST to DOCX** comes in.
36
-
37
- ### **How It Works**
38
-
39
- 1. **AI tools generate content in Markdown**.
40
- 2. **Unified.js & Remark Ecosystem** convert Markdown into **Markdown Abstract Syntax Tree (MDAST)**.
41
- 3. **MDAST to DOCX** processes this structure and exports a **well-formatted DOCX document**.
42
-
43
- ### **Use Cases**
44
-
45
- - **AI-Generated Reports** – Convert AI-generated Markdown reports into polished DOCX files.
46
- - **AI-Powered Content Export** – Transform AI-generated blogs, research papers, and structured content into a DOCX format for easy sharing and editing.
47
- - **Client & Server Flexibility** – Works both in **browser-based AI tools** and **high-performance server environments**.
48
-
49
- ### **✅ Benefits**
50
-
51
- - **Works on both Client & Server** – Choose to **offload processing to the client** for better scalability or **run it on the server** for batch conversions.
52
- - **Optimized & Extensible** – Use **only the plugins you need**, keeping your AI workflows lightweight.
53
-
54
- By integrating **MDAST to DOCX**, AI applications can **seamlessly export Markdown-based content into DOCX**, making it more accessible, editable, and shareable. 🚀
55
-
56
- </details>
57
-
58
- ---
59
-
60
- ---
61
-
62
- ## **📦 Installation**
63
-
64
- Install the package using `pnpm`, `npm`, or `yarn`:
65
-
66
- ```bash
67
- pnpm add mdast2docx
68
- ```
69
-
70
- **_or_**
71
-
72
- ```bash
73
- npm install mdast2docx
74
- ```
75
-
76
- **_or_**
77
-
78
- ```bash
79
- yarn add mdast2docx
80
- ```
81
-
82
- ---
83
-
84
- ## **🚀 Usage**
85
-
86
- ### **Basic Example**
87
-
88
- ```typescript
89
- import { toDocx } from "mdast2docx";
90
- import { unified } from "unified";
91
- import remarkParse from "remark-parse";
92
- import remarkMmd from "remark-mmd"; // Assumed MMD plugin
93
-
94
- const markdown = `
95
- # Sample Document
96
- This is a **bold** text and _italic_ text.
97
-
98
- > A blockquote example
99
-
100
- - List Item 1
101
- - List Item 2
102
-
103
- [Click Here](https://example.com)
104
-
105
- This is a footnote reference[^1].
106
-
107
- [^1]: This is the footnote content.
108
- `;
109
-
110
- const mdast = unified().use(remarkParse).use(remarkMmd).parse(markdown);
111
-
112
- (async () => {
113
- const docxBlob = await toDocx(mdast, { title: "My Document" }, {});
114
- const url = URL.createObjectURL(docxBlob as Blob);
115
- const link = document.createElement("a");
116
- link.href = url;
117
- link.download = "document.docx";
118
- link.click();
119
- URL.revokeObjectURL(url);
120
- })();
121
- ```
122
-
123
- ---
124
-
125
- ## **📜 API Reference**
126
-
127
- ### **`toDocx(astInputs, docxProps, defaultSectionProps, outputType?)`**
128
-
129
- | Parameter | Type | Description |
130
- | ------------------------- | -------------------------------------------------- | ---------------------------------------------------------------- |
131
- | `astInputs` | `Root` \| `{ ast: Root; props?: ISectionProps }[]` | Single or multiple MDAST trees with optional section properties. |
132
- | `docxProps` | `IDocxProps` | General document properties (title, styles, metadata). |
133
- | `defaultSectionProps` | `ISectionProps` | Default properties for document sections. |
134
- | `outputType` _(optional)_ | `"blob"` (default) \| `"buffer"` \| `"base64"` | Format of the generated DOCX document. |
135
-
136
- 📌 **Returns:** A `Promise` resolving to a DOCX document in the chosen format.
137
-
138
- ---
139
-
140
- ## **📜 Supported Markdown Elements**
141
-
142
- | Markdown Syntax | Supported in DOCX |
143
- | ---------------------------------- | ------------------------------------- |
144
- | Headings `# H1` to `###### H6` | ✅ |
145
- | Paragraphs | ✅ |
146
- | Bold `**text**` & Italics `_text_` | ✅ |
147
- | Blockquotes `> quote` | ✅ |
148
- | Lists (ordered & unordered) | ✅ _(ordered lists via `listPlugin`)_ |
149
- | Links `[text](url)` | ✅ |
150
- | Images `![alt](url)` | ✅ _(via `imagePlugin`)_ |
151
- | Code Blocks `` `code` `` | ✅ |
152
- | Footnotes `[^1]` | ✅ |
153
- | Tables | ✅ _(via `tablePlugin`)_ |
154
- | Hyperlinks (external & internal) | ✅ |
155
- | Latex Math | 🚧 _(via `mathPlugin`; in progress)_ |
156
- | HTML Tags | 🚧 _(Work in progress; beta)_ |
157
-
158
- ---
159
-
160
- ## **🔧 Configuration**
161
-
162
- You can customize the DOCX output using `ISectionProps` and `IDocxProps`.
163
-
164
- ### **Example: Customizing Styles**
165
-
166
- ```typescript
167
- const docxProps = {
168
- title: "Styled Document",
169
- author: "John Doe",
170
- };
171
-
172
- const sectionProps = {
173
- page: { margin: { top: 1000, bottom: 1000, left: 1200, right: 1200 } },
174
- };
175
-
176
- const docxBlob = await toDocx(mdast, docxProps, sectionProps);
177
- ```
178
-
179
- ### **Use Plugins**
180
-
181
- Plugins allow extending functionality like adding image or table support.
182
-
183
- ```typescript
184
- import { toDocx } from "mdast2docx";
185
- import { imagePlugin, tablePlugin, listPlugin, mathPlugin } from "mdast2docx/dist/plugins";
186
-
187
- const downloadDocx = () => {
188
- toDocx(
189
- mdast,
190
- {},
191
- { plugins: [imagePlugin(), tablePlugin(), listPlugin(), mathPlugin()] },
192
- "blob",
193
- ).then(blob => {
194
- const url = URL.createObjectURL(blob as Blob);
195
- const link = document.createElement("a");
196
- link.href = url;
197
- link.download = "my-document.docx";
198
- link.click();
199
- URL.revokeObjectURL(url);
200
- });
201
- };
202
- ```
203
-
204
- 📖 **More details:**
205
-
206
- - [DOCX.js Document Properties](https://docx.js.org/#/usage/document)
207
- - [DOCX.js Section Options](https://docx.js.org/#/usage/sections)
208
-
209
- ---
210
-
211
- ## **📝 Contributing**
212
-
213
- We welcome contributions! To get started:
214
-
215
- 1. **Fork** the repository
216
- 2. **Create a feature branch** (`git checkout -b feature-new`)
217
- 3. **Commit your changes** (`git commit -m "Add new feature"`)
218
- 4. **Push to GitHub** (`git push origin feature-new`)
219
- 5. **Open a Pull Request** 🚀
220
-
221
- ### **Extend Functionality with Plugins**
222
-
223
- 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.
224
-
225
- ---
226
-
227
- ## **📄 License**
228
-
229
- This project is **licensed under MPL-2.0**. See the [LICENSE](./LICENSE) file for details.
230
-
231
- ---
232
-
233
- ## **🙌 Acknowledgments**
234
-
235
- Thanks to the **docx.js** and **unified.js** ecosystems for making this possible.
236
-
237
- > ⭐ **Star this repository** if you find it useful!
238
- > ❤️ Support our work by [sponsoring](https://github.com/sponsors/mayank1513).
239
-
240
- ---
241
-
242
- <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 `@m2d/image` plugin
17
+
18
+ > **Note:** Images are no longer supported by default. To enable image support, use the image plugin from `@m2d/image` or `mdast2docx/plugins` explicitly.
19
+ > This change helps us keep the library lean and extensible by community via plugins.
20
+
21
+ ---
22
+
23
+ ## **🚀 Relevance to Generative AI**
24
+
25
+ <details open>
26
+ <summary>
27
+ <i>Converts markdown content/artifacts generated by Generative AI to docx for further processing/record-keeping/sharing.</i>
28
+ </summary>
29
+
30
+ Modern **Generative AI tools** often produce structured content in **Markdown (MD)** format. However, converting this AI-generated Markdown into **professional DOCX documents** requires an additional transformation step. This is where **MDAST to DOCX** comes in.
31
+
32
+ ### **How It Works**
33
+
34
+ 1. **AI tools generate content in Markdown**.
35
+ 2. **Unified.js & Remark Ecosystem** convert Markdown into **Markdown Abstract Syntax Tree (MDAST)**.
36
+ 3. **MDAST to DOCX** processes this structure and exports a **well-formatted DOCX document**.
37
+
38
+ ### **Use Cases**
39
+
40
+ - **AI-Generated Reports** – Convert AI-generated Markdown reports into polished DOCX files.
41
+ - **AI-Powered Content Export** – Transform AI-generated blogs, research papers, and structured content into a DOCX format for easy sharing and editing.
42
+ - **Client & Server Flexibility** – Works both in **browser-based AI tools** and **high-performance server environments**.
43
+
44
+ ### **✅ Benefits**
45
+
46
+ - **Works on both Client & Server** – Choose to **offload processing to the client** for better scalability or **run it on the server** for batch conversions.
47
+ - **Optimized & Extensible** – Use **only the plugins you need**, keeping your AI workflows lightweight.
48
+
49
+ By integrating **MDAST to DOCX**, AI applications can **seamlessly export Markdown-based content into DOCX**, making it more accessible, editable, and shareable. 🚀
50
+
51
+ </details>
52
+
53
+ ---
54
+
55
+ ## **📦 Installation**
56
+
57
+ ### **Install Everything at Once**
58
+
59
+ ```bash
60
+ pnpm add mdast2docx
61
+ ```
62
+
63
+ ### **Or Install Only What You Need (Scoped Packages)**
64
+
65
+ ```bash
66
+ pnpm add @m2d/core @m2d/html @m2d/image @m2d/math @m2d/table @m2d/list @m2d/mdast
67
+ ```
68
+
69
+ ---
70
+
71
+ ## **🚀 Usage**
72
+
73
+ ### **Basic Example**
74
+
75
+ ```typescript
76
+ import { toDocx } from "mdast2docx";
77
+ import { unified } from "unified";
78
+ import remarkParse from "remark-parse";
79
+ import remarkMmd from "remark-mmd"; // Assumed MMD plugin
80
+
81
+ const markdown = `
82
+ # Sample Document
83
+ This is a **bold** text and _italic_ text.
84
+
85
+ > A blockquote example
86
+
87
+ - List Item 1
88
+ - List Item 2
89
+
90
+ [Click Here](https://example.com)
91
+
92
+ This is a footnote reference[^1].
93
+
94
+ [^1]: This is the footnote content.
95
+ `;
96
+
97
+ const mdast = unified().use(remarkParse).use(remarkMmd).parse(markdown);
98
+
99
+ (async () => {
100
+ const docxBlob = await toDocx(mdast, { title: "My Document" }, {});
101
+ const url = URL.createObjectURL(docxBlob as Blob);
102
+ const link = document.createElement("a");
103
+ link.href = url;
104
+ link.download = "document.docx";
105
+ link.click();
106
+ URL.revokeObjectURL(url);
107
+ })();
108
+ ```
109
+
110
+ ---
111
+
112
+ ## **📜 API Reference**
113
+
114
+ ### **`toDocx(astInputs, docxProps, defaultSectionProps, outputType?)`**
115
+
116
+ | Parameter | Type | Description |
117
+ | ------------------------- | -------------------------------------------------- | ---------------------------------------------------------------- |
118
+ | `astInputs` | `Root` \| `{ ast: Root; props?: ISectionProps }[]` | Single or multiple MDAST trees with optional section properties. |
119
+ | `docxProps` | `IDocxProps` | General document properties (title, styles, metadata). |
120
+ | `defaultSectionProps` | `ISectionProps` | Default properties for document sections. |
121
+ | `outputType` _(optional)_ | `"blob"` (default) \| `"buffer"` \| `"base64"` | Format of the generated DOCX document. |
122
+
123
+ 📌 **Returns:** A `Promise` resolving to a DOCX document in the chosen format.
124
+
125
+ ---
126
+
127
+ ## **📜 Supported Markdown Elements**
128
+
129
+ | Markdown Syntax | Supported in DOCX |
130
+ | ---------------------------------- | ------------------------------------- |
131
+ | Headings `# H1` to `###### H6` | ✅ |
132
+ | Paragraphs | ✅ |
133
+ | Bold `**text**` & Italics `_text_` | ✅ |
134
+ | Blockquotes `> quote` | ✅ |
135
+ | Lists (ordered & unordered) | ✅ _(ordered lists via `listPlugin`)_ |
136
+ | Links `[text](url)` | ✅ |
137
+ | Images `![alt](url)` | ✅ _(via `imagePlugin`)_ |
138
+ | Code Blocks `` `code` `` | ✅ |
139
+ | Footnotes `[^1]` | ✅ |
140
+ | Tables | ✅ _(via `tablePlugin`)_ |
141
+ | Hyperlinks (external & internal) | ✅ |
142
+ | Latex Math | ✅ _(via `mathPlugin`)_ |
143
+ | HTML Tags | ✅ _(via `htmlPlugin`)_ |
144
+
145
+ ---
146
+
147
+ ## **🔧 Configuration**
148
+
149
+ You can customize the DOCX output using `ISectionProps` and `IDocxProps`.
150
+
151
+ ### **Example: Customizing Styles**
152
+
153
+ ```typescript
154
+ const docxProps = {
155
+ title: "Styled Document",
156
+ author: "John Doe",
157
+ };
158
+
159
+ const sectionProps = {
160
+ page: { margin: { top: 1000, bottom: 1000, left: 1200, right: 1200 } },
161
+ };
162
+
163
+ const docxBlob = await toDocx(mdast, docxProps, sectionProps);
164
+ ```
165
+
166
+ ### **Use Plugins**
167
+
168
+ Plugins allow extending functionality like adding image or table support.
169
+
170
+ ```typescript
171
+ import { toDocx } from "@m2d/core";
172
+ import { imagePlugin } from "@m2d/image";
173
+ import { tablePlugin } from "@m2d/table";
174
+ import { listPlugin } from "@m2d/list";
175
+ import { mathPlugin } from "@m2d/math";
176
+
177
+ const downloadDocx = () => {
178
+ toDocx(
179
+ mdast,
180
+ {},
181
+ { plugins: [imagePlugin(), tablePlugin(), listPlugin(), mathPlugin()] },
182
+ "blob",
183
+ ).then(blob => {
184
+ const url = URL.createObjectURL(blob as Blob);
185
+ const link = document.createElement("a");
186
+ link.href = url;
187
+ link.download = "my-document.docx";
188
+ link.click();
189
+ URL.revokeObjectURL(url);
190
+ });
191
+ };
192
+ ```
193
+
194
+ 📖 **More details:**
195
+
196
+ - [DOCX.js Document Properties](https://docx.js.org/#/usage/document)
197
+ - [DOCX.js Section Options](https://docx.js.org/#/usage/sections)
198
+
199
+ ---
200
+
201
+ ## **🧠 Relevance in Generative AI**
202
+
203
+ AI tools often generate Markdown as output (e.g., reports, documentation, summaries). This library makes it easy to convert those Markdown-based outputs into rich DOCX documents.
204
+
205
+ - Supports both **client-side** and **server-side** usage
206
+ - Enables **offloading document generation** to users' browsers or running high-performance server renderers
207
+ - Combine it with `unified` and `remark` to parse Markdown into MDAST, and then convert to DOCX seamlessly
208
+
209
+ ---
210
+
211
+ ## **📝 Contributing**
212
+
213
+ We welcome contributions! To get started:
214
+
215
+ 1. **Fork** the repository
216
+ 2. **Create a feature branch** (`git checkout -b feature-new`)
217
+ 3. **Commit your changes** (`git commit -m "Add new feature"`)
218
+ 4. **Push to GitHub** (`git push origin feature-new`)
219
+ 5. **Open a Pull Request** 🚀
220
+
221
+ ### **Extend Functionality with Plugins**
222
+
223
+ 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.
224
+
225
+ ---
226
+
227
+ ## **📄 License**
228
+
229
+ This project is **licensed under MPL-2.0**. See the [LICENSE](./LICENSE) file for details.
230
+
231
+ ---
232
+
233
+ ## **🙌 Acknowledgments**
234
+
235
+ Thanks to the **docx.js** and **unified.js** ecosystems for making this possible.
236
+
237
+ > ⭐ **Star this repository** if you find it useful!
238
+ > ❤️ Support our work by [sponsoring](https://github.com/sponsors/mayank1513).
239
+
240
+ ---
241
+
242
+ <p align="center">Made with 💖 by <a href="https://mayank-chaudhari.vercel.app" target="_blank">Mayank Kumar Chaudhari</a></p>