@mdgate/odf 0.6.8 → 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.
- package/README.md +148 -8
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -1,26 +1,166 @@
|
|
|
1
1
|
# @mdgate/odf
|
|
2
2
|
|
|
3
|
-
Convert OpenDocument
|
|
4
|
-
browsers. No native addons.
|
|
3
|
+
**Convert OpenDocument files to Markdown in TypeScript.**
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
[`@mdgate/odf`](https://github.com/mdgate/converters/tree/main/packages/odf) reads OpenDocument text, spreadsheets, presentations, and drawings directly in JavaScript and converts them into GitHub-Flavored Markdown, without Python, native addons, WASM, or LibreOffice.
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
Handles `.odt`, `.ods`, `.odp`, `.odg`, templates (`.ott`, `.ots`, `.otp`, `.otg`), and flat XML (`.fodt`, `.fods`, `.fodp`, `.fodg`).
|
|
8
|
+
|
|
9
|
+
Works in **Node.js, Cloudflare Workers, Edge runtimes, and browsers**.
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @mdgate/odf
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { toMarkdown } from '@mdgate/odf';
|
|
17
|
+
|
|
18
|
+
const markdown = await toMarkdown(bytes);
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`bytes` is a `Uint8Array`, so the file can come from a file upload, object storage, an HTTP request, a browser file picker, or anywhere else your application gets bytes.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Why [`@mdgate/odf`](https://github.com/mdgate/converters/tree/main/packages/odf)
|
|
26
|
+
|
|
27
|
+
OpenDocument is the native format of LibreOffice, many government systems, and a large share of non-Microsoft office files.
|
|
28
|
+
|
|
29
|
+
[`@mdgate/odf`](https://github.com/mdgate/converters/tree/main/packages/odf) is an ODF reader written for the same runtime as your application:
|
|
30
|
+
|
|
31
|
+
* **Pure TypeScript**
|
|
32
|
+
* **ODF → Markdown locally**
|
|
33
|
+
* **No Python runtime**
|
|
34
|
+
* **No native addons**
|
|
35
|
+
* **No WASM runtime**
|
|
36
|
+
* **Zero third-party runtime dependencies**
|
|
37
|
+
* **Works with raw `Uint8Array` input**
|
|
38
|
+
* **Detects ODF packages and flat XML from their contents, not only the filename**
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## What it extracts
|
|
43
|
+
|
|
44
|
+
[`@mdgate/odf`](https://github.com/mdgate/converters/tree/main/packages/odf) reads the ODF XML (from a ZIP package or a flat XML file) and rebuilds a shared document model.
|
|
45
|
+
|
|
46
|
+
The converter handles OpenDocument concerns including:
|
|
47
|
+
|
|
48
|
+
* text documents: headings, paragraphs, lists, links, emphasis
|
|
49
|
+
* spreadsheets: sheets as Markdown tables
|
|
50
|
+
* presentations: slide text in order
|
|
51
|
+
* drawings: readable text from the drawing
|
|
52
|
+
* styles that map onto headings and emphasis
|
|
53
|
+
* tables, including spanning cells where present
|
|
54
|
+
|
|
55
|
+
The output is Markdown that can be searched, indexed, chunked, cached, or passed directly to an AI agent.
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Node.js
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import { readFile } from 'node:fs/promises';
|
|
63
|
+
import { toMarkdown } from '@mdgate/odf';
|
|
64
|
+
|
|
65
|
+
const bytes = new Uint8Array(await readFile('paper.odt'));
|
|
66
|
+
const markdown = await toMarkdown(bytes);
|
|
67
|
+
|
|
68
|
+
console.log(markdown);
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## Browser
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import { toMarkdown } from '@mdgate/odf';
|
|
77
|
+
|
|
78
|
+
const file = input.files![0];
|
|
79
|
+
const bytes = new Uint8Array(await file.arrayBuffer());
|
|
80
|
+
|
|
81
|
+
const markdown = await toMarkdown(bytes);
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## Cloudflare Workers and Edge runtimes
|
|
9
87
|
|
|
10
88
|
```ts
|
|
11
89
|
import { toMarkdown } from '@mdgate/odf';
|
|
12
90
|
|
|
91
|
+
export default {
|
|
92
|
+
async fetch(request: Request) {
|
|
93
|
+
const bytes = new Uint8Array(await request.arrayBuffer());
|
|
94
|
+
const markdown = await toMarkdown(bytes);
|
|
95
|
+
|
|
96
|
+
return new Response(markdown, {
|
|
97
|
+
headers: {
|
|
98
|
+
'content-type': 'text/markdown; charset=utf-8',
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## Format detection
|
|
108
|
+
|
|
109
|
+
You do not need to trust the file extension.
|
|
110
|
+
|
|
111
|
+
[`@mdgate/odf`](https://github.com/mdgate/converters/tree/main/packages/odf) recognizes ODF ZIP packages from their mimetype and flat ODF from XML structure.
|
|
112
|
+
|
|
113
|
+
```ts
|
|
13
114
|
const markdown = await toMarkdown(bytes);
|
|
14
115
|
```
|
|
15
116
|
|
|
16
|
-
|
|
117
|
+
A path can still be supplied as a format hint when [`@mdgate/odf`](https://github.com/mdgate/converters/tree/main/packages/odf) 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.
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## Compose it with other file readers
|
|
122
|
+
|
|
123
|
+
[`@mdgate/odf`](https://github.com/mdgate/converters/tree/main/packages/odf) implements the converter interface from [`@mdgate/core`](https://github.com/mdgate/converters/tree/main/packages/core).
|
|
17
124
|
|
|
18
125
|
```ts
|
|
19
126
|
import { create } from '@mdgate/core';
|
|
20
127
|
import { odf } from '@mdgate/odf';
|
|
128
|
+
import { docx } from '@mdgate/docx';
|
|
129
|
+
import { pdf } from '@mdgate/pdf';
|
|
130
|
+
|
|
131
|
+
const read = create([
|
|
132
|
+
odf(),
|
|
133
|
+
docx(),
|
|
134
|
+
pdf(),
|
|
135
|
+
]);
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
The application still uses one reading interface while each format remains independently installable.
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## Need more than OpenDocument?
|
|
143
|
+
|
|
144
|
+
If your application needs to read many different file types, use the complete converter set:
|
|
21
145
|
|
|
22
|
-
|
|
146
|
+
```bash
|
|
147
|
+
npm install @mdgate/converters
|
|
23
148
|
```
|
|
24
149
|
|
|
25
|
-
|
|
26
|
-
|
|
150
|
+
```ts
|
|
151
|
+
import { toMarkdown } from '@mdgate/converters';
|
|
152
|
+
|
|
153
|
+
const markdown = await toMarkdown(bytes, {
|
|
154
|
+
path: filename,
|
|
155
|
+
});
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
[`@mdgate/odf`](https://github.com/mdgate/converters/tree/main/packages/odf) is one of the single-format packages in the open-source [`mdgate/converters`](https://github.com/mdgate/converters) project.
|
|
159
|
+
|
|
160
|
+
For AI agents, the same converter architecture can be used to extend `read_file` from text files to real-world document formats.
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## License
|
|
165
|
+
|
|
166
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdgate/odf",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.9",
|
|
4
4
|
"description": "mdgate OpenDocument converter (odt/ods/odp/odg and flat/templates)",
|
|
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.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"
|