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