From b94aff86bf4de9f6e2a2645d6e9c62a3e844c102 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 2 Feb 2013 12:38:43 +0530 Subject: [PATCH] Tweak Book: When rebuilding azw3 files handle tags that have name but not id attribute, these are apparently produced by kindlegen. Fixes #1112934 (links are borken in azw3 (KF8) when tweaking book) --- src/calibre/ebooks/mobi/writer8/main.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/calibre/ebooks/mobi/writer8/main.py b/src/calibre/ebooks/mobi/writer8/main.py index b1479ee7c3..47a27dd06c 100644 --- a/src/calibre/ebooks/mobi/writer8/main.py +++ b/src/calibre/ebooks/mobi/writer8/main.py @@ -241,6 +241,11 @@ class KF8Writer(object): j = 0 for tag in root.iterdescendants(etree.Element): id_ = tag.attrib.get('id', None) + if id_ is None: + # Can happen during tweaking + id_ = tag.attrib.get('name', None) + if id_ is not None: + tag.attrib['id'] = id_ if id_ is not None or barename(tag.tag).lower() in aid_able_tags: aid = aidbase + j tag.attrib['aid'] = to_base(aid, base=32)