Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…

Read the release notes

Highlights and Annotations

How readers highlight passages and attach private notes to an article, where those are stored, and how to read, export or style them.

What readers get

A reader selects text in an article. A small toolbar appears by the selection. One button highlights the passage in a chosen colour, another highlights it and opens a note. The highlight is still there on the next visit, and a mark in the margin shows which highlights have notes.

Everything is stored in that reader's browser. Nothing is sent to a server, no account is needed, and no other reader sees it. Try it: select a sentence in the demo.

The parts

PartJob
<selection-menu> Shows a toolbar when text is selected inside the element named by for. It holds whatever action elements you put in it and knows nothing about highlights. Alt + F10 moves focus into the toolbar and Escape returns it.
<highlight-wc> The highlighter button and its colour choices. It turns the menu's target into a highlightable article.
<note-wc> The note button and the panel where a note is written. It also opens that panel when the reader clicks a mark in the margin.
data-highlights The attribute that marks an element as holding highlights. <highlight-wc> sets it on the target for you. Write it yourself to show stored highlights with no toolbar.

Highlights are drawn with the CSS Custom Highlight API, which paints ranges of text without changing the document. In a browser without it, each highlight is wrapped in a <mark> element.

Common arrangements

Highlights without notes

Leave out <note-wc>.

Showing stored highlights only

Use the attribute alone, with data-highlights-readonly. Highlights saved earlier are drawn and new selections do nothing.

Your own colours

The default colours are yellow, green, blue and pink, each a token named --highlight-{name}. To add one, define its token and list the names in colors. A colour with no token is not painted.

Give the token a light and a dark value, as the built-in ones have, so highlighted text stays readable in both schemes. The text colour over a highlight is --highlight-ink. Set --highlight-{name}-ink to change it for one colour.

A notes button in the page toolbar

A <note-wc> outside the selection menu, with for, is a button that opens the note panel on the first highlight that has a note, or the first highlight if none has.

Where highlights are kept

Highlights are saved through VBStore, which writes to the browser's local storage by default. Each article's set is saved under a key. The key is the page's path unless you name one.

Name a key when the same article is served at more than one address, or when two articles share a page.

A highlight is stored as a start and end position in the article's text, with a copy of the highlighted words and of the 32 characters on either side. When the article's text changes, each stored highlight is checked against that copy. If the words are no longer at the stored position, the article is searched for them, and the text on either side picks between several matches. An edit elsewhere in the article therefore moves a highlight and does not remove it.

A highlight whose words are no longer in the article cannot be shown. It is not deleted: it stays in storage, is tried again on each visit, and comes back if the words do. When that happens the article fires highlights:unplaced and a warning is written to the console. removeHighlight(id) or clearAll() discards such a highlight for good.

Working with highlights in script

The <highlight-wc> element is the way in. Its methods act on the article it highlights.

MethodDoes
getHighlights()Returns an array of { id, startOffset, endOffset, text, prefix, suffix, color, note, created }
highlightSelection(color)Highlights the current selection
removeHighlight(id)Removes one
clearAll()Removes all of them
exportHighlights()Returns a JSON string of the set
importHighlights(json)Replaces the set. Records that do not fit the text or the palette are dropped. Returns { imported, rejected }.

To build your own controls with no selection toolbar, place <highlight-wc for="post"> anywhere on the page. In that form it shows nothing and gives you the methods and events.

Events

All of these fire on the article and bubble.

EventDetailWhen
highlights:added{ id, text, color, note }A highlight is made
highlights:removed{ id }A highlight is removed with removeHighlight()
highlights:unplaced{ highlights }After stored highlights load, when the words of one or more are no longer in the article. highlights is an array of those records.
highlights:note-changed{ id, note }A note is saved
highlights:clicked{ id, highlight }The reader clicks a highlight or its margin mark
highlights:selected{ text, rect }The reader finishes selecting text in the article. Use it to place your own toolbar.
highlights:request-note{ id, highlight, controller }The reader clicks a margin mark. <note-wc> listens for this and opens its panel.
↑