mirror of
https://github.com/john-okeefe/foliate-js.git
synced 2026-10-22 06:49:51 -04:00
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:
1 parent
cd2fbf278e
commit
8e1d5fc8d6
5 files changed
+308
-10
No files matched your search
@@ -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')
|
||||
|
||||
Reference in new issue
Block a user