Add book titles when exporting annots from the browse annots tool

This commit is contained in:
Kovid Goyal 2020-08-25 13:31:19 +05:30
parent 130b27219f
commit 5e53142d0c
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 15 additions and 7 deletions

View File

@ -106,13 +106,21 @@ class Export(Dialog):
'annotations': self.annotations,
}, ensure_ascii=False, sort_keys=True, indent=2)
lines = []
db = current_db()
bid_groups = {}
for a in self.annotations:
atype = a['type']
if atype == 'highlight':
render_highlight_as_text(a, lines)
elif atype == 'bookmark':
render_bookmark_as_text(a, lines)
return '\n'.join(lines)
bid_groups.setdefault(a['book_id'], []).append(a)
for book_id, group in bid_groups.items():
lines.append('## ' + db.field_for('title', book_id))
lines.append('')
for a in group:
atype = a['type']
if atype == 'highlight':
render_highlight_as_text(a, lines)
elif atype == 'bookmark':
render_bookmark_as_text(a, lines)
lines.append('')
return '\n'.join(lines).strip()
def render_notes(notes, tag='p'):

View File

@ -45,7 +45,7 @@ class Export(ExportBase):
lines = []
for hl in self.annotations:
render_highlight_as_text(hl, lines)
return '\n'.join(lines)
return '\n'.join(lines).strip()
class Highlights(QListWidget):