Example #1
0
 def exported_data(self):
     cbd = get_current_book_data()
     link_prefix = library_id = None
     if 'calibre_library_id' in cbd:
         library_id = cbd['calibre_library_id']
         book_id = cbd['calibre_book_id']
         book_fmt = cbd['calibre_book_fmt']
     elif cbd.get('book_library_details'):
         bld = cbd['book_library_details']
         book_id = bld['book_id']
         book_fmt = bld['fmt'].upper()
         library_id = bld['library_id']
     if library_id:
         library_id = '_hex_-' + library_id.encode('utf-8').hex()
         link_prefix = f'calibre://show-book/{library_id}/{book_id}/{book_fmt}?open_at='
     fmt = self.export_format.currentData()
     if fmt == 'calibre_highlights':
         return json.dumps({
             'version': 1,
             'type': 'calibre_highlights',
             'highlights': self.annotations,
         }, ensure_ascii=False, sort_keys=True, indent=2)
     lines = []
     as_markdown = fmt == 'md'
     for hl in self.annotations:
         render_highlight_as_text(hl, lines, as_markdown=as_markdown, link_prefix=link_prefix)
     return '\n'.join(lines).strip()
Example #2
0
 def exported_data(self):
     fmt = self.export_format.currentData()
     if fmt == 'calibre_highlights':
         return json.dumps(
             {
                 'version': 1,
                 'type': 'calibre_highlights',
                 'highlights': self.annotations,
             },
             ensure_ascii=False,
             sort_keys=True,
             indent=2)
     lines = []
     as_markdown = fmt == 'md'
     link_prefix = link_prefix_for_location_links()
     chapter_groups = {}
     def_chap = (_('Unknown chapter'), )
     for a in self.annotations:
         toc_titles = a.get('toc_family_titles', def_chap)
         chapter_groups.setdefault(toc_titles[0], []).append(a)
     for chapter, group in chapter_groups.items():
         if len(chapter_groups) > 1:
             lines.append('### ' + chapter)
             lines.append('')
         for hl in group:
             render_highlight_as_text(hl,
                                      lines,
                                      as_markdown=as_markdown,
                                      link_prefix=link_prefix)
     return '\n'.join(lines).strip()
Example #3
0
 def exported_data(self):
     if self.export_format.currentData() == 'calibre_highlights':
         return json.dumps({
             'version': 1,
             'type': 'calibre_highlights',
             'highlights': self.annotations,
         }, ensure_ascii=False, sort_keys=True, indent=2)
     lines = []
     for hl in self.annotations:
         render_highlight_as_text(hl, lines)
     return '\n'.join(lines).strip()
Example #4
0
 def exported_data(self):
     fmt = self.export_format.currentData()
     if fmt == 'calibre_highlights':
         return json.dumps(
             {
                 'version': 1,
                 'type': 'calibre_highlights',
                 'highlights': self.annotations,
             },
             ensure_ascii=False,
             sort_keys=True,
             indent=2)
     lines = []
     as_markdown = fmt == 'md'
     link_prefix = link_prefix_for_location_links()
     for hl in self.annotations:
         render_highlight_as_text(hl,
                                  lines,
                                  as_markdown=as_markdown,
                                  link_prefix=link_prefix)
     return '\n'.join(lines).strip()