From 673bcb3b2b2220a8ecc7a2f60dbf852eca421cee Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 15 Jul 2020 21:13:00 +0530 Subject: [PATCH] Improve formatting of notes in the browse details panel --- src/calibre/gui2/library/annotations.py | 26 +++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/calibre/gui2/library/annotations.py b/src/calibre/gui2/library/annotations.py index 83777ef601..b06137f289 100644 --- a/src/calibre/gui2/library/annotations.py +++ b/src/calibre/gui2/library/annotations.py @@ -395,15 +395,29 @@ class DetailsPanel(QWidget): a = prepare_string_for_xml paras = [] + + def p(text, tag='p'): + paras.append('<{0}>{1}'.format(tag, a(text))) + if annot['type'] == 'bookmark': - paras.append(a(annot['title'])) + p(annot['title']) elif annot['type'] == 'highlight': - paras.append(a(annot['highlighted_text'])) - paras.append(a(annot.get('notes') or '')) - - for para in paras: - annot_text += '
' + para + '
 
' + p(annot['highlighted_text']) + notes = annot.get('notes') + if notes: + p(_('Notes'), 'h4') + current_lines = [] + for line in notes.splitlines(): + if line: + current_lines.append(line) + else: + if current_lines: + p('\n'.join(current_lines)) + current_lines = [] + if current_lines: + p('\n'.join(current_lines)) + annot_text += '\n'.join(paras) date = QDateTime.fromString(annot['timestamp'], Qt.ISODate).toLocalTime().toString(Qt.SystemLocaleShortDate) text = '''

{title} [{book_format}]