From 524f70ccecb2bd901e0ab8d8bf3b809a53f4e475 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 14 Nov 2022 11:04:59 +0530 Subject: [PATCH] Content server viewer: When exporting highlights as text include chapter titles --- src/pyj/read_book/highlights.pyj | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/pyj/read_book/highlights.pyj b/src/pyj/read_book/highlights.pyj index 810939ae58..f1e9ea0f24 100644 --- a/src/pyj/read_book/highlights.pyj +++ b/src/pyj/read_book/highlights.pyj @@ -605,8 +605,21 @@ def show_export_dialog(annotations_manager): return as_markdown = fmt is 'markdown' lines = v'[]' + def_chap = [_('Unknown chapter')] + chapter_groups = {} + chapters = v'[]' for hl in all_highlights: - render_highlight_as_text(hl, lines, link_prefix, current_query, as_markdown=as_markdown) + toc_title = (hl['toc_family_titles'] or def_chap)[0] + if not chapter_groups[toc_title]: + chapter_groups[toc_title] = v'[]' + chapters.push(toc_title) + chapter_groups[toc_title].push(hl) + for chapter_title in chapters: + if chapters.length > 1: + lines.push('### ' + chapter_title) + lines.push('') + for hl in chapter_groups[chapter_title]: + render_highlight_as_text(hl, lines, link_prefix, current_query, as_markdown=as_markdown) document.getElementById(ta_id).textContent = lines.join('\n') def fmt_item(text, val):