From 1249a155703f269e0050403e8daefbc1f9482f50 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 23 Feb 2012 13:32:25 +0530 Subject: [PATCH] MOBI Output: When the same anchor is present more than once in the input document, use the first occurence rather than the last one. Fixes #934031 (link destination is wrong in case of html -> mobi conversion) --- src/calibre/ebooks/mobi/writer2/serializer.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/calibre/ebooks/mobi/writer2/serializer.py b/src/calibre/ebooks/mobi/writer2/serializer.py index 5bf6b10d23..abcd68673e 100644 --- a/src/calibre/ebooks/mobi/writer2/serializer.py +++ b/src/calibre/ebooks/mobi/writer2/serializer.py @@ -306,7 +306,9 @@ class Serializer(object): if id_: href = '#'.join((item.href, id_)) offset = self.anchor_offset or buf.tell() - self.id_offsets[urlnormalize(href)] = offset + key = urlnormalize(href) + if key not in self.id_offsets: + self.id_offsets[urlnormalize(href)] = offset if self.anchor_offset is not None and \ tag == 'a' and not elem.attrib and \ not len(elem) and not elem.text: