From f54b31fc5c7781b9351d631affda772742ba5a2a Mon Sep 17 00:00:00 2001 From: Abe Jellinek Date: Thu, 29 Aug 2024 13:37:37 -0400 Subject: [PATCH] EPUB: Rewrite to For https://github.com/sarabander/sicp --- epubjs/epub.js | 2 +- src/dom/epub/lib/sanitize-and-render.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/epubjs/epub.js b/epubjs/epub.js index a621d372..c8af9446 160000 --- a/epubjs/epub.js +++ b/epubjs/epub.js @@ -1 +1 @@ -Subproject commit a621d3727bc75ad7e49f2d70941dc969be65dd21 +Subproject commit c8af9446579aac722a0a86cb2bf44a5ee80100b4 diff --git a/src/dom/epub/lib/sanitize-and-render.ts b/src/dom/epub/lib/sanitize-and-render.ts index 1b9166ae..91c9e17f 100644 --- a/src/dom/epub/lib/sanitize-and-render.ts +++ b/src/dom/epub/lib/sanitize-and-render.ts @@ -51,6 +51,22 @@ export async function sanitizeAndRender(xhtml: string, options: { else if (elem.tagName == 'title') { toRemove.push(elem); } + else if (elem.tagName === 'object' + && elem.hasAttribute('data') + && elem.getAttribute("type")?.startsWith("image/")) { + // apparently can't display blob: SVGs in Firefox + let img = doc.createElement('img'); + for (let attr of elem.getAttributeNames()) { + if (attr === 'data' || attr === 'title') { + continue; + } + img.setAttribute(attr, elem.getAttribute(attr)!); + } + img.src = elem.getAttribute('data')!; + img.alt = elem.getAttribute('title') || elem.textContent || ''; + elem.replaceWith(img); + walker.currentNode = img; + } } for (let elem of toRemove) {