annals.highlights#
Each reader’s highlights: passages of documents kept with a name, tags and a note.
A reader selects text on a document’s page and keeps it. The page side is the
manicules widget (vendored under
ui/vendor/manicules/); this module is the server side it talks to: what a highlight is
allowed to be, where each reader’s are kept, and how they are searched. A highlight of a
document’s whole title keeps the document itself, which is how a reader marks a favourite.
A highlight, as stored (the shape of manicules’ highlight.schema.json):
{"id": "hmf3k2x9a1b2c3", "name": "Bread notes-highlight-1",
"target": {"source": {"id": "<doc id>", "title": "Bread notes", "url": "d/<doc id>"},
"part": "body",
"quote": {"exact": "85 percent water", "prefix": "A rye loaf takes ", "suffix": ", and"},
"position": {"start": 310, "end": 327}},
"comment": "the number I keep forgetting", "tags": ["rye"], "color": "green",
"created": "2026-11-27T10:00:00+00:00"}
The target is two W3C Web Annotation selectors (the quote with its context, and where it
was): the page finds the passage again from them after the document changed. whole in a
target means the entire part, whatever it says now. The server never interprets a target;
it bounds its size and keeps it.
Records live under the data root, one JSON file per reader
(highlights/<reader>.json, {id: highlight}, the layout manicules’ own file store and
CLI use), through annals.jsonstore.JsonFileStore; each reader’s two settings (the
default colour, and whether a page shows all its highlights when it opens) are beside them
(highlight-settings/<reader>.json). for_reader() is the seam: any
(reader) -> ReaderHighlights callable can replace it (mk_api(highlights=...)), its
records being anything with the three calls of Records. The routes the widget
talks to are annals.highlights_api.mk_router().
>>> rec = clean({"target": {"source": {"id": "d1", "title": "Notes"}, "quote": {"exact": "three sites"}}},
... names=["Notes-highlight-1"], now="2026-11-27T10:00:00+00:00", new_id=lambda: "h1")
>>> rec["name"], rec["target"]["part"], rec["tags"], rec["comment"]
('Notes-highlight-2', 'body', [], '')
>>> [h["id"] for h in search({"h1": rec}, "SITES notes")]
['h1']
>>> search({"h1": rec}, "sites absent")
[]
>>> clean_patch({"comment": "why", "color": None, "tags": ["b", "A", "a"]})
{'comment': 'why', 'color': None, 'tags': ['A', 'b']}
Module Attributes
the reader an agent surface (the CLI, the MCP server) answers for when none is named |
|
the colours a highlight may have (manicules' palette; each is legible in light and dark) |
|
what a reader gets before choosing anything |
|
the file is read whole on every page |
|
every list, search and page view reads it whole |
|
ids the API's own routes use ( |
|
the fields a reader may change afterwards; the target never changes |
Functions
|
Keep a new highlight. |
|
|
|
A complete highlight from what a caller sent, validated and bounded. |
|
What a reader may change ( |
|
The settings a reader may set, validated: |
|
A target as stored: its source, its part, and the selectors, each bounded. |
|
|
|
Change a highlight's name, note, tags or colour. |
|
The default seam: |
|
A highlight's page, opened on it, relative to the page's base ( |
|
A new id: sortable by creation time, unique enough for one reader's collection. |
|
One reader's highlights by id, read through a |
|
Who has highlights under a data root, read through its |
|
Delete a highlight and return it. |
|
The highlights matching every word of |
|
What a highlight is found by: its name, passage, note, tags and its page's title. |
|
A reader's settings over the defaults (a stored value of the wrong kind is ignored). |
Classes
|
One reader's highlights: |
|
What the API keeps for one reader: the highlights ( |
|
One reader's highlights, as this module and the API use them: any store with these three calls can stand behind the seam (a table in a database as well as a file). |
|
One reader's settings: |
- annals.highlights.DEFAULT_SETTINGS = {'color': 'yellow', 'showOthers': True}#
what a reader gets before choosing anything
- annals.highlights.ENV_READER = 'ANNALS_HIGHLIGHTS_READER'#
the reader an agent surface (the CLI, the MCP server) answers for when none is named
- class annals.highlights.HighlightStore(path)[source]#
Bases:
JsonFileStoreOne reader’s highlights:
{id: highlight}in one JSON file.- has_room()[source]#
Whether another highlight may be added: the file is read whole on every page, so it is bounded in bytes (
MAX_STORE_BYTES) as well as in number.- Return type:
- annals.highlights.MAX_HIGHLIGHTS = 5000#
the file is read whole on every page
- Type:
at most this many highlights per reader
- annals.highlights.MAX_STORE_BYTES = 20000000#
every list, search and page view reads it whole
- Type:
and their file at most this big
- annals.highlights.PALETTE = ('yellow', 'green', 'blue', 'pink', 'orange', 'purple')#
the colours a highlight may have (manicules’ palette; each is legible in light and dark)
- annals.highlights.PATCHABLE = ('name', 'comment', 'tags', 'color')#
the fields a reader may change afterwards; the target never changes
- annals.highlights.RESERVED_IDS = frozenset({'settings'})#
ids the API’s own routes use (
/highlights/settings)
- class annals.highlights.ReaderHighlights(records, settings)[source]#
Bases:
objectWhat the API keeps for one reader: the highlights (
Records), and the settings beside them (a mapping of setting name to value, withsnapshot()).
- class annals.highlights.Records(*args, **kwargs)[source]#
Bases:
ProtocolOne reader’s highlights, as this module and the API use them: any store with these three calls can stand behind the seam (a table in a database as well as a file).
- class annals.highlights.SettingsStore(path)[source]#
Bases:
JsonFileStoreOne reader’s settings:
{setting: value}in one JSON file.
- annals.highlights.add(records, data)[source]#
Keep a new highlight. Raises
ValueErrorwhen it is invalid, when its id is taken, or when the reader already hasMAX_HIGHLIGHTS.- Return type:
- annals.highlights.apply_patch(record, patch, *, now=None)[source]#
recordwith a cleaned patch applied; aNonecolour goes back to the default.- Return type:
- annals.highlights.clean(data, *, names=(), now=None, new_id=<function new_id>)[source]#
A complete highlight from what a caller sent, validated and bounded.
namesare the names of the page’s other highlights, for the default name. Anidorcreatedthe caller sent is kept when well formed (the page makes the id, so an undo puts back the very same highlight); unknown fields are dropped.- Return type:
- annals.highlights.clean_patch(patch)[source]#
What a reader may change (
PATCHABLE), validated; anything else is refused.- Return type:
- annals.highlights.clean_settings(patch)[source]#
The settings a reader may set, validated:
colorandshowOthers.- Return type:
- annals.highlights.clean_target(target)[source]#
A target as stored: its source, its part, and the selectors, each bounded.
Raises
ValueErrorfor a target with no source id, with neither a quote norwhole, or with a field of the wrong kind or size.- Return type:
- annals.highlights.default_name(title, names=())[source]#
<title>-highlight-<n>,nthe first number no highlight of that page uses.>>> default_name("Notes", ["a", "Notes-highlight-3"]) 'Notes-highlight-4' >>> default_name(" ") 'page-highlight-1'
- Return type:
- annals.highlights.edit(records, hid, patch)[source]#
Change a highlight’s name, note, tags or colour.
KeyErrorwhen there is none.- Return type:
- annals.highlights.for_reader(root)[source]#
The default seam:
<root>/highlights/<reader>.jsonandhighlight-settings/.- Return type:
- annals.highlights.href(record)[source]#
A highlight’s page, opened on it, relative to the page’s base (
""when it names none).The one place that address is built: the API’s
href, the CLI’surland the page all come from here.>>> href({"id": "h1", "target": {"source": {"id": "d1", "url": "d/d1?f=a.md"}}}) 'd/d1?f=a.md&h=h1'
- Return type:
- annals.highlights.new_id()[source]#
A new id: sortable by creation time, unique enough for one reader’s collection.
- Return type:
- annals.highlights.read_records(target, reader)[source]#
One reader’s highlights by id, read through a
Target(a local folder, or over ssh): for a caller that only reads. The one other place that knows the file layout isfor_reader().
- annals.highlights.readers(target)[source]#
Who has highlights under a data root, read through its
Target(so over ssh too).
- annals.highlights.remove(records, hid)[source]#
Delete a highlight and return it.
KeyErrorwhen there is none.- Return type:
- annals.highlights.search(records, q='', *, source=None, tag=None)[source]#
The highlights matching every word of
q(case ignored), newest first.sourcekeeps one page’s (its source id),tagthe ones carrying a tag. This is the function a wider search calls to list a reader’s highlights beside documents.