Skip to content

Commit 8e6b107

Browse files
committed
feat: add title attribute to MagicEpub hotspot link elements
1 parent 60ad467 commit 8e6b107

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

accfix/ace_fix.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def ace_fix_mec(epub: Epub):
4141
html_tree = ElementTree(etree.fromstring(data))
4242
set_lang(html_tree, lang)
4343
fix_trn_links(html_tree)
44+
fix_hotspot_links_kf8(html_tree)
4445
data = etree.tostring(html_tree, xml_declaration=True, encoding="utf-8", pretty_print=True)
4546
epub.write(page_path, data)
4647
yield "All content pages fixed and updated"
@@ -127,6 +128,22 @@ def fix_trn_links(html_tree):
127128
return html_tree
128129

129130

131+
def fix_hotspot_links_kf8(html_tree):
132+
# type: (ElementTree) -> ElementTree
133+
"""Add required title attribute to MagicEpub hotspot link elements"""
134+
root = html_tree.getroot()
135+
namespaces = {
136+
"xhtml": "http://www.w3.org/1999/xhtml",
137+
"epub": "http://www.idpf.org/2007/ops",
138+
}
139+
hot_spot_divs = root.xpath('//xhtml:div[@class="hotspot"]', namespaces=namespaces)
140+
for div in hot_spot_divs:
141+
link = div.find(".//xhtml:a", namespaces=namespaces)
142+
if link is not None:
143+
link.set("title", "Link area")
144+
return html_tree
145+
146+
130147
if __name__ == "__main__":
131148
fp = r"../scratch/test1.epub"
132149
epb = Epub(fp, clone=True)

0 commit comments

Comments
 (0)