Skip to content

Attach exported highlights to their original Reader documents - #37

Closed
Endle wants to merge 2 commits into
mainfrom
feat/reader-document-highlights
Closed

Endle wants to merge 2 commits into
mainfrom
feat/reader-document-highlights

Conversation

@Endle

@Endle Endle commented Sep 24, 2026 •

Copy link
Copy Markdown
Owner

Highlights exported from downloaded Reader articles currently become separate entries through the Readwise v2 API. This change sends them to Reader's POST /api/v3/save/ with the original document's parent_id and selected passage, so they attach to that document. Other books retain the existing v2 export.

Successful Reader highlight IDs and notes are persisted after each request. Repeated syncs skip unchanged passages, and note edits or removal update the existing highlight. The Reader request helper accepts 201, retains bounded 429 retries, and avoids automatically retrying a create request after an ambiguous network failure. If parsing or any export fails, sync stops before archive, cleanup, or reconciliation can remove local annotations.

The implementation separates HTTP/authentication/retries into readwisereader/api.lua and highlight payloads/history/note updates into readwisereader/highlights.lua. main.lua coordinates KOReader's UI, parsing, settings, and sync, and is 306 lines smaller than before this extraction. The modules receive explicit dependencies instead of the plugin object. API errors are presented by the plugin, token changes take effect on the next request, and each client owns its rate-limit session. Installation instructions now call out copying the entire plugin directory, including these modules.

Addresses #20, following the API update reported in this comment. API contract: Reader create/update documentation.

Validation:

  • 21 LuaJIT regression tests pass with KOReader and HTTP stubs: routing, payloads, saved history across restarts, note edits/removal, partial failures, rate-limit retries, malformed responses, cleanup protection, current-token authentication, safe read retries, error presentation, and independent rate-limit sessions.
  • Luacheck: zero warnings or errors across the plugin and tests.
  • LuaJIT syntax checks and git diff --check pass.
  • CI now runs the regression suite and lints the tests.

Live KOReader/Reader testing has not been performed. Before release, verify text anchoring for selections across paragraphs, styled text, and punctuation. Reader can reject selections that differ from its stored article text. Existing v2 highlights are not migrated; export tracking is local and keyed by document and exact passage. Identical passages share an export record, highlight text changes create a new highlight, and local deletions do not propagate. Resetting settings or losing a create response can allow a later export to be resent. These limits and the behavior of explicit manual archive/delete actions are documented in the README.

@Endle
Endle marked this pull request as draft September 24, 2026 01:57
@Kageetai

Copy link
Copy Markdown
Contributor

Hey, thanks for the change.
I just tested it on my device and it starts fine and all, but when I try to sync again after highlighting something, it always shows the "has been rejected" message. I tried with three different paragraphs.

@Kageetai

Copy link
Copy Markdown
Contributor

Alright, just tried with another passage from the same article and this time it worked. The highlight appeared correctly inside Readwise itself, even in the Reader app.
I will try more to see how often it might get rejected.

@Endle

Endle commented Sep 24, 2026

Copy link
Copy Markdown
Owner Author

Hi @Kageetai , thank you so much for your interest.

I'm so sorry that I haven't tested it on my own yet. I'll definitely test with real kindle before merging into master

@Endle
Endle force-pushed the feat/reader-document-highlights branch from 3816c67 to 7ac8f9b Compare September 26, 2026 19:05
@Endle
Endle changed the base branch from main to fix/reader-request-safety September 26, 2026 19:06
@Endle
Endle changed the base branch from fix/reader-request-safety to main September 26, 2026 19:10
@Endle
Endle force-pushed the feat/reader-document-highlights branch from 7ac8f9b to 3816c67 Compare September 26, 2026 19:10
@Endle

Endle commented Sep 26, 2026

Copy link
Copy Markdown
Owner Author

Closed. Replaced by #38, #39 and #41, a stacked split of this PR for easier review: #38 is the API module refactor, #39 has the request safety fixes, and #41 is the Reader highlight export. Further work on the rejected-highlight issue reported above will happen in #41.

@Endle Endle closed this Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants