diff --git a/src/pyj/read_book/highlights.pyj b/src/pyj/read_book/highlights.pyj index d9e72ef8f4..45def397ef 100644 --- a/src/pyj/read_book/highlights.pyj +++ b/src/pyj/read_book/highlights.pyj @@ -5,7 +5,7 @@ from __python__ import bound_methods, hash_literals from elementmaker import E from ajax import encode_query -from book_list.globals import get_session_data +from book_list.globals import get_session_data, get_current_query from book_list.theme import get_color from complete import create_search_bar from dom import add_extra_css, build_rule, clear, svgicon, unique_id @@ -525,13 +525,14 @@ def get_container(): return document.getElementById(get_container_id()) -def render_highlight_as_text(hl, lines, as_markdown=False, link_prefix=None): +def render_highlight_as_text(hl, lines, link_prefix, current_query, as_markdown=False): lines.push(hl.highlighted_text) date = Date(hl.timestamp).toLocaleString() - if as_markdown and link_prefix: + if as_markdown: cfi = hl.start_cfi spine_index = (1 + hl.spine_index) * 2 - link = link_prefix + encode_query({'open_at': f'epubcfi(/{spine_index}{cfi})'}) + current_query.bookpos = f'epubcfi(/{spine_index}{cfi})' + link = link_prefix + encode_query(current_query)[1:].replace(/\)/g, '%29') date = f'[{date}]({link})' lines.push(date) notes = hl.notes @@ -554,6 +555,12 @@ def show_export_dialog(annotations_manager): fmt = 'text' all_highlights = annotations_manager.all_highlights() ta_id = unique_id() + href = window.location.href + idx = href.indexOf('#') + href = href[:idx+1] + current_query = Object.assign({}, get_current_query()) + link_prefix = window.location.href + link_prefix = link_prefix[:link_prefix.indexOf('#') + 1] def update_text(): if fmt is 'calibre_annotations_collection': @@ -567,7 +574,7 @@ def show_export_dialog(annotations_manager): as_markdown = fmt is 'markdown' lines = v'[]' for hl in all_highlights: - render_highlight_as_text(hl, lines, as_markdown=as_markdown) + 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): @@ -625,7 +632,6 @@ def find(backwards): all_highlights.reverse() q = text.toLowerCase() for h in all_highlights: - console.log(h.dataset.title) if h.dataset.title.toLowerCase().indexOf(q) > -1 or h.dataset.notes.toLowerCase().indexOf(q) > -1: set_current_highlight_entry(h) h.scrollIntoView()