mdast2docx 0.0.0-beta.0 → 0.1.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 +203 -170
- package/dist/chunk-3ZZBJC3M.mjs +1 -0
- package/dist/chunk-7LR5HC5O.mjs +4 -0
- package/dist/chunk-7W4N3GRD.mjs +75 -0
- package/dist/chunk-GM6UUFDK.mjs +2 -0
- package/dist/chunk-TASCVLMX.mjs +1 -0
- package/dist/chunk-UXY5TDOP.mjs +1 -0
- package/dist/chunk-XIRSNIMN.mjs +1 -0
- package/dist/chunk-YKZOUIFR.mjs +1 -0
- package/dist/chunk-Z5DPYROV.mjs +31 -0
- package/dist/chunk-ZKNVKZAF.mjs +1 -0
- package/dist/index.d.ts +7 -8
- package/dist/index.js +2 -38
- package/dist/index.mjs +1 -1
- package/dist/multipart-parser-WKN2UV32.mjs +2 -0
- package/dist/plugins/html.d.ts +0 -0
- package/dist/plugins/html.js +1 -0
- package/dist/plugins/image.d.ts +37 -0
- package/dist/plugins/image.js +1 -0
- package/dist/plugins/image.mjs +1 -0
- package/dist/plugins/index.d.ts +4 -0
- package/dist/plugins/index.js +75 -0
- package/dist/plugins/index.mjs +1 -0
- package/dist/plugins/list.d.ts +57 -0
- package/dist/plugins/list.js +1 -0
- package/dist/plugins/list.mjs +1 -0
- package/dist/plugins/math.d.ts +11 -0
- package/dist/plugins/math.js +75 -0
- package/dist/plugins/math.mjs +1 -0
- package/dist/plugins/node-image.d.ts +27 -0
- package/dist/plugins/node-image.js +35 -0
- package/dist/plugins/node-image.mjs +1 -0
- package/dist/plugins/node.d.ts +1 -0
- package/dist/plugins/node.js +35 -0
- package/dist/plugins/node.mjs +1 -0
- package/dist/plugins/table.d.ts +26 -0
- package/dist/plugins/table.js +1 -0
- package/dist/plugins/table.mjs +1 -0
- package/dist/section.d.ts +9 -8
- package/dist/section.js +2 -38
- package/dist/section.mjs +1 -1
- package/dist/utils.d.ts +75 -20
- package/dist/utils.js +1 -37
- package/dist/utils.mjs +1 -1
- package/package.json +6 -20
- package/dist/chunk-KRMGJ4HN.mjs +0 -2
- package/dist/chunk-O6BHSWEF.mjs +0 -37
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
|
-
[](https://github.com/tiny-md/mdast2docx/actions/workflows/test.yml) [](https://codeclimate.com/github/tiny-md/mdast2docx/maintainability) [](https://codecov.io/gh/tiny-md/mdast2docx) [](https://www.npmjs.com/package/mdast2docx) [](https://www.npmjs.com/package/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
|
-
✅ **
|
|
14
|
-
✅ **Hyperlink support** —
|
|
15
|
-
✅ **
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
link.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
|
92
|
-
|
|
|
93
|
-
| `
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
|
105
|
-
|
|
|
106
|
-
|
|
|
107
|
-
|
|
|
108
|
-
|
|
|
109
|
-
|
|
|
110
|
-
|
|
|
111
|
-
|
|
|
112
|
-
|
|
|
113
|
-
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
+
[](https://github.com/tiny-md/mdast2docx/actions/workflows/test.yml) [](https://codeclimate.com/github/tiny-md/mdast2docx/maintainability) [](https://codecov.io/gh/tiny-md/mdast2docx) [](https://www.npmjs.com/package/mdast2docx) [](https://www.npmjs.com/package/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 `` | ✅ _(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 @@
|
|
|
1
|
+
var i=Object.create;var f=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var l=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty;var g=a=>{throw TypeError(a)};var o=(a=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(a,{get:(b,c)=>(typeof require!="undefined"?require:b)[c]}):a)(function(a){if(typeof require!="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+a+'" is not supported')});var p=(a,b)=>()=>(b||a((b={exports:{}}).exports,b),b.exports);var n=(a,b,c,d)=>{if(b&&typeof b=="object"||typeof b=="function")for(let e of k(b))!m.call(a,e)&&e!==c&&f(a,e,{get:()=>b[e],enumerable:!(d=j(b,e))||d.enumerable});return a};var q=(a,b,c)=>(c=a!=null?i(l(a)):{},n(b||!a||!a.__esModule?f(c,"default",{value:a,enumerable:!0}):c,a));var h=(a,b,c)=>b.has(a)||g("Cannot "+c);var r=(a,b,c)=>(h(a,b,"read from private field"),c?c.call(a):b.get(a)),s=(a,b,c)=>b.has(a)?g("Cannot add the same private member more than once"):b instanceof WeakSet?b.add(a):b.set(a,c),t=(a,b,c,d)=>(h(a,b,"write to private field"),d?d.call(a,c):b.set(a,c),c);export{o as a,p as b,q as c,r as d,s as e,t as f};
|