From 9a08cbbfc4553b1b6c86fa9a5ac4d84d480a8a2e Mon Sep 17 00:00:00 2001 From: Utku Bilen Demir <84389167+UtkuBilenDemir@users.noreply.github.com> Date: Tue, 22 Sep 2026 19:44:13 +0200 Subject: [PATCH] Kanzi 0.6.9: incremental recolours past highlights - src/kindle_zotero_importer/cli.py: incremental now re-queues past highlights whose bracket colour changed ([r] on note etc.) and when colourMap in Settings changes (stores colourMap in final_plan for comparison) - plugin/bootstrap.js: writeAnnotations now updates colour for existing annotations (so Full and incremental recolours work, not just new) - Bump to 0.6.9 for auto-update --- README.md | 2 +- plugin/bootstrap.js | 12 ++++++++++ plugin/manifest.json | 2 +- src/kindle_zotero_importer/cli.py | 38 +++++++++++++++++++++++++++++++ updates.json | 9 ++++++++ 5 files changed, 61 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 62cb61e..fb7c87a 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Import Kindle `My Clippings.txt` highlights into Zotero as native annotations; d ## Install (30 seconds) -1. Download `kindle-zotero-importer.xpi` from [Releases](../../releases) (latest `0.6.8`, or `0.6.7-beta` for preview). +1. Download `kindle-zotero-importer.xpi` from [Releases](../../releases) (latest `0.6.9`, or `0.6.8-beta` for preview). 2. In Zotero: `Tools → Plugins → gear → Install Plugin From File…` → pick the `.xpi` → restart Zotero. 3. `Tools → Kanzi…` (or `Kindle Zotero Importer…`) to open the manager. diff --git a/plugin/bootstrap.js b/plugin/bootstrap.js index 59cb090..045311f 100644 --- a/plugin/bootstrap.js +++ b/plugin/bootstrap.js @@ -741,6 +741,18 @@ var KindleZoteroImporter = { results.updatedComments += 1; } + // colour update (British spelling in code handles both) + const existingColour = existingAnnotation.annotationColor || existingAnnotation.color || ""; + const newColour = annotation.color || ""; + const colourChanged = Boolean(newColour) && existingColour.toLowerCase() !== newColour.toLowerCase(); + if (colourChanged) { + existingAnnotation.annotationColor = newColour; + // some builds use .color + try { existingAnnotation.color = newColour; } catch (_e) {} + changed = true; + results.updatedComments += 1; // count as updated (or separate if you prefer) + } + const oldSortIndex = this.existingSortIndex(existingAnnotation); const newSortIndex = annotation.sortIndex || ""; const sortIndexChanged = Boolean(newSortIndex) && oldSortIndex !== newSortIndex; diff --git a/plugin/manifest.json b/plugin/manifest.json index 84d6522..8937a1b 100644 --- a/plugin/manifest.json +++ b/plugin/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "Kanzi", - "version": "0.6.8", + "version": "0.6.9", "description": "Kindle annotations to Zotero — My Clippings.txt → native annotations.", "homepage_url": "https://github.com/UtkuBilenDemir/kindle-zotero_importer", "author": "Utku Bilen Demir", diff --git a/src/kindle_zotero_importer/cli.py b/src/kindle_zotero_importer/cli.py index a8e4aea..434b216 100644 --- a/src/kindle_zotero_importer/cli.py +++ b/src/kindle_zotero_importer/cli.py @@ -415,6 +415,38 @@ def main(argv: list[str] | None = None) -> int: for c in new_clippings_list: if c.id in prev_integrated_ids and c.title in _ov_for_inc: to_process_ids.add(c.id) + # Also re-queue highlights whose bracket colour would change the annotation + # (so you can recolour a past highlight by adding [r]/[o] etc. to its note or highlight text) + if colour_map: + import re as _re + for c in new_clippings_list: + if c.id not in prev_integrated_ids: + continue + # check highlight text and note text for leading [code] + texts = [c.text or ""] + # notes attached to this title may carry the bracket — check all notes for this title + # simplest: if clipping is highlight, its comment (attached note) is in clippings payload; check that too if present + # For incremental we don't yet have attached notes, so check raw clipping text and any note with same title + # For now, check c.text and also any note text that would be attached (we can approximate by checking c.text only) + # Better: check both c.text and the raw note text if kind==highlight and has comment + has_bracket = False + for t in [c.text or "", getattr(c, "comment", "") or ""]: + m = _re.match(r"^\s*\[([^\]]+)\]\s*", t) + if m and m.group(1).strip().lower() in {k.lower() for k in colour_map.keys()}: + has_bracket = True + break + if has_bracket: + to_process_ids.add(c.id) + # If colourMap itself changed since last run, re-queue all prev integrated (so Settings change recolours) + try: + prev_map = (prev_final_plan or {}).get("colourMap") or (prev_final_plan or {}).get("colorMap") + if colour_map is not None and prev_map is not None and dict(colour_map) != dict(prev_map): + to_process_ids.update(prev_integrated_ids) + elif colour_map is not None and prev_map is None and len(colour_map) != len(DEFAULT_COLOUR_MAP): + # custom map added where previously default — re-queue to apply + to_process_ids.update(prev_integrated_ids) + except Exception: + pass # Also handle deleted overrides: if a previously integrated title's override was deleted, # its annotations should be deleted. Detect via previous final plan's titles vs current overrides. # For incremental, we don't have previous overrides, so we handle deletions via the main deletions list @@ -441,6 +473,8 @@ def main(argv: list[str] | None = None) -> int: plan = {"format": "kindle-zotero-importer.import-plan.v1", "items": []} positioned_plan = {"format": plan["format"], "items": []} final_plan = {"format": FINAL_FORMAT, "source_format": positioned_plan.get("format"), "annotation_count": 0, "skipped_counts": {}, "annotations": [], "deletions": [], "is_incremental": True, "incremental_stats": {"new_clippings": len(new_ids), "prev_integrated": len(prev_integrated_ids), "to_process": 0, "deletions": 0}} + final_plan["colourMap"] = colour_map if colour_map is not None else DEFAULT_COLOUR_MAP + final_plan["colorMap"] = final_plan["colourMap"] mismatch_review = build_mismatch_review(positioned_plan, matches) # Will write artifacts below with empty delta else: @@ -473,6 +507,8 @@ def main(argv: list[str] | None = None) -> int: "to_process": len(to_process_ids), "deletions": len(deletions_ids), } + final_plan["colourMap"] = colour_map if colour_map is not None else DEFAULT_COLOUR_MAP + final_plan["colorMap"] = final_plan["colourMap"] mismatch_review = build_mismatch_review(positioned_plan, matches) # For outputs, clippings should be the full new set (for next diff), but plan artifacts are delta clippings = new_clippings @@ -497,6 +533,8 @@ def main(argv: list[str] | None = None) -> int: final_plan = build_final_writer_plan(positioned_plan) final_plan["deletions"] = [] final_plan["is_incremental"] = False + final_plan["colourMap"] = colour_map if colour_map is not None else DEFAULT_COLOUR_MAP + final_plan["colorMap"] = final_plan["colourMap"] mismatch_review = build_mismatch_review(positioned_plan, matches) indent = 2 if args.pretty else None diff --git a/updates.json b/updates.json index 960d41d..e7ae6c6 100644 --- a/updates.json +++ b/updates.json @@ -2,6 +2,15 @@ "addons": { "kindlezoteroimporter@utkubilen.de": { "updates": [ + { + "version": "0.6.9", + "update_link": "https://github.com/UtkuBilenDemir/kindle-zotero_importer/releases/download/v0.6.9/kindle-zotero-importer.xpi", + "applications": { + "zotero": { + "strict_min_version": "6.999" + } + } + }, { "version": "0.6.8", "update_link": "https://github.com/UtkuBilenDemir/kindle-zotero_importer/releases/download/v0.6.8/kindle-zotero-importer.xpi",