@docen/export-docx 0.0.10 → 0.0.11

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,271 +1,271 @@
1
- # @docen/export-docx
2
-
3
- ![npm version](https://img.shields.io/npm/v/@docen/export-docx)
4
- ![npm downloads](https://img.shields.io/npm/dw/@docen/export-docx)
5
- ![npm license](https://img.shields.io/npm/l/@docen/export-docx)
6
-
7
- > Export TipTap/ProseMirror editor content to Microsoft Word DOCX format.
8
-
9
- ## Features
10
-
11
- - 📝 **Rich Text Support** - Full support for headings, paragraphs, and blockquotes with proper formatting
12
- - 🖼️ **Image Handling** - Automatic image sizing, positioning, and metadata extraction
13
- - 📊 **Table Support** - Complete table structure with headers, cells, colspan, and rowspan
14
- - ✅ **Lists & Tasks** - Bullet lists, numbered lists with custom start numbers, and task lists with checkboxes
15
- - 🎨 **Text Formatting** - Bold, italic, underline, strikethrough, subscript, and superscript
16
- - 🎯 **Text Styles** - Comprehensive style support including colors, backgrounds, fonts, sizes, and line heights
17
- - 🔗 **Links** - Hyperlink support with href preservation
18
- - 💻 **Code Blocks** - Syntax highlighted code blocks with language attribute support
19
- - 📁 **Collapsible Content** - Details/summary sections for expandable content
20
- - 😀 **Emoji Support** - Native emoji rendering in documents
21
- - 🧮 **Mathematical Content** - LaTeX-style formula support
22
- - ⚙️ **Configurable Options** - Customizable export options for documents, tables, styles, and horizontal rules
23
-
24
- ## Installation
25
-
26
- ```bash
27
- # Install with npm
28
- $ npm install @docen/export-docx
29
-
30
- # Install with yarn
31
- $ yarn add @docen/export-docx
32
-
33
- # Install with pnpm
34
- $ pnpm add @docen/export-docx
35
- ```
36
-
37
- ## Quick Start
38
-
39
- ```typescript
40
- import { generateDOCX } from "@docen/export-docx";
41
- import { writeFileSync } from "node:fs";
42
-
43
- // Your TipTap/ProseMirror editor content
44
- const content = {
45
- type: "doc",
46
- content: [
47
- {
48
- type: "paragraph",
49
- content: [
50
- {
51
- type: "text",
52
- marks: [{ type: "bold" }, { type: "italic" }],
53
- text: "Hello, world!",
54
- },
55
- ],
56
- },
57
- ],
58
- };
59
-
60
- // Convert to DOCX and save to file
61
- const docx = await generateDOCX(content, { outputType: "nodebuffer" });
62
- writeFileSync("document.docx", docx);
63
- ```
64
-
65
- ## API Reference
66
-
67
- ### `generateDOCX(content, options)`
68
-
69
- Converts TipTap/ProseMirror content to DOCX format.
70
-
71
- **Parameters:**
72
-
73
- - `content: JSONContent` - TipTap/ProseMirror editor content
74
- - `options: DocxExportOptions` - Export configuration options
75
-
76
- **Returns:** `Promise<OutputByType[T]>` - DOCX file data with type matching the specified outputType
77
-
78
- **Available Output Types:**
79
-
80
- - `"base64"` - Base64 encoded string
81
- - `"string"` - Text string
82
- - `"text"` - Plain text
83
- - `"binarystring"` - Binary string
84
- - `"array"` - Array of numbers
85
- - `"uint8array"` - Uint8Array
86
- - `"arraybuffer"` - ArrayBuffer
87
- - `"blob"` - Blob object
88
- - `"nodebuffer"` - Node.js Buffer
89
-
90
- **Configuration Options:**
91
-
92
- - `title` - Document title
93
- - `creator` - Document author
94
- - `description` - Document description
95
- - `outputType` - Output format (required)
96
- - `table` - Table styling defaults (alignment, spacing, borders)
97
- - `image` - Image handling options
98
- - `styles` - Document default styles (font, line height, spacing)
99
- - `horizontalRule` - Horizontal rule style
100
-
101
- ## Supported Content Types
102
-
103
- ### Text Formatting
104
-
105
- - **Bold**, _Italic_, <u>Underline</u>, ~~Strikethrough~~
106
- - ^Superscript^ and ~Subscript~
107
- - Text colors and background colors
108
- - Font families and sizes
109
- - Line heights
110
-
111
- ### Block Elements
112
-
113
- - **Headings** (H1-H6) with level attribute
114
- - **Paragraphs** with text alignment (left, right, center, justify)
115
- - **Blockquotes** (Note: Exported as indented paragraphs with left border due to DOCX format)
116
- - **Horizontal Rules** (Exported as page breaks by default)
117
- - **Code Blocks** with language support
118
-
119
- ### Lists
120
-
121
- - **Bullet Lists** - Standard unordered lists
122
- - **Numbered Lists** - Ordered lists with custom start number
123
- - **Task Lists** - Checkbox lists with checked/unchecked states
124
-
125
- ### Tables
126
-
127
- - Complete table structure with rows and cells
128
- - **Table Headers** with colspan/rowspan support
129
- - **Table Cells** with colspan/rowspan support
130
- - Cell alignment and formatting options
131
-
132
- ### Media & Embeds
133
-
134
- - **Images** with automatic sizing and positioning
135
- - **Links** (hyperlinks) with href attribute
136
- - **Emoji** rendering
137
- - **Mathematics** formulas (LaTeX-style)
138
- - **Details/Summary** collapsible sections
139
-
140
- ## Examples
141
-
142
- ### Document with Tables and Colspan/Rowspan
143
-
144
- ```typescript
145
- const content = {
146
- type: "doc",
147
- content: [
148
- {
149
- type: "table",
150
- content: [
151
- {
152
- type: "tableRow",
153
- content: [
154
- {
155
- type: "tableHeader",
156
- attrs: { colspan: 2, rowspan: 1 },
157
- content: [
158
- {
159
- type: "paragraph",
160
- content: [{ type: "text", text: "Spanning Header" }],
161
- },
162
- ],
163
- },
164
- {
165
- type: "tableCell",
166
- content: [
167
- {
168
- type: "paragraph",
169
- content: [{ type: "text", text: "Regular Cell" }],
170
- },
171
- ],
172
- },
173
- ],
174
- },
175
- ],
176
- },
177
- ],
178
- };
179
- ```
180
-
181
- ### Document with Text Styles
182
-
183
- ```typescript
184
- const content = {
185
- type: "doc",
186
- content: [
187
- {
188
- type: "paragraph",
189
- content: [
190
- {
191
- type: "text",
192
- marks: [
193
- {
194
- type: "textStyle",
195
- attrs: {
196
- color: "#FF0000",
197
- fontSize: "18px",
198
- fontFamily: "Arial",
199
- backgroundColor: "#FFFF00",
200
- },
201
- },
202
- ],
203
- text: "Red, 18px, Arial text on yellow background",
204
- },
205
- ],
206
- },
207
- ],
208
- };
209
- ```
210
-
211
- ### Document with Lists
212
-
213
- ```typescript
214
- const content = {
215
- type: "doc",
216
- content: [
217
- {
218
- type: "bulletList",
219
- content: [
220
- {
221
- type: "listItem",
222
- content: [
223
- {
224
- type: "paragraph",
225
- content: [{ type: "text", text: "First item" }],
226
- },
227
- ],
228
- },
229
- {
230
- type: "listItem",
231
- content: [
232
- {
233
- type: "paragraph",
234
- content: [{ type: "text", text: "Second item" }],
235
- },
236
- ],
237
- },
238
- ],
239
- },
240
- ],
241
- };
242
- ```
243
-
244
- ## Known Limitations
245
-
246
- ### Blockquote Structure
247
-
248
- DOCX does not have a semantic blockquote structure. Blockquotes are exported as:
249
-
250
- - Indented paragraphs (720 twips / 0.5 inch left indentation)
251
- - Left border (single line)
252
-
253
- This is a DOCX format limitation, not a bug.
254
-
255
- ### Code Marks
256
-
257
- The `code` mark is exported as monospace font (Consolas). When re-importing, it will be recognized as `textStyle` with `fontFamily: "Consolas"`, not as a `code` mark.
258
-
259
- This is intentional - we do not detect code marks from fonts during import to avoid false positives.
260
-
261
- ### Color Name Conversion
262
-
263
- Color names (like `"red"`, `"green"`, `"blue"`) are automatically converted to hex values (`"#FF0000"`, `"#008000"`, `"#0000FF"`) for DOCX compatibility.
264
-
265
- ## Contributing
266
-
267
- Contributions are welcome! Please read our [Contributor Covenant](https://www.contributor-covenant.org/version/2/1/code_of_conduct/) and submit pull requests to the [main repository](https://github.com/DemoMacro/docen).
268
-
269
- ## License
270
-
271
- - [MIT](LICENSE) &copy; [Demo Macro](https://imst.xyz/)
1
+ # @docen/export-docx
2
+
3
+ ![npm version](https://img.shields.io/npm/v/@docen/export-docx)
4
+ ![npm downloads](https://img.shields.io/npm/dw/@docen/export-docx)
5
+ ![npm license](https://img.shields.io/npm/l/@docen/export-docx)
6
+
7
+ > Export TipTap/ProseMirror editor content to Microsoft Word DOCX format.
8
+
9
+ ## Features
10
+
11
+ - 📝 **Rich Text Support** - Full support for headings, paragraphs, and blockquotes with proper formatting
12
+ - 🖼️ **Image Handling** - Automatic image sizing, positioning, and metadata extraction
13
+ - 📊 **Table Support** - Complete table structure with headers, cells, colspan, and rowspan
14
+ - ✅ **Lists & Tasks** - Bullet lists, numbered lists with custom start numbers, and task lists with checkboxes
15
+ - 🎨 **Text Formatting** - Bold, italic, underline, strikethrough, subscript, and superscript
16
+ - 🎯 **Text Styles** - Comprehensive style support including colors, backgrounds, fonts, sizes, and line heights
17
+ - 🔗 **Links** - Hyperlink support with href preservation
18
+ - 💻 **Code Blocks** - Syntax highlighted code blocks with language attribute support
19
+ - 📁 **Collapsible Content** - Details/summary sections for expandable content
20
+ - 😀 **Emoji Support** - Native emoji rendering in documents
21
+ - 🧮 **Mathematical Content** - LaTeX-style formula support
22
+ - ⚙️ **Configurable Options** - Customizable export options for documents, tables, styles, and horizontal rules
23
+
24
+ ## Installation
25
+
26
+ ```bash
27
+ # Install with npm
28
+ $ npm install @docen/export-docx
29
+
30
+ # Install with yarn
31
+ $ yarn add @docen/export-docx
32
+
33
+ # Install with pnpm
34
+ $ pnpm add @docen/export-docx
35
+ ```
36
+
37
+ ## Quick Start
38
+
39
+ ```typescript
40
+ import { generateDOCX } from "@docen/export-docx";
41
+ import { writeFileSync } from "node:fs";
42
+
43
+ // Your TipTap/ProseMirror editor content
44
+ const content = {
45
+ type: "doc",
46
+ content: [
47
+ {
48
+ type: "paragraph",
49
+ content: [
50
+ {
51
+ type: "text",
52
+ marks: [{ type: "bold" }, { type: "italic" }],
53
+ text: "Hello, world!",
54
+ },
55
+ ],
56
+ },
57
+ ],
58
+ };
59
+
60
+ // Convert to DOCX and save to file
61
+ const docx = await generateDOCX(content, { outputType: "nodebuffer" });
62
+ writeFileSync("document.docx", docx);
63
+ ```
64
+
65
+ ## API Reference
66
+
67
+ ### `generateDOCX(content, options)`
68
+
69
+ Converts TipTap/ProseMirror content to DOCX format.
70
+
71
+ **Parameters:**
72
+
73
+ - `content: JSONContent` - TipTap/ProseMirror editor content
74
+ - `options: DocxExportOptions` - Export configuration options
75
+
76
+ **Returns:** `Promise<OutputByType[T]>` - DOCX file data with type matching the specified outputType
77
+
78
+ **Available Output Types:**
79
+
80
+ - `"base64"` - Base64 encoded string
81
+ - `"string"` - Text string
82
+ - `"text"` - Plain text
83
+ - `"binarystring"` - Binary string
84
+ - `"array"` - Array of numbers
85
+ - `"uint8array"` - Uint8Array
86
+ - `"arraybuffer"` - ArrayBuffer
87
+ - `"blob"` - Blob object
88
+ - `"nodebuffer"` - Node.js Buffer
89
+
90
+ **Configuration Options:**
91
+
92
+ - `title` - Document title
93
+ - `creator` - Document author
94
+ - `description` - Document description
95
+ - `outputType` - Output format (required)
96
+ - `table` - Table styling defaults (alignment, spacing, borders)
97
+ - `image` - Image handling options
98
+ - `styles` - Document default styles (font, line height, spacing)
99
+ - `horizontalRule` - Horizontal rule style
100
+
101
+ ## Supported Content Types
102
+
103
+ ### Text Formatting
104
+
105
+ - **Bold**, _Italic_, <u>Underline</u>, ~~Strikethrough~~
106
+ - ^Superscript^ and ~Subscript~
107
+ - Text colors and background colors
108
+ - Font families and sizes
109
+ - Line heights
110
+
111
+ ### Block Elements
112
+
113
+ - **Headings** (H1-H6) with level attribute
114
+ - **Paragraphs** with text alignment (left, right, center, justify)
115
+ - **Blockquotes** (Note: Exported as indented paragraphs with left border due to DOCX format)
116
+ - **Horizontal Rules** (Exported as page breaks by default)
117
+ - **Code Blocks** with language support
118
+
119
+ ### Lists
120
+
121
+ - **Bullet Lists** - Standard unordered lists
122
+ - **Numbered Lists** - Ordered lists with custom start number
123
+ - **Task Lists** - Checkbox lists with checked/unchecked states
124
+
125
+ ### Tables
126
+
127
+ - Complete table structure with rows and cells
128
+ - **Table Headers** with colspan/rowspan support
129
+ - **Table Cells** with colspan/rowspan support
130
+ - Cell alignment and formatting options
131
+
132
+ ### Media & Embeds
133
+
134
+ - **Images** with automatic sizing and positioning
135
+ - **Links** (hyperlinks) with href attribute
136
+ - **Emoji** rendering
137
+ - **Mathematics** formulas (LaTeX-style)
138
+ - **Details/Summary** collapsible sections
139
+
140
+ ## Examples
141
+
142
+ ### Document with Tables and Colspan/Rowspan
143
+
144
+ ```typescript
145
+ const content = {
146
+ type: "doc",
147
+ content: [
148
+ {
149
+ type: "table",
150
+ content: [
151
+ {
152
+ type: "tableRow",
153
+ content: [
154
+ {
155
+ type: "tableHeader",
156
+ attrs: { colspan: 2, rowspan: 1 },
157
+ content: [
158
+ {
159
+ type: "paragraph",
160
+ content: [{ type: "text", text: "Spanning Header" }],
161
+ },
162
+ ],
163
+ },
164
+ {
165
+ type: "tableCell",
166
+ content: [
167
+ {
168
+ type: "paragraph",
169
+ content: [{ type: "text", text: "Regular Cell" }],
170
+ },
171
+ ],
172
+ },
173
+ ],
174
+ },
175
+ ],
176
+ },
177
+ ],
178
+ };
179
+ ```
180
+
181
+ ### Document with Text Styles
182
+
183
+ ```typescript
184
+ const content = {
185
+ type: "doc",
186
+ content: [
187
+ {
188
+ type: "paragraph",
189
+ content: [
190
+ {
191
+ type: "text",
192
+ marks: [
193
+ {
194
+ type: "textStyle",
195
+ attrs: {
196
+ color: "#FF0000",
197
+ fontSize: "18px",
198
+ fontFamily: "Arial",
199
+ backgroundColor: "#FFFF00",
200
+ },
201
+ },
202
+ ],
203
+ text: "Red, 18px, Arial text on yellow background",
204
+ },
205
+ ],
206
+ },
207
+ ],
208
+ };
209
+ ```
210
+
211
+ ### Document with Lists
212
+
213
+ ```typescript
214
+ const content = {
215
+ type: "doc",
216
+ content: [
217
+ {
218
+ type: "bulletList",
219
+ content: [
220
+ {
221
+ type: "listItem",
222
+ content: [
223
+ {
224
+ type: "paragraph",
225
+ content: [{ type: "text", text: "First item" }],
226
+ },
227
+ ],
228
+ },
229
+ {
230
+ type: "listItem",
231
+ content: [
232
+ {
233
+ type: "paragraph",
234
+ content: [{ type: "text", text: "Second item" }],
235
+ },
236
+ ],
237
+ },
238
+ ],
239
+ },
240
+ ],
241
+ };
242
+ ```
243
+
244
+ ## Known Limitations
245
+
246
+ ### Blockquote Structure
247
+
248
+ DOCX does not have a semantic blockquote structure. Blockquotes are exported as:
249
+
250
+ - Indented paragraphs (720 twips / 0.5 inch left indentation)
251
+ - Left border (single line)
252
+
253
+ This is a DOCX format limitation, not a bug.
254
+
255
+ ### Code Marks
256
+
257
+ The `code` mark is exported as monospace font (Consolas). When re-importing, it will be recognized as `textStyle` with `fontFamily: "Consolas"`, not as a `code` mark.
258
+
259
+ This is intentional - we do not detect code marks from fonts during import to avoid false positives.
260
+
261
+ ### Color Name Conversion
262
+
263
+ Color names (like `"red"`, `"green"`, `"blue"`) are automatically converted to hex values (`"#FF0000"`, `"#008000"`, `"#0000FF"`) for DOCX compatibility.
264
+
265
+ ## Contributing
266
+
267
+ Contributions are welcome! Please read our [Contributor Covenant](https://www.contributor-covenant.org/version/2/1/code_of_conduct/) and submit pull requests to the [main repository](https://github.com/DemoMacro/docen).
268
+
269
+ ## License
270
+
271
+ - [MIT](LICENSE) &copy; [Demo Macro](https://imst.xyz/)
package/dist/docx.d.mts CHANGED
@@ -1 +1 @@
1
- export * from 'docx';
1
+ export * from "docx";
package/dist/docx.mjs CHANGED
@@ -1 +1,2 @@
1
- export*from"docx";
1
+ export * from "docx";
2
+ export {};