@mdgate/doc 0.6.8 → 0.6.10
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 +172 -8
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -1,26 +1,190 @@
|
|
|
1
1
|
# @mdgate/doc
|
|
2
2
|
|
|
3
|
-
Convert legacy
|
|
4
|
-
browsers. No native addons.
|
|
3
|
+
**Convert legacy Word `.doc` files to Markdown in TypeScript.**
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
[`@mdgate/doc`](https://github.com/mdgate/converters/tree/main/packages/doc) reads binary Word documents (`.doc`, `.dot`) directly in JavaScript and converts them into GitHub-Flavored Markdown, without Python, native addons, WASM, or Microsoft Word.
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
Works in **Node.js, Cloudflare Workers, Edge runtimes, and browsers**.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @mdgate/doc
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { toMarkdown } from '@mdgate/doc';
|
|
15
|
+
|
|
16
|
+
const markdown = await toMarkdown(bytes);
|
|
17
|
+
```
|
|
18
|
+
|
|
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/doc`](https://github.com/mdgate/converters/tree/main/packages/doc)
|
|
24
|
+
|
|
25
|
+
Old Word files are still everywhere: attachments from 2004, government forms, mail archives.
|
|
26
|
+
|
|
27
|
+
Most JavaScript stacks have a DOCX parser and nothing for binary Word. [`@mdgate/doc`](https://github.com/mdgate/converters/tree/main/packages/doc) reads the OLE compound file in the same runtime as your application:
|
|
28
|
+
|
|
29
|
+
* **Pure TypeScript**
|
|
30
|
+
* **DOC → 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 binary Word from OLE streams, not only the filename**
|
|
37
|
+
|
|
38
|
+
Use it when an agent or ingestion pipeline has to read the Word format people actually sent, not only `.docx`.
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## What it extracts
|
|
43
|
+
|
|
44
|
+
[`@mdgate/doc`](https://github.com/mdgate/converters/tree/main/packages/doc) parses the binary Word document stream and rebuilds a shared document model.
|
|
45
|
+
|
|
46
|
+
The converter handles Word 97-2003 concerns including:
|
|
47
|
+
|
|
48
|
+
* paragraphs and heading styles
|
|
49
|
+
* bold, italic, and strikethrough
|
|
50
|
+
* lists
|
|
51
|
+
* tables
|
|
52
|
+
* basic character encoding
|
|
53
|
+
* encrypted document detection
|
|
54
|
+
|
|
55
|
+
The output is Markdown that can be searched, indexed, chunked, cached, or passed directly to an AI agent.
|
|
56
|
+
|
|
57
|
+
OOXML Word files (`.docx`) are a different format. Use [`@mdgate/docx`](https://github.com/mdgate/converters/tree/main/packages/docx) for those.
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## Node.js
|
|
9
62
|
|
|
10
63
|
```ts
|
|
64
|
+
import { readFile } from 'node:fs/promises';
|
|
11
65
|
import { toMarkdown } from '@mdgate/doc';
|
|
12
66
|
|
|
67
|
+
const bytes = new Uint8Array(await readFile('memo.doc'));
|
|
13
68
|
const markdown = await toMarkdown(bytes);
|
|
69
|
+
|
|
70
|
+
console.log(markdown);
|
|
14
71
|
```
|
|
15
72
|
|
|
16
|
-
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## Browser
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
import { toMarkdown } from '@mdgate/doc';
|
|
79
|
+
|
|
80
|
+
const file = input.files![0];
|
|
81
|
+
const bytes = new Uint8Array(await file.arrayBuffer());
|
|
82
|
+
|
|
83
|
+
const markdown = await toMarkdown(bytes);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Conversion can happen locally without uploading the document to a parsing service.
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## Cloudflare Workers and Edge runtimes
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
import { toMarkdown } from '@mdgate/doc';
|
|
94
|
+
|
|
95
|
+
export default {
|
|
96
|
+
async fetch(request: Request) {
|
|
97
|
+
const bytes = new Uint8Array(await request.arrayBuffer());
|
|
98
|
+
const markdown = await toMarkdown(bytes);
|
|
99
|
+
|
|
100
|
+
return new Response(markdown, {
|
|
101
|
+
headers: {
|
|
102
|
+
'content-type': 'text/markdown; charset=utf-8',
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
```text
|
|
110
|
+
upload DOC
|
|
111
|
+
↓
|
|
112
|
+
Cloudflare Worker
|
|
113
|
+
↓
|
|
114
|
+
@mdgate/doc
|
|
115
|
+
↓
|
|
116
|
+
Markdown
|
|
117
|
+
↓
|
|
118
|
+
agent / search / index / storage
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## Format detection
|
|
124
|
+
|
|
125
|
+
You do not need to trust the file extension.
|
|
126
|
+
|
|
127
|
+
[`@mdgate/doc`](https://github.com/mdgate/converters/tree/main/packages/doc) recognizes binary Word from OLE compound-file streams.
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
const markdown = await toMarkdown(bytes);
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
A path can still be supplied as a format hint when [`@mdgate/doc`](https://github.com/mdgate/converters/tree/main/packages/doc) 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.
|
|
134
|
+
|
|
135
|
+
Some files named `.doc` are actually RTF. Those belong to [`@mdgate/rtf`](https://github.com/mdgate/converters/tree/main/packages/rtf).
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## Encrypted documents
|
|
140
|
+
|
|
141
|
+
Encrypted or password-protected Word files are reported as encrypted rather than returning misleading partial output.
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## Compose it with other file readers
|
|
146
|
+
|
|
147
|
+
[`@mdgate/doc`](https://github.com/mdgate/converters/tree/main/packages/doc) implements the converter interface from [`@mdgate/core`](https://github.com/mdgate/converters/tree/main/packages/core).
|
|
17
148
|
|
|
18
149
|
```ts
|
|
19
150
|
import { create } from '@mdgate/core';
|
|
20
151
|
import { doc } from '@mdgate/doc';
|
|
152
|
+
import { docx } from '@mdgate/docx';
|
|
153
|
+
|
|
154
|
+
const read = create([
|
|
155
|
+
doc(),
|
|
156
|
+
docx(),
|
|
157
|
+
]);
|
|
158
|
+
|
|
159
|
+
const markdown = await read(bytes);
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
The application still uses one reading interface while each format remains independently installable.
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## Need more than Word?
|
|
21
167
|
|
|
22
|
-
|
|
168
|
+
If your application needs to read many different file types, use the complete converter set:
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
npm install @mdgate/converters
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
import { toMarkdown } from '@mdgate/converters';
|
|
176
|
+
|
|
177
|
+
const markdown = await toMarkdown(bytes, {
|
|
178
|
+
path: filename,
|
|
179
|
+
});
|
|
23
180
|
```
|
|
24
181
|
|
|
25
|
-
|
|
26
|
-
|
|
182
|
+
[`@mdgate/doc`](https://github.com/mdgate/converters/tree/main/packages/doc) is one of the single-format packages in the open-source [`mdgate/converters`](https://github.com/mdgate/converters) project.
|
|
183
|
+
|
|
184
|
+
For AI agents, the same converter architecture can be used to extend `read_file` from text files to real-world document formats.
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## License
|
|
189
|
+
|
|
190
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdgate/doc",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.10",
|
|
4
4
|
"description": "mdgate legacy Word converter (binary .doc)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"homepage": "https://
|
|
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.
|
|
32
|
-
"@mdgate/core": "0.6.
|
|
33
|
-
"@mdgate/document": "0.6.
|
|
34
|
-
"@mdgate/office-common": "0.6.
|
|
35
|
-
"@mdgate/utils": "0.6.
|
|
31
|
+
"@mdgate/containers": "0.6.10",
|
|
32
|
+
"@mdgate/core": "0.6.10",
|
|
33
|
+
"@mdgate/document": "0.6.10",
|
|
34
|
+
"@mdgate/office-common": "0.6.10",
|
|
35
|
+
"@mdgate/utils": "0.6.10"
|
|
36
36
|
},
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public"
|