From 058d58b4f2080f266cb558b00ce4bc0136f74cac Mon Sep 17 00:00:00 2001 From: Bailey Jennings Date: Mon, 11 May 2026 20:57:45 -0400 Subject: [PATCH] fix(kosync): populate chapter field on synced annotations (#4134) Annotations and bookmarks inserted into KOReader via the Readest sync plugin were missing the chapter field, which native KOReader highlights stamp at creation time. Downstream tools that group highlights by chapter (e.g. obsidian-koreader-highlights, KOReader's own Markdown exporter) treated these as orphans. Resolve the chapter title from the xpointer using the same TOC call that ReaderHighlight uses natively, and include it on both annotation and bookmark item tables. Closes #4133 --- apps/readest.koplugin/syncannotations.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apps/readest.koplugin/syncannotations.lua b/apps/readest.koplugin/syncannotations.lua index 50e1dad6..005563ca 100644 --- a/apps/readest.koplugin/syncannotations.lua +++ b/apps/readest.koplugin/syncannotations.lua @@ -300,6 +300,10 @@ function SyncAnnotations:pull(ui, settings, client, book_hash, meta_hash, dialog -- Resolve KOReader page number from xpointer local pageno = ui.document:getPageFromXPointer(xp0) or note.page + -- Resolve chapter title so downstream tools can group by chapter, + -- matching native KOReader highlight creation behavior. + local chapter = ui.toc and ui.toc:getTocTitleByPage(xp0) or nil + if chapter == "" then chapter = nil end if note_type == "bookmark" then if existing_bookmarks[xp0] then goto continue end @@ -309,6 +313,7 @@ function SyncAnnotations:pull(ui, settings, client, book_hash, meta_hash, dialog page = xp0, text = note.text or "", note = note.note or "", + chapter = chapter, pageno = pageno, datetime = datetime_str, datetime_updated = datetime_updated_str, @@ -335,6 +340,7 @@ function SyncAnnotations:pull(ui, settings, client, book_hash, meta_hash, dialog note = note.note or "", drawer = drawer, color = READEST_TO_KO_COLOR[note.color] or "yellow", + chapter = chapter, pageno = pageno, datetime = datetime_str, datetime_updated = datetime_updated_str,