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
This commit is contained in:
parent
48359919ec
commit
9a08cbbfc4
5 changed files with 61 additions and 2 deletions
|
|
@ -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.
|
||||
|
||||
|
|
|
|||
12
plugin/bootstrap.js
vendored
12
plugin/bootstrap.js
vendored
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue