NIP-84
======
Highlights
----------
`draft` `optional`
This NIP defines `kind:9802`, a "highlight" event, to signal content a user finds valuable.
## Format
The `.content` of these events is the highlighted portion of the text.
`.content` might be empty for highlights of non-text based media (e.g. NIP-94 audio/video).
### References
Events SHOULD tag the source of the highlight, whether nostr-native or not.
`a` or `e` tags should be used for nostr events and `r` tags for URLs.
When tagging a URL, clients generating these events SHOULD do a best effort of cleaning the URL from trackers
or obvious non-useful information from the query string.
### Attribution
Clients MAY include one or more `p` tags, tagging the original authors of the material being highlighted; this is particularly
useful when highlighting non-nostr content for which the client might be able to get a nostr pubkey somehow
(e.g. prompting the user or reading a `` tag on the document). A role MAY be included as the
last value of the tag.
```jsonc
{
"tags": [
["p", "", "", "author"],
["p", "", "", "author"],
["p", "", "", "editor"]
],
// other fields...
}
```
### Context
Clients MAY include a `context` tag, useful when the highlight is a subset of a paragraph and displaying the
surrounding content might be beneficial to give context to the highlight.
## Quote Highlights
A `comment` tag may be added to create a quote highlight. This MUST be rendered like a quote repost with the highlight as the quoted note.
This is to prevent the creation and multiple notes (highlight + kind 1) for a single highlight action, which looks bad in micro-blogging clients where these notes may appear in succession.
p-tag mentions MUST have a `mention` attribute to distinguish it from authors and editors.
r-tag urls from the comment MUST have a `mention` attribute to distinguish from the highlighted source url. The source url MUST have the `source` attribute.
## GitRepublic Usage
GitRepublic extends NIP-84 highlights for code review and code selection features. Highlights enable users to select and comment on specific code sections in pull requests.
### Code Highlighting
When users select code in a PR for review:
1. **Highlight Creation**: A kind 9802 event is created with the selected code in the `content` field
2. **File Context**: Custom tags (`file`, `line-start`, `line-end`) specify which file and lines are highlighted
3. **PR Reference**: The highlight references the PR using `a` and `e` tags
4. **Attribution**: `P` and `p` tags reference the PR author and highlight creator
### Extended Tags
GitRepublic extends NIP-84 with file-specific tags for code context:
- `file`: File path being highlighted
- `line-start`: Starting line number
- `line-end`: Ending line number
- `context`: Optional surrounding context
- `comment`: Optional comment text for quote highlights
### Example: Code Highlight on PR
```jsonc
{
"kind": 9802,
"content": "const result = await fetch(url);",
"tags": [
["a", "1618:pr_author_pubkey.../repo-name"],
["e", "pr_event_id"],
["P", "pr_author_pubkey"],
["K", "1618"],
["file", "src/main.ts"],
["line-start", "42"],
["line-end", "45"],
["context", "// Fetch data from API"],
["p", "pr_author_pubkey", "wss://relay.example.com", "author"]
]
}
```
**Implementation**: `src/lib/services/nostr/highlights-service.ts`