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