From 0ed633752ad0848b96ccc897abee40f78e1358f7 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 11 Jun 2012 15:10:42 +0530 Subject: [PATCH] AZW3 Output: Handle the case of a link pointing to the last line of text in the document. Fixes #1011330 (cannot convert rtf to azw3) --- src/calibre/ebooks/mobi/writer8/skeleton.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/calibre/ebooks/mobi/writer8/skeleton.py b/src/calibre/ebooks/mobi/writer8/skeleton.py index ebdaab1672..7f79f12726 100644 --- a/src/calibre/ebooks/mobi/writer8/skeleton.py +++ b/src/calibre/ebooks/mobi/writer8/skeleton.py @@ -372,6 +372,11 @@ class Chunker(object): # the chunk immediately after pos_fid = (chunk.sequence_number, 0, offset) break + if chunk is self.chunk_table[-1]: + # This can happen for aids very close to the end of the the + # end of the text (https://bugs.launchpad.net/bugs/1011330) + pos_fid = (chunk.sequence_number, offset-chunk.insert_pos, + offset) if pos_fid is None: raise ValueError('Could not find chunk for aid: %r'% match.group(1))