Content server viewer: When exporting highlights as text include chapter titles

This commit is contained in:
Kovid Goyal 2022-11-14 11:04:59 +05:30
parent 9e58974ec9
commit 524f70ccec
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -605,8 +605,21 @@ def show_export_dialog(annotations_manager):
return return
as_markdown = fmt is 'markdown' as_markdown = fmt is 'markdown'
lines = v'[]' lines = v'[]'
def_chap = [_('Unknown chapter')]
chapter_groups = {}
chapters = v'[]'
for hl in all_highlights: 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') document.getElementById(ta_id).textContent = lines.join('\n')
def fmt_item(text, val): def fmt_item(text, val):