Skip to content

Commit 33982ab

Browse files
committed
Render KOReader ribbon page bookmarks as "Bookmarked"
KOReader's ribbon (corner-tap) page bookmarks live alongside text highlights in the same `annotations` array, distinguished by the absence of a `pos0`/`pos1` selection range. KOReader auto-fills the `text` field with "in <chapter>" for those rows so they render as something in its own UI. The plugin was passing that auto-text straight into the highlight renderer, producing blocks like: > in Chapter 4: Natural and Spiritual Freedom chapter:: Chapter 4: Natural and Spiritual Freedom page:: 360 instead of the canonical bookmark shape: > Bookmarked chapter:: Chapter 4: Natural and Spiritual Freedom page:: 360 Detect the missing selection range in the parser and clear `text` so the existing renderer's "empty text → page bookmark" path takes over. Same fix on the legacy `bookmarks` array; also dropped the wrong `b.notes` fallback that previously mirrored auto-text into `text`.
1 parent 9602abc commit 33982ab

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

src/sidecar.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function extractHighlights(raw: any): KoreaderHighlight[] {
132132
for (const a of annotations) {
133133
if (!a) continue
134134
out.push({
135-
text: stringOrUndefined(a.text) ?? '',
135+
text: isRibbonBookmark(a) ? '' : stringOrUndefined(a.text) ?? '',
136136
note: stringOrUndefined(a.note),
137137
page: a.pageno ?? a.page,
138138
chapter: stringOrUndefined(a.chapter),
@@ -150,7 +150,7 @@ function extractHighlights(raw: any): KoreaderHighlight[] {
150150
for (const b of bookmarks) {
151151
if (!b) continue
152152
out.push({
153-
text: stringOrUndefined(b.notes) ?? stringOrUndefined(b.text) ?? '',
153+
text: isRibbonBookmark(b) ? '' : stringOrUndefined(b.text) ?? '',
154154
note: undefined,
155155
page: b.page,
156156
chapter: stringOrUndefined(b.chapter),
@@ -162,6 +162,19 @@ function extractHighlights(raw: any): KoreaderHighlight[] {
162162
return out
163163
}
164164

165+
/**
166+
* KOReader's ribbon page-bookmarks live alongside text highlights in
167+
* the `annotations` (modern) and `bookmarks` (legacy) arrays. They have
168+
* no `pos0`/`pos1` selection range — those are present on every text
169+
* highlight — and KOReader auto-fills `text` with "in <chapter>" so the
170+
* row renders as something in its own UI. We detect the shape via the
171+
* absent selection range and discard the auto-text so the renderer's
172+
* "empty text → page bookmark" path can produce `> Bookmarked`.
173+
*/
174+
function isRibbonBookmark(a: any): boolean {
175+
return !stringOrUndefined(a?.pos0) && !stringOrUndefined(a?.pos1)
176+
}
177+
165178
function deriveHighlightId(a: any): string {
166179
// Compose a stable per-highlight key. KOReader doesn't ship a UUID, but
167180
// the (datetime, pos0, pos1) tuple is unique within a sidecar; falling back

0 commit comments

Comments
 (0)