This Flutter app is the canonical integration example for
searchlight_highlight.
It validates two distinct paths:
- standalone highlighting with
Highlight,Position,HTML, andtrim() - parsedoc-backed folder indexing where
searchlight_parsedocextracts live.mdand.htmlfiles into records,searchlightindexes them, andsearchlight_highlightrenders the matched ranges
The app is intentionally an integration harness, not a reusable UI package.
This example depends on three packages with separate responsibilities:
searchlight_highlightcomputes highlight state,HTML, and inclusivePositionoffsetssearchlightindexes records and executes queriessearchlight_parsedocparses Markdown and HTML into Searchlight-ready records
This split mirrors the upstream package boundaries:
- standalone highlighting is not a create-time plugin
- parsing lives outside core search
- UI rendering stays in the app
Current example-app constraints:
- the parsedoc integration currently depends on
searchlight_parsedocfrom GitHubmain - live folder indexing in this app is desktop-only
From example/:
flutter pub get
flutter run -d macosIn Standalone highlight mode the default sample is an excerpt from
Alice's Adventures in Wonderland with the query Alice Rabbit.
Confirm the four output cards:
- TextSpan preview — Flutter
RichText/TextSpanrendering from inclusivePositionranges, with the positions listed below the preview - Rendered HTML preview — the highlight HTML rendered by
flutter_html - Raw HTML string — the literal HTML markup (should contain
<mark class="searchlight-highlight">) shown in a code-style block - Trim(18) — the trimmed highlight output from
highlight.trim(18)
Also:
- try the three strategy modes; depending on the current sample/query pair, some modes may render the same output
- toggle case sensitivity and verify matching changes
In Parsedoc + highlight mode:
- Click
Choose Folder. - Pick a folder containing
.mdand/or.htmlfiles. - Confirm the app reports the indexed record count and supported file count.
- Enter a search term that exists in extracted record
contentorpath. - Confirm:
- the result list filters down to matching records
- the result list shows content preview highlighting for matching records
- the selected record details show highlighted title and highlighted content
- markdown records show
Rendered with flutter_markdown_plus MarkdownBody. - HTML records show
Shown as raw HTML source text.
Supported live folder formats in this example:
.md.html
searchlight_highlight.Position.end is inclusive.
When converting positions into TextSpan ranges, use end + 1 for the Dart
substring end offset. The example app demonstrates that pattern in
main.dart.
The standalone example app uses searchlight-highlight as a custom CSS class
for readability in its raw HTML card. The package default remains
orama-highlight unless you override HighlightOptions.CSSClass.