wasamasa / nov.el

Major mode for reading EPUBs in Emacs
GNU General Public License v3.0
654 stars 34 forks source link

Enhancement: Add support for org-noter #24

Closed sudarshang closed 6 years ago

sudarshang commented 6 years ago

Org-noter is interested in adding support for annotating EPUB files being viewed with nov.el. See Nov.el support. Is there a way nov.el could expose an API that will make this task easier?

wasamasa commented 6 years ago

None that I know of. The most obvious one is mapping the position of point to the file path, as is done currently. There is no such thing as referring to a page, simply because EPUBs don't consist of pages, but interlinked and reflowable documents. Assuming that you define a page by what is in the viewport after scrolling n pages, that wouldn't be terribly meaningful as it depends on many variables, such as the font metrics (including, but not limited to font size), window size and margins. If you have an idea for a better approach, please open a more specific issue.

weirdNox commented 6 years ago

Hello there! I was thinking of adding support by using the point of the position on each chapter, because I skim read your code and it seemed you used it as a restore point for resuming where the user left off. I experimented a bit, even with justify-kp, and the point seemed to be pretty consistent.

What do you think? Is the point consistent enough for bookmarking a position? Maybe if you add other things to nov.el in future versions, it will drift a bit, but even then, it probably will stay around the same section, no?

wasamasa commented 6 years ago

Yeah, as long as the rendering doesn't change, you'll be fine, even with reflow. I can only imagine things breaking if either shr.el (my dependency for actually rendering the stuff) changes significantly or the user picks their own renderer (in that case, the position of point would become invalid once they change, but from then on be reliable again).

nmsalgueiro commented 6 years ago

Ohh, I so hope this works! 😊

weirdNox commented 6 years ago

@wasamasa Yeah, that's what I thought, thanks. I think it may be good enough for our needs :)

@nmsalgueiro I don't know if I'll be able to do this anytime soon, but I'll do it as fast as I can :D

sudarshang commented 6 years ago

Calibre supports adding annotations to epub files using the following format see here

     {
       "id": 42,                                  // INTEGER NOT NULL PRIMARY KEY
       "created": "2014-11-02 12:19:13.000000",   // DATETIME DEFAULT NOW
       "updated": "2014-11-02 12:19:13.000000",   // DATETIME DEFAULT NOW

       "title": "The title of an exemplary book", // TEXT, title of book in Calibre
       "text": "A note I wrote",                  // TEXT, content of annotation
       "quote": "The text actually said this, since I quoted it.", // TEXT, the annotated text (added by frontend)
       "uri": "epub://part0036.html",             // TEXT, URI of annotated document (added by frontend)

       "user": "yousir",                          // TEXT, generally set to $HOME username or machine hostname

       // these are populated run-time by backref via the `range` table
       "ranges": [                                // list of ranges covered by annotation (usually only one entry)
         {
           "start": "/p[69]/span/span",           // (relative) XPath to start element
           "end": "/p[70]/span/span",             // (relative) XPath to end element
           "startOffset": 23,                     // character offset within start element
           "endOffset": 120                       // character offset within end element
         }
       ]
     }

   A sample =Range= structure is like:

     {
       "id": 2,                               // INTEGER NOT NULL PRIMARY KEY
       "start": "/p[69]/span/span",           // VARCHAR(255), (relative) XPath to start element
       "end": "/p[70]/span/span",             // VARCHAR(255), (relative) XPath to end element
       "startOffset": 23,                     // INTEGER, character offset within start element
       "endOffset": 120,                      // INTEGER, character offset within end element

       "annotation_id": 42                    // INTEGER FOREIGN KEY(annotation.id)
     }

Could org-noter use a format similar to the above so that comments made in Calibre can be viewed in Emacs? Can nov.el support an interface so that when adding notes in emacs org-noter will have the above information?

nmsalgueiro commented 6 years ago

@weirdNox I wouldn't dare to ask for it. You guys are too generous to develop these wonderful tools, so "when it's done" is a detail. Thank you both for your work! 😉👍

wasamasa commented 6 years ago

@sudarshang I don't see this working out because it leans on the assumption that there is a mapping from the rendered document to its DOM. The most you get from shr.el is a few text properties embedded in the buffer.

weirdNox commented 6 years ago

I just committed initial support for nov.el, should be in MELPA in a few hours. It is very experimental though, many underlying things were changed!