Expand description
Marking ranges of text that somebody else owns.
§The boundary, and what the caller owes
This crate does not search text. Deciding that a run of characters answers a query is the same kind of judgement as deciding that a word is a keyword: it needs to know about case folding, word boundaries, normalisation forms, whether the query is a regular expression, and what the host considers one document — none of which a product-neutral component can answer, and all of which the application that owns the text already has.
So the component takes ranges, not a query. The caller owes:
- the exact
SharedStringit wants marked, handed to this component; - byte offsets into that string, on character boundaries;
- ranges sorted ascending and not overlapping one another;
- which of them, by index, is the current one — or none.
A range that breaks any of those is skipped rather than drawn wrongly and
rather than panicking, because a highlight is decoration over text that is
still readable without it: losing a mark is recoverable, losing the line is
not. HighlightedText::published_hits reports how many were actually
drawn, so a caller that got the offsets wrong can see it.
The same boundary serves the read-only code view, which takes
pre-classified CodeSpans for exactly the same
reason.
Structs§
- Highlighted
Text - A run of text with some of it marked.