Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: keep existing highlights and notes, and add sort by chapter progress #107

Merged
merged 10 commits into from
Jan 11, 2024

Conversation

rsletta
Copy link

@rsletta rsletta commented Apr 6, 2023

This PR adds support for keeping existing highlights and notes, and a new setting to sort highlights by chapter progress, rather than annotation creation date.

The implementation uses a simple approach using the existing files, rather than creating unnecessary complexity by introducing some sort of state management. It uses the bookmark id from the Kobo db as highlight markers. On transformation to markdown, the plugin checks to see if the highlight already exist, and if it does that, it injects the existing markdown, rather than the new. By using the bookmark id in the highlight marker, we are able to handle them as separate blocks. Using comments as highlight markers makes them invisible in read mode.

Tests are refactored to include the highlight markers, and a new test is introduced to test handling of existing highlights.

README is updated with information regarding the changes.

Fixes #91

@OGKevin
Copy link
Owner

OGKevin commented Apr 6, 2023

My Typos 😩 🙈
Thx for fixing them!


This is a nice solution, thanks for the PR!

A few questions:

  • What if a bookmark goes missing from the DB? I think it would be nice to at least mark the extracted note as stale/deleted. And the user can than decide what to do with it.
  • I need to check out the code and test, but are highlight markers visible in edit mode in Obsidian? Do you need to explicitly enable source mode? If this is the case, than I think we need to document this as well.
  • Is the same bookmark ID re-used by kobo if you update an existing highlight? If so, instead of re-using the existing content in the .md file, we might want to replace that with what has been extracted from the DB.

Based on the above, I suggest to create 2 markers, and inner marker and an outer marker:

%%START-c5b2637d-ddaf-4f15-9a81-dd701e0ad8fe%%
<user can type what they want here>
%%START-EXTRACED-BOOKMARK-c5b2637d-ddaf-4f15-9a81-dd701e0ad8fe%%
<text from db, 100% managed by plugin>
%%END-EXTRACED-BOOKMARK-c5b2637d-ddaf-4f15-9a81-dd701e0ad8fe%%
<user can type what they want here>
%%END-c5b2637d-ddaf-4f15-9a81-dd701e0ad8fe%%

This way

  1. We extract the whole block
  2. Keep the highlight up to date or mark as stale
  3. Still preserve user content

wdyt?

@OGKevin OGKevin added this to the 1.6.0 milestone Apr 6, 2023
@OGKevin OGKevin self-requested a review April 6, 2023 14:52
@rsletta
Copy link
Author

rsletta commented Apr 6, 2023

Thanks for the feedback.

The markers are visible in regular edit mode(Live preview).
image

I will investigate if the id is kept on edits, or if a new is created. I'll also see if I can find a good solution of handling it, and also the one regarding removed highlights. In the current implementation, a removed bookmark would mean it would be removed from the file. I'm not foreign to consider your suggestion. I'll get back to you when I have something. ☺️👍

@rsletta rsletta marked this pull request as draft April 6, 2023 16:57
@rsletta
Copy link
Author

rsletta commented Apr 13, 2023

Just a small update. IDs are kept across edits, so I need to consider that too. My initial thought is that we use the modified date to track modifications, and creation date to enable the sorting by date created. This will need a larger refactoring, but I have some ideas on how to do it. I hope I'll have an implementation ready some time in the coming month. 👍

@rsletta
Copy link
Author

rsletta commented Jun 1, 2023

Sorry about the slow progress. Between my job and family obligations, I haven't had the time or energy to work on this yet. I just wanted to give an update, so you don't think I've abandoned it. 🙄 Hopefully things will calm a bit down towards the summer, so I can get it done. 👍

@OGKevin
Copy link
Owner

OGKevin commented Jul 16, 2023

@rsletta anything change re your availability? No rush, just checking in.

@rsletta
Copy link
Author

rsletta commented Jul 16, 2023

I so sorry for not working faster. There has been no time to sit down and get back into this yet, even though I hoped I would be able to in my summer holiday. I have to prioritize family time first, and then it hasn't been much left. I can step away if I'm blocking progress, but I do intend to finish what I've started, if there isn't a rush. Sorry for the slow progress. 😕

@OGKevin
Copy link
Owner

OGKevin commented Dec 19, 2023

FYI @rsletta: #266 (comment)

@rsletta
Copy link
Author

rsletta commented Dec 20, 2023

Thank's for the heads up. I'm really sorry for dropping the ball on this, not delivering as promised.

This allowes to add notes to the highlight, without overwriting the
notes and keeping the higlight up to date.
@OGKevin OGKevin changed the title Keep existing highlights and notes, and add sort by chapter progress feat: keep existing highlights and notes, and add sort by chapter progress Jan 11, 2024
@OGKevin OGKevin marked this pull request as ready for review January 11, 2024 11:44
@OGKevin
Copy link
Owner

OGKevin commented Jan 11, 2024

Screenshot 2024-01-11 at 12 48 49
Screenshot 2024-01-11 at 12 48 53


I've also added a test case where the highlight is outdated, while having a custom note.

@OGKevin
Copy link
Owner

OGKevin commented Jan 11, 2024


> [email protected] test
> mocha



  HighlightService
    Sample Content
      Sample Bookmark with no annotation
        ✔ fromMaptoMarkdown with date
        ✔ fromMaptoMarkdown without date
        ✔ fromMaptoMarkdown with callouts
        ✔ fromMaptoMarkdown with callouts and date
        ✔ fromMaptoMarkdown with custom callouts
        ✔ fromMaptoMarkdown with custom callouts and date
      Sample Bookmark with annotation
        ✔ fromMaptoMarkdown with date
        ✔ fromMaptoMarkdown without date
        ✔ fromMaptoMarkdown with callouts
        ✔ fromMaptoMarkdown with callouts and date
        ✔ fromMaptoMarkdown with custom callouts
        ✔ fromMaptoMarkdown with custom callouts and date
      Sample Bookmark with annotation, with existing highlights and added notes
        ✔ fromMaptoMarkdown with existing file
      Sample Bookmark with annotation, with outdated existing highlights and added notes
        ✔ fromMaptoMarkdown with existing file
    Sample Content Missing
      Sample Bookmark linked to missing content
bookmark seems to link to a non existing content: missing-content-id
        ✔ fromMaptoMarkdown with date
    with multiple content
      ✔ getAllHighlight
      ✔ createHighlightFromBookmark e7f8f92d-38ca-4556-bab8-a4d902e9c430
      ✔ createHighlightFromBookmark d40c9071-993f-4f1f-ae53-594847d9fd27
      ✔ createHighlightFromBookmark 3408844d-65a6-4d23-9d99-8f189ca07d0b
      ✔ createHighlightFromBookmark c0d92aca-e4bb-476a-8131-ee0c0c21ced5

  Repository
    ✔ getAllBookmark (46ms)
    ✔ getBookmarkById null
    ✔ getBookmarkById not null
    ✔ getAllContent
    ✔ getContentByContentId
    ✔ getContentByContentId no results
    ✔ getAllContentByBookTitle (61ms)

  template
    ✔ applyTemplateTransformations default
    ✔ applyTemplateTransformations default
    ✔ applyTemplateTransformations with front matter


  30 passing (161ms)

@OGKevin OGKevin merged commit 7b31cd9 into OGKevin:master Jan 11, 2024
3 of 4 checks passed
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.

[Feature Request] Append to highlight note instead of overwriting.
2 participants