Debian Codegraph @

src/pyj/read_book/extract.pyj

raw
1 # vim:fileencoding=utf-8
2 # License: GPL v3 Copyright: 2019, Kovid Goyal <kovid at kovidgoyal.net>
3 from __python__ import bound_methods, hash_literals
4
5 from read_book.globals import annot_id_uuid_map
6
7
8 def get_elements(x, y):
9 nonlocal img_id_counter
10 ans = {'link': None, 'img': None, 'highlight': None, 'crw': None}
11 for elem in document.elementsFromPoint(x, y):
12 tl = elem.tagName.toLowerCase()
13 if tl is 'a' and elem.getAttribute('href') and not ans.link:
14 ans.link = elem.getAttribute('href')
15 elif (tl is 'img' or tl is 'image') and elem.getAttribute('data-calibre-src') and not ans.img:
16 ans.img = elem.getAttribute('data-calibre-src')
17 elif elem.dataset?.calibreRangeWrapper:
18 ans.crw = elem.dataset.calibreRangeWrapper
19 annot_id = annot_id_uuid_map[ans.crw]
20 if annot_id:
21 ans.highlight = annot_id
22 return ans