From 87ab6fa4485121f2faa593eb1739268ee85dff14 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 4 Apr 2023 10:35:30 +0530 Subject: [PATCH] E-book viewer: Fix images embedded inside svg tags not available for viewing in a popup --- src/calibre/srv/render_book.py | 5 +++++ src/pyj/read_book/extract.pyj | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/calibre/srv/render_book.py b/src/calibre/srv/render_book.py index 4512373f52..0b7e11fb47 100644 --- a/src/calibre/srv/render_book.py +++ b/src/calibre/srv/render_book.py @@ -347,6 +347,7 @@ def transform_html(container, name, virtualize_resources, link_uid, link_to_map, link_xpath = XPath('//h:a[@href]') svg_link_xpath = XPath('//svg:a') img_xpath = XPath('//h:img[@src]') + svg_img_xpath = XPath('//svg:image[@xl:href]') res_link_xpath = XPath('//h:link[@href]') root = container.parsed(name) changed_names = set() @@ -357,6 +358,10 @@ def transform_html(container, name, virtualize_resources, link_uid, link_to_map, img_name = container.href_to_name(img.get('src'), name) if img_name: img.set('data-calibre-src', img_name) + for img in svg_img_xpath(root): + img_name = container.href_to_name(img.get(XLINK('href')), name) + if img_name: + img.set('data-calibre-src', img_name) # Disable non-stylesheet link tags. This link will not be loaded by the # browser anyway and will causes the resource load check to hang diff --git a/src/pyj/read_book/extract.pyj b/src/pyj/read_book/extract.pyj index 5d3d0359b1..e5d853fa6c 100644 --- a/src/pyj/read_book/extract.pyj +++ b/src/pyj/read_book/extract.pyj @@ -10,9 +10,10 @@ def get_elements(x, y): nonlocal img_id_counter ans = {'link': None, 'img': None, 'highlight': None, 'crw': None} for elem in document.elementsFromPoint(x, y): - if elem.tagName.toLowerCase() is 'a' and elem.getAttribute('href') and not ans.link: + tl = elem.tagName.toLowerCase() + if tl is 'a' and elem.getAttribute('href') and not ans.link: ans.link = elem.getAttribute('href') - elif elem.tagName.toLowerCase() is 'img' and elem.getAttribute('data-calibre-src') and not ans.img: + elif (tl is 'img' or tl is 'image') and elem.getAttribute('data-calibre-src') and not ans.img: ans.img = elem.getAttribute('data-calibre-src') elif elem.dataset?.calibreRangeWrapper: ans.crw = elem.dataset.calibreRangeWrapper