@markitdownjs/epub 0.1.0
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/dist/epub-converter.d.ts +49 -0
- package/dist/epub-converter.d.ts.map +1 -0
- package/dist/epub-converter.js +715 -0
- package/dist/epub-converter.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +33 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Converter, ConversionInput, ConversionResult } from "@markitdownjs/shared";
|
|
2
|
+
/**
|
|
3
|
+
* Converts EPUB e-book files into AST and Markdown output.
|
|
4
|
+
*
|
|
5
|
+
* Key features:
|
|
6
|
+
* - Parses `META-INF/container.xml` to locate the OPF file
|
|
7
|
+
* - Extracts metadata (title, creator, language, etc.) from the OPF
|
|
8
|
+
* - Reads content files in SPINE ORDER (not alphabetical)
|
|
9
|
+
* - Recursively traverses XHTML content without `document.createTreeWalker`
|
|
10
|
+
* - Produces a complete DocumentNode AST with all content in correct reading order
|
|
11
|
+
* - Renders headings, paragraphs, lists, tables, links, images, and code blocks
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const converter = new EpubConverter();
|
|
16
|
+
* const result = await converter.convert({ data: epubBuffer });
|
|
17
|
+
* console.log(result.ast); // DocumentNode AST
|
|
18
|
+
* console.log(result.markdown); // Rendered Markdown
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare class EpubConverter implements Converter {
|
|
22
|
+
readonly id = "epub";
|
|
23
|
+
readonly supportedMimeTypes: string[];
|
|
24
|
+
readonly supportedExtensions: string[];
|
|
25
|
+
/**
|
|
26
|
+
* Checks whether this converter can handle the given input.
|
|
27
|
+
* Validates MIME type, file extension, and ZIP magic bytes.
|
|
28
|
+
*
|
|
29
|
+
* @param input - The conversion input to check
|
|
30
|
+
* @returns True if this converter can process the input
|
|
31
|
+
*/
|
|
32
|
+
canConvert(input: ConversionInput): Promise<boolean>;
|
|
33
|
+
/**
|
|
34
|
+
* Converts an EPUB file into a ConversionResult with AST and Markdown.
|
|
35
|
+
*
|
|
36
|
+
* Processing steps:
|
|
37
|
+
* 1. Parse the ZIP archive
|
|
38
|
+
* 2. Read `META-INF/container.xml` to find the OPF path
|
|
39
|
+
* 3. Parse the OPF for metadata, manifest, and spine
|
|
40
|
+
* 4. Read XHTML files in spine order
|
|
41
|
+
* 5. Parse each XHTML into AST nodes
|
|
42
|
+
* 6. Build the complete document AST and render to Markdown
|
|
43
|
+
*
|
|
44
|
+
* @param input - The EPUB file as Uint8Array, ArrayBuffer, Blob, or string
|
|
45
|
+
* @returns A ConversionResult with the document AST, Markdown, and metadata
|
|
46
|
+
*/
|
|
47
|
+
convert(input: ConversionInput): Promise<ConversionResult>;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=epub-converter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"epub-converter.d.ts","sourceRoot":"","sources":["../src/epub-converter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,eAAe,EACf,gBAAgB,EAKjB,MAAM,sBAAsB,CAAC;AAupB9B;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,aAAc,YAAW,SAAS;IAC7C,QAAQ,CAAC,EAAE,UAAU;IACrB,QAAQ,CAAC,kBAAkB,WAA4B;IACvD,QAAQ,CAAC,mBAAmB,WAAa;IAEzC;;;;;;OAMG;IACG,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC;IA+B1D;;;;;;;;;;;;;OAaG;IACG,OAAO,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAyGjE"}
|
|
@@ -0,0 +1,715 @@
|
|
|
1
|
+
import { createNode, readInputData, parseHTML, } from "@markitdownjs/shared";
|
|
2
|
+
import JSZip from "jszip";
|
|
3
|
+
/** Known XHTML content file extensions within EPUB archives. */
|
|
4
|
+
const XHTML_EXTENSIONS = [".html", ".xhtml", ".htm", ".xml"];
|
|
5
|
+
// ─── OPF Parsing Helpers ──────────────────────────────────────────────────────
|
|
6
|
+
/**
|
|
7
|
+
* Parses the `META-INF/container.xml` file to extract the path to the OPF file.
|
|
8
|
+
*
|
|
9
|
+
* @param zip - The JSZip instance containing the EPUB archive
|
|
10
|
+
* @returns The relative path to the OPF file within the archive
|
|
11
|
+
* @throws If container.xml is missing or does not contain a rootfile element
|
|
12
|
+
*/
|
|
13
|
+
async function getOpfPathFromContainer(zip) {
|
|
14
|
+
const containerFile = zip.file("META-INF/container.xml");
|
|
15
|
+
if (!containerFile) {
|
|
16
|
+
throw new Error("EPUB is missing META-INF/container.xml");
|
|
17
|
+
}
|
|
18
|
+
const containerXml = await containerFile.async("string");
|
|
19
|
+
const doc = await parseXMLString(containerXml);
|
|
20
|
+
const rootfileEl = doc.querySelector("rootfile");
|
|
21
|
+
if (!rootfileEl) {
|
|
22
|
+
throw new Error("container.xml does not contain a <rootfile> element");
|
|
23
|
+
}
|
|
24
|
+
const opfPath = rootfileEl.getAttribute("full-path");
|
|
25
|
+
if (!opfPath) {
|
|
26
|
+
throw new Error("<rootfile> element is missing the full-path attribute");
|
|
27
|
+
}
|
|
28
|
+
return opfPath;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Parses the OPF (Open Packaging Format) file to extract metadata, manifest, and spine.
|
|
32
|
+
*
|
|
33
|
+
* @param zip - The JSZip instance containing the EPUB archive
|
|
34
|
+
* @param opfPath - The relative path to the OPF file within the archive
|
|
35
|
+
* @returns The parsed OPF package structure
|
|
36
|
+
*/
|
|
37
|
+
async function parseOpf(zip, opfPath) {
|
|
38
|
+
const opfFile = zip.file(opfPath);
|
|
39
|
+
if (!opfFile) {
|
|
40
|
+
throw new Error(`OPF file not found at: ${opfPath}`);
|
|
41
|
+
}
|
|
42
|
+
const opfXml = await opfFile.async("string");
|
|
43
|
+
const doc = await parseXMLString(opfXml);
|
|
44
|
+
const opfDir = opfPath.substring(0, opfPath.lastIndexOf("/") + 1);
|
|
45
|
+
const metadata = parseMetadata(doc);
|
|
46
|
+
const manifest = parseManifest(doc, opfDir);
|
|
47
|
+
const spine = parseSpine(doc);
|
|
48
|
+
return { metadata, manifest, spine };
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Parses the `<metadata>` section of the OPF document.
|
|
52
|
+
* Extracts Dublin Core (dc:*) elements and additional properties.
|
|
53
|
+
*
|
|
54
|
+
* @param doc - The parsed OPF XML document
|
|
55
|
+
* @returns The extracted metadata
|
|
56
|
+
*/
|
|
57
|
+
function parseMetadata(doc) {
|
|
58
|
+
const meta = { custom: {} };
|
|
59
|
+
const metaEl = doc.querySelector("metadata");
|
|
60
|
+
if (!metaEl)
|
|
61
|
+
return meta;
|
|
62
|
+
// Helper: get the first matching element's text content
|
|
63
|
+
const getText = (tag) => {
|
|
64
|
+
const el = metaEl.querySelector(tag);
|
|
65
|
+
return el?.textContent?.trim() || undefined;
|
|
66
|
+
};
|
|
67
|
+
// Helper: get all matching elements' text content
|
|
68
|
+
const getAllText = (tag) => {
|
|
69
|
+
return Array.from(metaEl.querySelectorAll(tag))
|
|
70
|
+
.map((el) => el.textContent?.trim())
|
|
71
|
+
.filter((t) => !!t);
|
|
72
|
+
};
|
|
73
|
+
meta.title = getText("dc\\:title") ?? getText("title");
|
|
74
|
+
meta.creator = getText("dc\\:creator") ?? getText("creator");
|
|
75
|
+
meta.language = getText("dc\\:language") ?? getText("language");
|
|
76
|
+
meta.identifier = getText("dc\\:identifier") ?? getText("identifier");
|
|
77
|
+
meta.description = getText("dc\\:description") ?? getText("description");
|
|
78
|
+
meta.date = getText("dc\\:date") ?? getText("date");
|
|
79
|
+
meta.publisher = getText("dc\\:publisher") ?? getText("publisher");
|
|
80
|
+
meta.rights = getText("dc\\:rights") ?? getText("rights");
|
|
81
|
+
meta.subject = [
|
|
82
|
+
...(getAllText("dc\\:subject") ?? []),
|
|
83
|
+
...(getAllText("subject") ?? []),
|
|
84
|
+
];
|
|
85
|
+
// Additional meta elements
|
|
86
|
+
const allMetaEls = metaEl.querySelectorAll("meta");
|
|
87
|
+
for (const m of Array.from(allMetaEls)) {
|
|
88
|
+
const name = m.getAttribute("name") ?? m.getAttribute("property");
|
|
89
|
+
const content = m.getAttribute("content") ?? m.textContent;
|
|
90
|
+
if (name && content) {
|
|
91
|
+
meta.custom[name] = content.trim();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return meta;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Parses the `<manifest>` section of the OPF document.
|
|
98
|
+
* Returns a Map of item id to manifest item for quick lookup.
|
|
99
|
+
*
|
|
100
|
+
* @param doc - The parsed OPF XML document
|
|
101
|
+
* @param opfDir - The directory containing the OPF file (for resolving relative hrefs)
|
|
102
|
+
* @returns A Map from item id to OpfManifestItem
|
|
103
|
+
*/
|
|
104
|
+
function parseManifest(doc, opfDir) {
|
|
105
|
+
const manifest = new Map();
|
|
106
|
+
const manifestEl = doc.querySelector("manifest");
|
|
107
|
+
if (!manifestEl)
|
|
108
|
+
return manifest;
|
|
109
|
+
const items = manifestEl.querySelectorAll("item");
|
|
110
|
+
for (const item of Array.from(items)) {
|
|
111
|
+
const id = item.getAttribute("id");
|
|
112
|
+
const href = item.getAttribute("href");
|
|
113
|
+
const mediaType = item.getAttribute("media-type");
|
|
114
|
+
if (id && href && mediaType) {
|
|
115
|
+
const resolvedHref = opfDir + href;
|
|
116
|
+
manifest.set(id, { id, href: resolvedHref, mediaType });
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return manifest;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Parses the `<spine>` section of the OPF document.
|
|
123
|
+
* Returns the ordered list of item references that define reading order.
|
|
124
|
+
*
|
|
125
|
+
* @param doc - The parsed OPF XML document
|
|
126
|
+
* @returns An array of spine item references
|
|
127
|
+
*/
|
|
128
|
+
function parseSpine(doc) {
|
|
129
|
+
const spine = [];
|
|
130
|
+
const spineEl = doc.querySelector("spine");
|
|
131
|
+
if (!spineEl)
|
|
132
|
+
return spine;
|
|
133
|
+
const itemrefs = spineEl.querySelectorAll("itemref");
|
|
134
|
+
for (const ref of Array.from(itemrefs)) {
|
|
135
|
+
const idref = ref.getAttribute("idref");
|
|
136
|
+
if (idref) {
|
|
137
|
+
spine.push({
|
|
138
|
+
idref,
|
|
139
|
+
linear: ref.getAttribute("linear") ?? undefined,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return spine;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Parses an XML string into a DOM Document using linkedom.
|
|
147
|
+
*
|
|
148
|
+
* @param xmlString - The XML content to parse
|
|
149
|
+
* @returns A Document object representing the parsed XML
|
|
150
|
+
*/
|
|
151
|
+
async function parseXMLString(xmlString) {
|
|
152
|
+
const DP = await getDOMParser();
|
|
153
|
+
return new DP().parseFromString(xmlString, "application/xml");
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Gets a DOMParser instance, preferring globalThis, then linkedom.
|
|
157
|
+
*
|
|
158
|
+
* @returns A DOMParser constructor
|
|
159
|
+
* @throws If no DOMParser is available
|
|
160
|
+
*/
|
|
161
|
+
async function getDOMParser() {
|
|
162
|
+
if (typeof globalThis.DOMParser !== "undefined") {
|
|
163
|
+
return globalThis.DOMParser;
|
|
164
|
+
}
|
|
165
|
+
try {
|
|
166
|
+
const mod = await import("linkedom");
|
|
167
|
+
if (mod.DOMParser) {
|
|
168
|
+
return mod.DOMParser;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
// linkedom not available
|
|
173
|
+
}
|
|
174
|
+
throw new Error("DOMParser is not available. Install 'linkedom' for Node.js support: npm install linkedom");
|
|
175
|
+
}
|
|
176
|
+
// ─── XHTML Content Processing ─────────────────────────────────────────────────
|
|
177
|
+
/**
|
|
178
|
+
* Recursively processes the child nodes of a DOM element into AST nodes.
|
|
179
|
+
* Replaces `document.createTreeWalker` with recursive traversal for Node.js compatibility.
|
|
180
|
+
*
|
|
181
|
+
* @param nodes - The DOM child nodes to process
|
|
182
|
+
* @returns An array of AST nodes
|
|
183
|
+
*/
|
|
184
|
+
function processChildNodes(nodes) {
|
|
185
|
+
const result = [];
|
|
186
|
+
for (const node of nodes) {
|
|
187
|
+
const converted = processSingleNode(node);
|
|
188
|
+
if (converted) {
|
|
189
|
+
if (Array.isArray(converted)) {
|
|
190
|
+
result.push(...converted);
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
result.push(converted);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return result;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Processes a single DOM node into an AST node or array of AST nodes.
|
|
201
|
+
* Uses numeric constants (3=TEXT_NODE, 8=COMMENT_NODE) for Node.js compatibility.
|
|
202
|
+
*
|
|
203
|
+
* @param node - The DOM node to process
|
|
204
|
+
* @returns The corresponding AST node(s), or null if the node should be skipped
|
|
205
|
+
*/
|
|
206
|
+
function processSingleNode(node) {
|
|
207
|
+
// Node.TEXT_NODE = 3, Node.COMMENT_NODE = 8
|
|
208
|
+
if (node.nodeType === 3) {
|
|
209
|
+
const text = node.textContent ?? "";
|
|
210
|
+
if (!text.trim())
|
|
211
|
+
return null;
|
|
212
|
+
return createNode({ type: "text", value: text });
|
|
213
|
+
}
|
|
214
|
+
if (node.nodeType === 8)
|
|
215
|
+
return null;
|
|
216
|
+
const el = node;
|
|
217
|
+
const tag = el.tagName.toLowerCase();
|
|
218
|
+
switch (tag) {
|
|
219
|
+
case "h1":
|
|
220
|
+
case "h2":
|
|
221
|
+
case "h3":
|
|
222
|
+
case "h4":
|
|
223
|
+
case "h5":
|
|
224
|
+
case "h6":
|
|
225
|
+
return createNode({
|
|
226
|
+
type: "heading",
|
|
227
|
+
level: parseInt(tag[1]),
|
|
228
|
+
children: processChildNodes(Array.from(el.childNodes)),
|
|
229
|
+
id: el.getAttribute("id") ?? undefined,
|
|
230
|
+
});
|
|
231
|
+
case "p":
|
|
232
|
+
return createNode({
|
|
233
|
+
type: "paragraph",
|
|
234
|
+
children: processChildNodes(Array.from(el.childNodes)),
|
|
235
|
+
});
|
|
236
|
+
case "table":
|
|
237
|
+
return processTableElement(el);
|
|
238
|
+
case "ul":
|
|
239
|
+
case "ol":
|
|
240
|
+
return createNode({
|
|
241
|
+
type: "list",
|
|
242
|
+
ordered: tag === "ol",
|
|
243
|
+
start: tag === "ol"
|
|
244
|
+
? parseInt(el.getAttribute("start") ?? "1") || 1
|
|
245
|
+
: undefined,
|
|
246
|
+
children: processListItems(el),
|
|
247
|
+
});
|
|
248
|
+
case "a":
|
|
249
|
+
return createNode({
|
|
250
|
+
type: "link",
|
|
251
|
+
href: el.getAttribute("href") ?? "",
|
|
252
|
+
title: el.getAttribute("title") ?? undefined,
|
|
253
|
+
children: processChildNodes(Array.from(el.childNodes)),
|
|
254
|
+
});
|
|
255
|
+
case "img":
|
|
256
|
+
return createNode({
|
|
257
|
+
type: "image",
|
|
258
|
+
src: el.getAttribute("src") ?? "",
|
|
259
|
+
alt: el.getAttribute("alt") ?? undefined,
|
|
260
|
+
title: el.getAttribute("title") ?? undefined,
|
|
261
|
+
width: el.hasAttribute("width")
|
|
262
|
+
? parseInt(el.getAttribute("width") ?? "0") || undefined
|
|
263
|
+
: undefined,
|
|
264
|
+
height: el.hasAttribute("height")
|
|
265
|
+
? parseInt(el.getAttribute("height") ?? "0") || undefined
|
|
266
|
+
: undefined,
|
|
267
|
+
});
|
|
268
|
+
case "pre": {
|
|
269
|
+
const codeEl = el.querySelector("code");
|
|
270
|
+
const text = (codeEl ?? el).textContent ?? "";
|
|
271
|
+
const className = codeEl?.className ?? el.className;
|
|
272
|
+
const langMatch = className.match(/language-(\w+)/);
|
|
273
|
+
return createNode({
|
|
274
|
+
type: "code",
|
|
275
|
+
language: langMatch?.[1] ?? undefined,
|
|
276
|
+
value: text,
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
case "code":
|
|
280
|
+
if (el.parentElement?.tagName.toLowerCase() === "pre")
|
|
281
|
+
return null;
|
|
282
|
+
return createNode({
|
|
283
|
+
type: "inline-code",
|
|
284
|
+
value: el.textContent ?? "",
|
|
285
|
+
});
|
|
286
|
+
case "strong":
|
|
287
|
+
case "b":
|
|
288
|
+
return createNode({
|
|
289
|
+
type: "strong",
|
|
290
|
+
children: processChildNodes(Array.from(el.childNodes)),
|
|
291
|
+
});
|
|
292
|
+
case "em":
|
|
293
|
+
case "i":
|
|
294
|
+
return createNode({
|
|
295
|
+
type: "emphasis",
|
|
296
|
+
children: processChildNodes(Array.from(el.childNodes)),
|
|
297
|
+
});
|
|
298
|
+
case "br":
|
|
299
|
+
return createNode({ type: "text", value: "\n" });
|
|
300
|
+
case "hr":
|
|
301
|
+
return createNode({ type: "thematic-break" });
|
|
302
|
+
case "blockquote":
|
|
303
|
+
return createNode({
|
|
304
|
+
type: "blockquote",
|
|
305
|
+
children: processChildNodes(Array.from(el.childNodes)),
|
|
306
|
+
});
|
|
307
|
+
case "div":
|
|
308
|
+
case "section":
|
|
309
|
+
case "article":
|
|
310
|
+
case "aside":
|
|
311
|
+
case "figure":
|
|
312
|
+
case "figcaption":
|
|
313
|
+
case "span":
|
|
314
|
+
case "header":
|
|
315
|
+
case "footer":
|
|
316
|
+
case "nav":
|
|
317
|
+
return processChildNodes(Array.from(el.childNodes));
|
|
318
|
+
default:
|
|
319
|
+
return processChildNodes(Array.from(el.childNodes));
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Processes a table element, handling thead/tbody/tfoot sections.
|
|
324
|
+
*
|
|
325
|
+
* @param el - The table DOM element
|
|
326
|
+
* @returns A TableNode with processed rows
|
|
327
|
+
*/
|
|
328
|
+
function processTableElement(el) {
|
|
329
|
+
const rows = [];
|
|
330
|
+
let caption;
|
|
331
|
+
const captionEl = el.querySelector("caption");
|
|
332
|
+
if (captionEl) {
|
|
333
|
+
caption = captionEl.textContent?.trim() || undefined;
|
|
334
|
+
}
|
|
335
|
+
const thead = el.querySelector("thead");
|
|
336
|
+
const tbody = el.querySelector("tbody");
|
|
337
|
+
const tfoot = el.querySelector("tfoot");
|
|
338
|
+
if (thead || tbody || tfoot) {
|
|
339
|
+
const sections = [thead, tbody, tfoot].filter(Boolean);
|
|
340
|
+
for (const section of sections) {
|
|
341
|
+
for (const tr of Array.from(section.querySelectorAll("tr"))) {
|
|
342
|
+
rows.push(processTableRowElement(tr));
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
for (const tr of Array.from(el.querySelectorAll("tr"))) {
|
|
348
|
+
rows.push(processTableRowElement(tr));
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
return createNode({ type: "table", children: rows, caption });
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Processes a table row element into a TableRowNode.
|
|
355
|
+
*
|
|
356
|
+
* @param tr - The table row DOM element
|
|
357
|
+
* @returns A TableRowNode with cells
|
|
358
|
+
*/
|
|
359
|
+
function processTableRowElement(tr) {
|
|
360
|
+
const cells = [];
|
|
361
|
+
const cellEls = tr.querySelectorAll("td, th");
|
|
362
|
+
for (const cellEl of Array.from(cellEls)) {
|
|
363
|
+
cells.push(createNode({
|
|
364
|
+
type: "table-cell",
|
|
365
|
+
children: processChildNodes(Array.from(cellEl.childNodes)),
|
|
366
|
+
colspan: cellEl.hasAttribute("colspan")
|
|
367
|
+
? parseInt(cellEl.getAttribute("colspan") ?? "1")
|
|
368
|
+
: undefined,
|
|
369
|
+
rowspan: cellEl.hasAttribute("rowspan")
|
|
370
|
+
? parseInt(cellEl.getAttribute("rowspan") ?? "1")
|
|
371
|
+
: undefined,
|
|
372
|
+
}));
|
|
373
|
+
}
|
|
374
|
+
return createNode({
|
|
375
|
+
type: "table-row",
|
|
376
|
+
children: cells,
|
|
377
|
+
isHeader: tr.querySelector("th") !== null,
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Processes the direct `<li>` children of a list element.
|
|
382
|
+
*
|
|
383
|
+
* @param listEl - The list DOM element (ul or ol)
|
|
384
|
+
* @returns An array of ListItemNode
|
|
385
|
+
*/
|
|
386
|
+
function processListItems(listEl) {
|
|
387
|
+
const items = [];
|
|
388
|
+
for (const li of Array.from(listEl.querySelectorAll(":scope > li"))) {
|
|
389
|
+
items.push(createNode({
|
|
390
|
+
type: "list-item",
|
|
391
|
+
children: processChildNodes(Array.from(li.childNodes)),
|
|
392
|
+
}));
|
|
393
|
+
}
|
|
394
|
+
return items;
|
|
395
|
+
}
|
|
396
|
+
// ─── Markdown Renderer ─────────────────────────────────────────────────────────
|
|
397
|
+
/**
|
|
398
|
+
* Renders an array of AST nodes into a Markdown string.
|
|
399
|
+
* This is the local renderMarkdown helper for the EPUB converter.
|
|
400
|
+
*
|
|
401
|
+
* @param nodes - The AST nodes to render
|
|
402
|
+
* @returns The rendered Markdown string
|
|
403
|
+
*/
|
|
404
|
+
function renderMarkdown(nodes) {
|
|
405
|
+
const parts = [];
|
|
406
|
+
for (const node of nodes) {
|
|
407
|
+
parts.push(renderNode(node));
|
|
408
|
+
}
|
|
409
|
+
return parts.join("\n\n").replace(/\n{3,}/g, "\n\n").trim();
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Renders a single AST node into its Markdown representation.
|
|
413
|
+
*
|
|
414
|
+
* @param node - The AST node to render
|
|
415
|
+
* @returns The Markdown string for this node
|
|
416
|
+
*/
|
|
417
|
+
function renderNode(node) {
|
|
418
|
+
switch (node.type) {
|
|
419
|
+
case "heading": {
|
|
420
|
+
const n = node;
|
|
421
|
+
const prefix = "#".repeat(n.level);
|
|
422
|
+
return `${prefix} ${renderNodes(n.children)}`;
|
|
423
|
+
}
|
|
424
|
+
case "paragraph": {
|
|
425
|
+
const n = node;
|
|
426
|
+
return renderNodes(n.children);
|
|
427
|
+
}
|
|
428
|
+
case "table": {
|
|
429
|
+
return renderTable(node);
|
|
430
|
+
}
|
|
431
|
+
case "list": {
|
|
432
|
+
const n = node;
|
|
433
|
+
return n.children
|
|
434
|
+
.map((item, i) => {
|
|
435
|
+
const bullet = n.ordered ? `${(n.start ?? 1) + i}. ` : "- ";
|
|
436
|
+
return `${bullet}${renderNodes(item.children)}`;
|
|
437
|
+
})
|
|
438
|
+
.join("\n");
|
|
439
|
+
}
|
|
440
|
+
case "list-item": {
|
|
441
|
+
const n = node;
|
|
442
|
+
return renderNodes(n.children);
|
|
443
|
+
}
|
|
444
|
+
case "link": {
|
|
445
|
+
const n = node;
|
|
446
|
+
const text = renderNodes(n.children);
|
|
447
|
+
return n.title
|
|
448
|
+
? `[${text}](${n.href} "${n.title}")`
|
|
449
|
+
: `[${text}](${n.href})`;
|
|
450
|
+
}
|
|
451
|
+
case "image": {
|
|
452
|
+
const n = node;
|
|
453
|
+
return ``;
|
|
454
|
+
}
|
|
455
|
+
case "code": {
|
|
456
|
+
const n = node;
|
|
457
|
+
return "```" + (n.language ?? "") + "\n" + n.value + "\n```";
|
|
458
|
+
}
|
|
459
|
+
case "inline-code": {
|
|
460
|
+
const n = node;
|
|
461
|
+
return `\`${n.value}\``;
|
|
462
|
+
}
|
|
463
|
+
case "strong": {
|
|
464
|
+
const n = node;
|
|
465
|
+
return `**${renderNodes(n.children)}**`;
|
|
466
|
+
}
|
|
467
|
+
case "emphasis": {
|
|
468
|
+
const n = node;
|
|
469
|
+
return `*${renderNodes(n.children)}*`;
|
|
470
|
+
}
|
|
471
|
+
case "blockquote": {
|
|
472
|
+
const n = node;
|
|
473
|
+
const content = renderNodes(n.children);
|
|
474
|
+
return content
|
|
475
|
+
.split("\n")
|
|
476
|
+
.map((line) => `> ${line}`)
|
|
477
|
+
.join("\n");
|
|
478
|
+
}
|
|
479
|
+
case "text": {
|
|
480
|
+
const n = node;
|
|
481
|
+
return n.value;
|
|
482
|
+
}
|
|
483
|
+
case "thematic-break":
|
|
484
|
+
return "---";
|
|
485
|
+
default:
|
|
486
|
+
if ("children" in node && Array.isArray(node.children)) {
|
|
487
|
+
return renderNodes(node.children);
|
|
488
|
+
}
|
|
489
|
+
return "";
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Renders a table node into a Markdown table string.
|
|
494
|
+
*
|
|
495
|
+
* @param table - The TableNode to render
|
|
496
|
+
* @returns The Markdown table string
|
|
497
|
+
*/
|
|
498
|
+
function renderTable(table) {
|
|
499
|
+
if (table.children.length === 0)
|
|
500
|
+
return "";
|
|
501
|
+
let lines = [];
|
|
502
|
+
if (table.caption) {
|
|
503
|
+
lines.push(`*${table.caption}*`);
|
|
504
|
+
lines.push("");
|
|
505
|
+
}
|
|
506
|
+
const rows = table.children;
|
|
507
|
+
const colCount = rows[0]?.children.length ?? 0;
|
|
508
|
+
const colWidths = new Array(colCount).fill(3);
|
|
509
|
+
const cellTexts = rows.map((row) => row.children.map((cell) => renderNodes(cell.children)));
|
|
510
|
+
for (const row of cellTexts) {
|
|
511
|
+
for (let i = 0; i < row.length; i++) {
|
|
512
|
+
colWidths[i] = Math.max(colWidths[i], row[i].length);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
for (let r = 0; r < cellTexts.length; r++) {
|
|
516
|
+
const cells = cellTexts[r];
|
|
517
|
+
const line = "| " + cells.map((c, i) => c.padEnd(colWidths[i])).join(" | ") + " |";
|
|
518
|
+
lines.push(line);
|
|
519
|
+
if (r === 0) {
|
|
520
|
+
lines.push("| " + colWidths.map((w) => "-".repeat(w)).join(" | ") + " |");
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
return lines.join("\n");
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Recursively renders an array of AST nodes into a single string.
|
|
527
|
+
*
|
|
528
|
+
* @param nodes - The AST nodes to render
|
|
529
|
+
* @returns The concatenated rendered output
|
|
530
|
+
*/
|
|
531
|
+
function renderNodes(nodes) {
|
|
532
|
+
return nodes.map((n) => renderNode(n)).join("");
|
|
533
|
+
}
|
|
534
|
+
// ─── EpubConverter ─────────────────────────────────────────────────────────────
|
|
535
|
+
/**
|
|
536
|
+
* Converts EPUB e-book files into AST and Markdown output.
|
|
537
|
+
*
|
|
538
|
+
* Key features:
|
|
539
|
+
* - Parses `META-INF/container.xml` to locate the OPF file
|
|
540
|
+
* - Extracts metadata (title, creator, language, etc.) from the OPF
|
|
541
|
+
* - Reads content files in SPINE ORDER (not alphabetical)
|
|
542
|
+
* - Recursively traverses XHTML content without `document.createTreeWalker`
|
|
543
|
+
* - Produces a complete DocumentNode AST with all content in correct reading order
|
|
544
|
+
* - Renders headings, paragraphs, lists, tables, links, images, and code blocks
|
|
545
|
+
*
|
|
546
|
+
* @example
|
|
547
|
+
* ```ts
|
|
548
|
+
* const converter = new EpubConverter();
|
|
549
|
+
* const result = await converter.convert({ data: epubBuffer });
|
|
550
|
+
* console.log(result.ast); // DocumentNode AST
|
|
551
|
+
* console.log(result.markdown); // Rendered Markdown
|
|
552
|
+
* ```
|
|
553
|
+
*/
|
|
554
|
+
export class EpubConverter {
|
|
555
|
+
id = "epub";
|
|
556
|
+
supportedMimeTypes = ["application/epub+zip"];
|
|
557
|
+
supportedExtensions = [".epub"];
|
|
558
|
+
/**
|
|
559
|
+
* Checks whether this converter can handle the given input.
|
|
560
|
+
* Validates MIME type, file extension, and ZIP magic bytes.
|
|
561
|
+
*
|
|
562
|
+
* @param input - The conversion input to check
|
|
563
|
+
* @returns True if this converter can process the input
|
|
564
|
+
*/
|
|
565
|
+
async canConvert(input) {
|
|
566
|
+
if (input.mimeType && this.supportedMimeTypes.includes(input.mimeType)) {
|
|
567
|
+
return true;
|
|
568
|
+
}
|
|
569
|
+
if (input.fileName) {
|
|
570
|
+
const ext = input.fileName
|
|
571
|
+
.slice(input.fileName.lastIndexOf("."))
|
|
572
|
+
.toLowerCase();
|
|
573
|
+
if (this.supportedExtensions.includes(ext)) {
|
|
574
|
+
return true;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
try {
|
|
578
|
+
const data = await readInputData(input.data);
|
|
579
|
+
if (data.length >= 4) {
|
|
580
|
+
const isZip = data[0] === 0x50 &&
|
|
581
|
+
data[1] === 0x4b &&
|
|
582
|
+
data[2] === 0x03 &&
|
|
583
|
+
data[3] === 0x04;
|
|
584
|
+
if (isZip)
|
|
585
|
+
return true;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
catch {
|
|
589
|
+
return false;
|
|
590
|
+
}
|
|
591
|
+
return false;
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* Converts an EPUB file into a ConversionResult with AST and Markdown.
|
|
595
|
+
*
|
|
596
|
+
* Processing steps:
|
|
597
|
+
* 1. Parse the ZIP archive
|
|
598
|
+
* 2. Read `META-INF/container.xml` to find the OPF path
|
|
599
|
+
* 3. Parse the OPF for metadata, manifest, and spine
|
|
600
|
+
* 4. Read XHTML files in spine order
|
|
601
|
+
* 5. Parse each XHTML into AST nodes
|
|
602
|
+
* 6. Build the complete document AST and render to Markdown
|
|
603
|
+
*
|
|
604
|
+
* @param input - The EPUB file as Uint8Array, ArrayBuffer, Blob, or string
|
|
605
|
+
* @returns A ConversionResult with the document AST, Markdown, and metadata
|
|
606
|
+
*/
|
|
607
|
+
async convert(input) {
|
|
608
|
+
const startTime = performance.now();
|
|
609
|
+
const data = await readInputData(input.data);
|
|
610
|
+
const zip = await JSZip.loadAsync(data);
|
|
611
|
+
// Step 1: Find OPF path from container.xml
|
|
612
|
+
const opfPath = await getOpfPathFromContainer(zip);
|
|
613
|
+
// Step 2: Parse OPF for metadata, manifest, spine
|
|
614
|
+
const opf = await parseOpf(zip, opfPath);
|
|
615
|
+
// Step 3: Identify spine content items (filter to XHTML)
|
|
616
|
+
const spineContentItems = [];
|
|
617
|
+
for (const spineRef of opf.spine) {
|
|
618
|
+
const item = opf.manifest.get(spineRef.idref);
|
|
619
|
+
if (item) {
|
|
620
|
+
const ext = item.href.substring(item.href.lastIndexOf(".")).toLowerCase();
|
|
621
|
+
if (XHTML_EXTENSIONS.some((xhtmlExt) => ext === xhtmlExt)) {
|
|
622
|
+
spineContentItems.push(item);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
// Step 4: Process each XHTML content file in spine order
|
|
627
|
+
const allChildren = [];
|
|
628
|
+
const headings = [];
|
|
629
|
+
for (const item of spineContentItems) {
|
|
630
|
+
const file = zip.file(item.href);
|
|
631
|
+
if (!file)
|
|
632
|
+
continue;
|
|
633
|
+
const content = await file.async("string");
|
|
634
|
+
const doc = await parseHTML(content);
|
|
635
|
+
const body = doc.body;
|
|
636
|
+
if (!body)
|
|
637
|
+
continue;
|
|
638
|
+
const chapterNodes = processChildNodes(Array.from(body.childNodes));
|
|
639
|
+
// Collect headings for the ConversionResult
|
|
640
|
+
for (const node of chapterNodes) {
|
|
641
|
+
if (node.type === "heading") {
|
|
642
|
+
const h = node;
|
|
643
|
+
headings.push({
|
|
644
|
+
level: h.level,
|
|
645
|
+
text: extractNodeText(h),
|
|
646
|
+
id: h.id,
|
|
647
|
+
});
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
allChildren.push(...chapterNodes);
|
|
651
|
+
}
|
|
652
|
+
// Step 5: Build the complete document node
|
|
653
|
+
const documentNode = createNode({
|
|
654
|
+
type: "document",
|
|
655
|
+
children: allChildren,
|
|
656
|
+
});
|
|
657
|
+
// Step 6: Render to Markdown
|
|
658
|
+
const markdown = renderMarkdown(allChildren);
|
|
659
|
+
// Step 7: Build metadata from OPF
|
|
660
|
+
const metadata = {
|
|
661
|
+
title: opf.metadata.title,
|
|
662
|
+
author: opf.metadata.creator,
|
|
663
|
+
language: opf.metadata.language,
|
|
664
|
+
description: opf.metadata.description,
|
|
665
|
+
createdAt: opf.metadata.date,
|
|
666
|
+
keywords: opf.metadata.subject && opf.metadata.subject.length > 0
|
|
667
|
+
? opf.metadata.subject
|
|
668
|
+
: undefined,
|
|
669
|
+
wordCount: markdown.split(/\s+/).filter(Boolean).length,
|
|
670
|
+
customProperties: {
|
|
671
|
+
identifier: opf.metadata.identifier,
|
|
672
|
+
publisher: opf.metadata.publisher,
|
|
673
|
+
rights: opf.metadata.rights,
|
|
674
|
+
...opf.metadata.custom,
|
|
675
|
+
},
|
|
676
|
+
};
|
|
677
|
+
const endTime = performance.now();
|
|
678
|
+
const stats = {
|
|
679
|
+
startTime,
|
|
680
|
+
endTime,
|
|
681
|
+
duration: endTime - startTime,
|
|
682
|
+
inputSize: data.length,
|
|
683
|
+
outputSize: new TextEncoder().encode(markdown).byteLength,
|
|
684
|
+
};
|
|
685
|
+
return {
|
|
686
|
+
markdown,
|
|
687
|
+
metadata,
|
|
688
|
+
assets: [],
|
|
689
|
+
tables: [],
|
|
690
|
+
images: [],
|
|
691
|
+
headings,
|
|
692
|
+
ast: documentNode,
|
|
693
|
+
format: "markdown",
|
|
694
|
+
converterId: this.id,
|
|
695
|
+
stats,
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
/**
|
|
700
|
+
* Extracts plain text from an AST node by recursively walking its children.
|
|
701
|
+
*
|
|
702
|
+
* @param node - The AST node to extract text from
|
|
703
|
+
* @returns The concatenated plain text content
|
|
704
|
+
*/
|
|
705
|
+
function extractNodeText(node) {
|
|
706
|
+
if (node.type === "text")
|
|
707
|
+
return node.value;
|
|
708
|
+
if (node.type === "inline-code")
|
|
709
|
+
return node.value;
|
|
710
|
+
if ("children" in node && Array.isArray(node.children)) {
|
|
711
|
+
return node.children.map((c) => extractNodeText(c)).join("");
|
|
712
|
+
}
|
|
713
|
+
return "";
|
|
714
|
+
}
|
|
715
|
+
//# sourceMappingURL=epub-converter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"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,SAAS;YAC7B,SAAS,EAAE,IAAI,CAAC,MAAM;YACtB,UAAU,EAAE,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,UAAU;SAC1D,CAAC;QAEF,OAAO;YACL,QAAQ;YACR,QAAQ;YACR,MAAM,EAAE,EAAE;YACV,MAAM,EAAE,EAAE;YACV,MAAM,EAAE,EAAE;YACV,QAAQ;YACR,GAAG,EAAE,YAAY;YACjB,MAAM,EAAE,UAAU;YAClB,WAAW,EAAE,IAAI,CAAC,EAAE;YACpB,KAAK;SACN,CAAC;IACJ,CAAC;CACF;AAED;;;;;GAKG;AACH,SAAS,eAAe,CAAC,IAAa;IACpC,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM;QAAE,OAAQ,IAAiB,CAAC,KAAK,CAAC;IAC1D,IAAI,IAAI,CAAC,IAAI,KAAK,aAAa;QAAE,OAAQ,IAAuB,CAAC,KAAK,CAAC;IACvE,IAAI,UAAU,IAAI,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QACvD,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@markitdownjs/epub",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "EPUB converter for MarkItDownJS",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"jszip": "^3.10.0",
|
|
21
|
+
"@markitdownjs/shared": "0.1.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"linkedom": "^0.18.12",
|
|
25
|
+
"typescript": "^5.5.0"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc --project tsconfig.json",
|
|
29
|
+
"dev": "tsc --watch --project tsconfig.json",
|
|
30
|
+
"typecheck": "tsc --noEmit",
|
|
31
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo"
|
|
32
|
+
}
|
|
33
|
+
}
|