feat(docx): Word (.docx) support via mammoth (lazy npm dependency)

makeDocxBook: the docx blob goes straight to mammoth.convertToHtml
(mammoth unzips internally; the browser entry takes {arrayBuffer}, the
node entry {buffer}). Converted HTML is sectioned at block-element
boundaries into ~150KB chunks (string-level — no DOMParser), giving a
Part N TOC; images inline as data URIs by default.

makeBook: zip files whose entries contain word/document.xml route to
the docx branch before the EPUB fallback (previously they died inside
new EPUB(...) on the missing container.xml).

mammoth is the fork's first runtime dependency: updates and security
fixes flow via semver; the browser-field mappings swap its node unzip
for the browser one; the dynamic import keeps it out of every other
format's path.
This commit is contained in:
John O'Keefe committed 2026-10-01 14:17:38 -04:00
1 parent cd2fbf278e
commit 8e1d5fc8d6
5 files changed
+308 -10

No files matched your search

-4
View File
@@ -36,10 +36,6 @@ export const makeTextBook = async file => {
if (cur.length) chunks.push(cur)
const urls = new Map()
const makeHTML = paras => `<!DOCTYPE html><html><head><meta charset="utf-8">`
+ `</head><body>`
+ paras.map(p => `<p>${escapeHTML(p)}</p>`).join('\n')
+ `</body></html>`
const load = i => {
if (!urls.has(i)) {
const html = chunks[i].map(p => `<p>${escapeHTML(p)}</p>`).join('\n')