@mdgate/docx 0.6.7 → 0.6.9

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 (2) hide show
  1. package/README.md +186 -8
  2. package/package.json +7 -7
package/README.md CHANGED
@@ -1,11 +1,14 @@
1
1
  # @mdgate/docx
2
2
 
3
- Convert Word documents to Markdown. Outputs GitHub-Flavored Markdown. Works in Node, Edge, and
4
- browsers. No native addons.
3
+ **Convert Word documents to Markdown in TypeScript.**
5
4
 
6
- Handles: `.docx`, `.docm`, `.dotx`, `.dotm`
5
+ [`@mdgate/docx`](https://github.com/mdgate/converters/tree/main/packages/docx) reads `.docx`, `.docm`, `.dotx`, and `.dotm` files directly in JavaScript and converts them into GitHub-Flavored Markdown, without Python, native addons, WASM, or an external Word service.
7
6
 
8
- ## Usage
7
+ Works in **Node.js, Cloudflare Workers, Edge runtimes, and browsers**.
8
+
9
+ ```bash
10
+ npm install @mdgate/docx
11
+ ```
9
12
 
10
13
  ```ts
11
14
  import { toMarkdown } from '@mdgate/docx';
@@ -13,14 +16,189 @@ import { toMarkdown } from '@mdgate/docx';
13
16
  const markdown = await toMarkdown(bytes);
14
17
  ```
15
18
 
16
- Compose with other converters:
19
+ `bytes` is a `Uint8Array`, so the document can come from a file upload, object storage, an HTTP request, a browser file picker, or anywhere else your application gets bytes.
20
+
21
+ ---
22
+
23
+ ## Why [`@mdgate/docx`](https://github.com/mdgate/converters/tree/main/packages/docx)
24
+
25
+ Word support often means a native library, a desktop application, or a remote conversion API.
26
+
27
+ [`@mdgate/docx`](https://github.com/mdgate/converters/tree/main/packages/docx) is a Word reader written for the same runtime as your application:
28
+
29
+ * **Pure TypeScript**
30
+ * **DOCX → Markdown locally**
31
+ * **No Python runtime**
32
+ * **No native addons**
33
+ * **No WASM runtime**
34
+ * **Zero third-party runtime dependencies**
35
+ * **Works with raw `Uint8Array` input**
36
+ * **Detects OOXML Word packages from their contents, not only the filename**
37
+
38
+ Use it when your application, AI agent, ingestion pipeline, or serverless function needs to read Word files without operating a separate document-processing service.
39
+
40
+ ---
41
+
42
+ ## What it extracts
43
+
44
+ [`@mdgate/docx`](https://github.com/mdgate/converters/tree/main/packages/docx) walks WordprocessingML and rebuilds a shared document model, then renders GitHub-Flavored Markdown.
45
+
46
+ The converter handles Word-specific concerns including:
47
+
48
+ * headings and paragraphs
49
+ * bold, italic, and strikethrough
50
+ * links
51
+ * ordered, unordered, and nested lists
52
+ * tables, including merged cells
53
+ * footnotes and endnotes
54
+ * field results
55
+ * charts and diagrams as readable blocks when present
56
+ * images that can be handed to a reader composed with [`@mdgate/core`](https://github.com/mdgate/converters/tree/main/packages/core)
57
+
58
+ The output is Markdown that can be searched, indexed, chunked, cached, or passed directly to an AI agent.
59
+
60
+ ---
61
+
62
+ ## Node.js
63
+
64
+ ```ts
65
+ import { readFile } from 'node:fs/promises';
66
+ import { toMarkdown } from '@mdgate/docx';
67
+
68
+ const bytes = new Uint8Array(await readFile('report.docx'));
69
+ const markdown = await toMarkdown(bytes);
70
+
71
+ console.log(markdown);
72
+ ```
73
+
74
+ ---
75
+
76
+ ## Browser
77
+
78
+ Word files can be converted directly from a browser file picker.
79
+
80
+ ```ts
81
+ import { toMarkdown } from '@mdgate/docx';
82
+
83
+ const file = input.files![0];
84
+ const bytes = new Uint8Array(await file.arrayBuffer());
85
+
86
+ const markdown = await toMarkdown(bytes);
87
+ ```
88
+
89
+ Conversion can happen locally without uploading the document to a parsing service.
90
+
91
+ ---
92
+
93
+ ## Cloudflare Workers and Edge runtimes
94
+
95
+ Because [`@mdgate/docx`](https://github.com/mdgate/converters/tree/main/packages/docx) does not depend on Python, native binaries, WASM, or a separate execution runtime, it can be used as a normal JavaScript dependency in Cloudflare Workers and other Edge runtimes.
96
+
97
+ ```ts
98
+ import { toMarkdown } from '@mdgate/docx';
99
+
100
+ export default {
101
+ async fetch(request: Request) {
102
+ const bytes = new Uint8Array(await request.arrayBuffer());
103
+ const markdown = await toMarkdown(bytes);
104
+
105
+ return new Response(markdown, {
106
+ headers: {
107
+ 'content-type': 'text/markdown; charset=utf-8',
108
+ },
109
+ });
110
+ },
111
+ };
112
+ ```
113
+
114
+ This makes it suitable for workflows such as:
115
+
116
+ ```text
117
+ upload DOCX
118
+
119
+ Cloudflare Worker
120
+
121
+ @mdgate/docx
122
+
123
+ Markdown
124
+
125
+ agent / search / index / storage
126
+ ```
127
+
128
+ ---
129
+
130
+ ## Format detection
131
+
132
+ You do not need to trust the file extension.
133
+
134
+ [`@mdgate/docx`](https://github.com/mdgate/converters/tree/main/packages/docx) recognizes Word OOXML packages from ZIP package metadata.
135
+
136
+ ```ts
137
+ const markdown = await toMarkdown(bytes);
138
+ ```
139
+
140
+ A path can still be supplied as a format hint when [`@mdgate/docx`](https://github.com/mdgate/converters/tree/main/packages/docx) is used through [`@mdgate/converters`](https://github.com/mdgate/converters/tree/main/packages/converters) or a reader composed with [`@mdgate/core`](https://github.com/mdgate/converters/tree/main/packages/core), but the path is never used to read a file from disk.
141
+
142
+ Legacy binary `.doc` files are a different format. Use [`@mdgate/doc`](https://github.com/mdgate/converters/tree/main/packages/doc) for those.
143
+
144
+ ---
145
+
146
+ ## Compose it with other file readers
147
+
148
+ [`@mdgate/docx`](https://github.com/mdgate/converters/tree/main/packages/docx) implements the converter interface from [`@mdgate/core`](https://github.com/mdgate/converters/tree/main/packages/core).
149
+
150
+ ```ts
151
+ import { create } from '@mdgate/core';
152
+ import { docx } from '@mdgate/docx';
153
+
154
+ const read = create([
155
+ docx(),
156
+ ]);
157
+
158
+ const markdown = await read(bytes);
159
+ ```
160
+
161
+ Add other converters when your application needs more than Word:
17
162
 
18
163
  ```ts
19
164
  import { create } from '@mdgate/core';
20
165
  import { docx } from '@mdgate/docx';
166
+ import { pdf } from '@mdgate/pdf';
167
+ import { xlsx } from '@mdgate/xlsx';
168
+
169
+ const read = create([
170
+ docx(),
171
+ pdf(),
172
+ xlsx(),
173
+ ]);
174
+ ```
175
+
176
+ The application still uses one reading interface while each format remains independently installable.
177
+
178
+ ---
21
179
 
22
- const convert = create([docx()]);
180
+ ## Need more than Word?
181
+
182
+ If your application needs to read many different file types, use the complete converter set:
183
+
184
+ ```bash
185
+ npm install @mdgate/converters
186
+ ```
187
+
188
+ ```ts
189
+ import { toMarkdown } from '@mdgate/converters';
190
+
191
+ const markdown = await toMarkdown(bytes, {
192
+ path: filename,
193
+ });
23
194
  ```
24
195
 
25
- Part of [mdgate converters](https://github.com/mdgate/converters); install
26
- `@mdgate/converters` for every format at once.
196
+ [`@mdgate/docx`](https://github.com/mdgate/converters/tree/main/packages/docx) is one of the single-format packages in the open-source [`mdgate/converters`](https://github.com/mdgate/converters) project.
197
+
198
+ For AI agents, the same converter architecture can be used to extend `read_file` from text files to real-world document formats.
199
+
200
+ ---
201
+
202
+ ## License
203
+
204
+ MIT
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@mdgate/docx",
3
- "version": "0.6.7",
3
+ "version": "0.6.9",
4
4
  "description": "mdgate Word converter (docx/docm)",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
- "homepage": "https://demo.mdgate.dev",
7
+ "homepage": "https://convert.mdgate.dev",
8
8
  "repository": {
9
9
  "type": "git",
10
10
  "url": "git+https://github.com/mdgate/converters.git",
@@ -28,11 +28,11 @@
28
28
  "prepublishOnly": "bun run build"
29
29
  },
30
30
  "dependencies": {
31
- "@mdgate/containers": "0.6.7",
32
- "@mdgate/core": "0.6.7",
33
- "@mdgate/document": "0.6.7",
34
- "@mdgate/office-common": "0.6.7",
35
- "@mdgate/utils": "0.6.7"
31
+ "@mdgate/containers": "0.6.9",
32
+ "@mdgate/core": "0.6.9",
33
+ "@mdgate/document": "0.6.9",
34
+ "@mdgate/office-common": "0.6.9",
35
+ "@mdgate/utils": "0.6.9"
36
36
  },
37
37
  "publishConfig": {
38
38
  "access": "public"