diff --git a/src/calibre/gui2/viewer/annotations.py b/src/calibre/gui2/viewer/annotations.py index 16a1cf6476..81ce8c9904 100644 --- a/src/calibre/gui2/viewer/annotations.py +++ b/src/calibre/gui2/viewer/annotations.py @@ -59,11 +59,18 @@ def serialize_annotations(annots_map): return json_dumps(ans) +def split_lines(chunk, length=80): + pos = 0 + while pos < len(chunk): + yield chunk[pos:pos+length] + pos += length + + def save_annots_to_epub(path, serialized_annots): try: zf = open(path, 'r+b') except IOError: return with zf: - serialized_annots = EPUB_FILE_TYPE_MAGIC + as_base64_bytes(serialized_annots) + serialized_annots = EPUB_FILE_TYPE_MAGIC + b'\n'.join(split_lines(as_base64_bytes(serialized_annots))) safe_replace(zf, 'META-INF/calibre_bookmarks.txt', BytesIO(serialized_annots), add_missing=True) diff --git a/src/calibre/srv/render_book.py b/src/calibre/srv/render_book.py index 5fe91dff16..1cb34c89c3 100644 --- a/src/calibre/srv/render_book.py +++ b/src/calibre/srv/render_book.py @@ -560,15 +560,16 @@ def parse_annotations(raw): def get_stored_annotations(container): - from calibre.ebooks.oeb.iterator.bookmarks import parse_bookmarks - raw = container.bookmark_data or b'' + if not raw: + return if raw.startswith(EPUB_FILE_TYPE_MAGIC): - raw = raw[len(EPUB_FILE_TYPE_MAGIC):] + raw = raw[len(EPUB_FILE_TYPE_MAGIC):].replace(b'\n', b'') for annot in parse_annotations(from_base64_bytes(raw)): yield annot return + from calibre.ebooks.oeb.iterator.bookmarks import parse_bookmarks for bm in parse_bookmarks(raw): if bm['type'] == 'cfi' and isinstance(bm['pos'], unicode_type): spine_index = (1 + bm['spine']) * 2