Skip to content

fix: handle missing annotationKey in newer Zotero annotation format#461

Open
yukiizumi3 wants to merge 1 commit intoPKM-er:masterfrom
yukiizumi3:fix/note-parser-annotation-key-compat
Open

fix: handle missing annotationKey in newer Zotero annotation format#461
yukiizumi3 wants to merge 1 commit intoPKM-er:masterfrom
yukiizumi3:fix/note-parser-annotation-key-compat

Conversation

@yukiizumi3
Copy link
Copy Markdown

Summary

  • Newer Zotero (7+) embeds annotation references in notes without the annotationKey field, using pageLabel + position instead
  • This caused the note parser to crash with: Unexpected annotation data: annotationKey must be defined
  • Fix makes annotationKey optional, preserves highlight text content, and generates page-level PDF links as fallback

Changes

format.ts

  • Made annotationKey optional in DataAnnotation schema
  • Added pageLabel and position as optional fields to accept the newer format

service.ts

  • Added highlightText and pageLabel fields to the annotations map
  • Store highlight text content and page label when processing annotations
  • Graceful fallback when annotationKey is missing: renders the highlight text with a page-level PDF link instead of crashing
  • No behavior change for older Zotero versions that still include annotationKey

Test plan

  • Create literature note for item with newer-format annotation references (no annotationKey)
  • Verify no crash, highlight text preserved, page links generated
  • Verify items with older format (with annotationKey) still work correctly

Newer versions of Zotero (7+) embed annotation references in notes
without the `annotationKey` field, using `pageLabel` + `position`
instead. This caused the note parser to crash with:
"Unexpected annotation data: annotationKey must be defined"

Changes:
- Make `annotationKey` optional in DataAnnotation schema, accept
  `pageLabel` and `position` fields from newer format
- Preserve highlight text content when annotationKey is missing
  instead of returning empty string
- Generate page-level PDF links as fallback when annotation-level
  links are unavailable
- Gracefully degrade without breaking existing behavior for older
  Zotero versions that still include annotationKey
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.

1 participant