Skip to content

Commit

Permalink
EPUB: Rewrite <object data> to <img src>
Browse files Browse the repository at this point in the history
  • Loading branch information
AbeJellinek committed Aug 29, 2024
1 parent dbf4bef commit f54b31f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion epubjs/epub.js
16 changes: 16 additions & 0 deletions src/dom/epub/lib/sanitize-and-render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/")) {
// <object data="..."> 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) {
Expand Down

0 comments on commit f54b31f

Please sign in to comment.