From 9763120b3d50ff5c3e03bc6005701bfafc85a8a5 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 25 Oct 2023 19:06:00 +0530 Subject: [PATCH] E-book viewer: Add support for HTML image maps. Fixes #2040487 [Image hotspots using map tag results in error message](https://bugs.launchpad.net/calibre/+bug/2040487) --- src/calibre/srv/render_book.py | 4 ++-- src/pyj/read_book/iframe.pyj | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/calibre/srv/render_book.py b/src/calibre/srv/render_book.py index a1e12171ff..488e6d41da 100644 --- a/src/calibre/srv/render_book.py +++ b/src/calibre/srv/render_book.py @@ -432,7 +432,7 @@ def transform_inline_styles(container, name, transform_sheet, transform_style): def transform_html(container, name, virtualize_resources, link_uid, link_to_map, virtualized_names): - link_xpath = XPath('//h:a[@href]') + link_xpath = XPath('//h:*[@href and (self::h:a or self::h:area)]') svg_link_xpath = XPath('//svg:a') img_xpath = XPath('//h:img[@src]') svg_img_xpath = XPath('//svg:image[@xl:href]') @@ -604,7 +604,7 @@ def worker_main(): def virtualize_html(container, name, link_uid, link_to_map, virtualized_names): changed = set() - link_xpath = XPath('//h:a[@href]') + link_xpath = XPath('//h:*[@href and (self::h:a or self::h:area)]') svg_link_xpath = XPath('//svg:a') link_replacer = create_link_replacer(container, link_uid, changed) diff --git a/src/pyj/read_book/iframe.pyj b/src/pyj/read_book/iframe.pyj index 4bd699d854..526ba30dca 100644 --- a/src/pyj/read_book/iframe.pyj +++ b/src/pyj/read_book/iframe.pyj @@ -691,7 +691,7 @@ class IframeBoss: self.comm.send_message(action, data) def connect_links(self): - for a in document.body.querySelectorAll(f'a[{self.link_attr}]'): + for a in document.body.querySelectorAll(f'a[{self.link_attr}],area[{self.link_attr}]'): a.addEventListener('click', self.link_activated) if runtime.is_standalone_viewer: # links with a target get turned into requests to open a new window by Qt