cognitive-engineering-lab / rust-book

The Rust Programming Language: Experimental Edition
https://rust-book.cs.brown.edu
Other
592 stars 92 forks source link

[Feature Idea] Export Highlights #121

Open fleshel opened 1 year ago

fleshel commented 1 year ago

Hello all!

I have been reading through the book and greatly enjoying it.

One idea I had was a way to export the highlighted portions as well as the notes, whether to a .txt or .csv file. I think that this would be incredibly helpful, especially due to the ephemeral nature of the highlights/notes (deleted when cookies are cleared).

Please let me know if this is a worthwhile idea -- I would be happy to assist in implementing it if so.

Thanks!

RobertRosca commented 10 months ago

I had a similar idea :smile:

The main question would be what format the export could take, since there isn't really a standard for this. The most used option I could find was CriticMarkup. It introduces syntax for comments and highlights:

Some text. {>>A comment for that text<<}

Some text with a {==highlighted section==}.

Some text with a {==highlighted section==}{>>with a comment for that section<<} followed by not-highlighted text.

Briefly looked at how it works and the book webpage uses web-highlighter for its highlights with a custom HighlightExtra for the text notes. In the end the data stored in the cookies is:

[
   {
      "startMeta":{
         "parentTagName":"P",
         "parentIndex":0,
         "textOffset":20
      },
      "endMeta":{
         "parentTagName":"P",
         "parentIndex":0,
         "textOffset":25
      },
      "text":"clear",
      "id":"a29c9903-dac2-451f-9c12-fdcdee276de5",
      "__isHighlightSource":{

      },
      "extra":"{\"text\":\"note text\",\"page\":\"/foreword.html\",\"domHash\":\"01bc6f8efa4202821e95f4fdf6298b30\"}"
   }
]

Where:

Given what's there, adding some functionality to export this to some plain text file (either by hackily reading the cookie data, or by a contribution to the book which adds the relevant JS functionality and a button somewhere) doesn't look too difficult, but the question would be what format(s) to pick for export.

Formats I can think of:

Maybe with, where appropriate, some options for exporting highlights from a single page or the whole book, and only highlighted text or all text.

My JS skills are wonky at best and I'm not sure when or if I'd have time to work on this (wanted to go through the book for years and got nowhere so far lol), so if you or somebody else is interested I'd be super happy with a single page or whole book all text export with CriticMarkup syntax :pray:

willcrichton commented 8 months ago

I won't have the time to implement this feature, but I would be to accept a PR if someone has the time.