r/javascript • u/ExpertPlay • Oct 27 '26
penciled – persistent text highlights/notes with the CSS Custom Highlight API (no DOM wrapping)
https://penciled.orgI built penciled, a small MIT library for persistent text highlights and notes in the browser. It uses the CSS Custom Highlight API instead of wrapping ranges in <span>s, so the DOM stays intact and layout/selection quirks are milder. Anchoring tries to survive edits when you come back to the page.
npm: penciled
GitHub: https://github.com/marcellosso/penciled
There's also a companion browser extension (same engine) if you want highlights on arbitrary sites, happy to answer questions about the API or the anchoring approach.
1
u/abhinavs1920 Oct 28 '26
What happens to a saved note when the same quoted text appears twice after a page edit? Does it ask the reader to choose, or leave the note unattached rather than risk moving it to the wrong passage?
1
u/ExpertPlay Oct 28 '26
When a quote is saved, we also store a bit of the surrounding context. That way, when a page changes, we re-anchor with the stored quote + that context. If two spots look about equally good, we orphan it instead of guessing: the note stays saved, we just don’t paint a highlight
1
u/timo770353 19d ago
Does the note UI flag orphaned anchors? Leaving them unattached avoids wrong matches; could a status help readers find those notes?
1
u/p_n_48947 19d ago
Yes: a review list could show each orphaned note with its saved quote/context and let readers reattach or dismiss it without the app guessing.
1
1
u/immutate Oct 27 '26
How accessible is it?