upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/95.md
diff options
context:
space:
mode:
authorChristian Chiarulli <chris.machine@pm.me>2025-03-29 15:29:33 -0400
committerGitHub <noreply@github.com>2025-03-29 16:29:33 -0300
commit7dad42c1cffc0a32fa4eeb43631e12f6bc0091a4 (patch)
treeb511758bbd986b62a0458db6d0763f2db8854749 /95.md
parent86fc82ce4affe1f10fa5cab787a710105217b26c (diff)
NIP-C0: Code snippets (#1852)
Diffstat (limited to '95.md')
-rw-r--r--95.md65
1 files changed, 65 insertions, 0 deletions
diff --git a/95.md b/95.md
new file mode 100644
index 0000000..3dd7f26
--- /dev/null
+++ b/95.md
@@ -0,0 +1,65 @@
1# NIP-95: Code Snippets
2
3`draft` `optional`
4
5## Abstract
6
7This NIP defines a new event kind for sharing and storing code snippets. Unlike regular text notes (`kind:1`), code snippets have specialized metadata like language, extension, and other code-specific attributes that enhance discoverability, syntax highlighting, and improved user experience.
8
9## Event Kind
10
11This NIP defines `kind:1337` as a code snippet event.
12
13The `.content` field contains the actual code snippet text.
14
15## Optional Tags
16
17- `l` - Programming language name (lowercase). Examples: "javascript", "python", "rust"
18- `name` - Name of the code snippet, commonly a filename. Examples: "hello-world.js", "quick-sort.py"
19- `extension` - File extension (without the dot). Examples: "js", "py", "rs"
20- `description` - Brief description of what the code does
21- `runtime` - Runtime or environment specification (e.g., "node v18.15.0", "python 3.11")
22- `license` - License under which the code is shared (e.g., "MIT", "GPL-3.0", "Apache-2.0")
23- `dep` - Dependency required for the code to run (can be repeated)
24- `repo` - Reference to a repository where this code originates
25
26## Format
27
28```json
29{
30 "id": "<32-bytes lowercase hex-encoded SHA-256 of the the serialized event data>",
31 "pubkey": "<32-bytes lowercase hex-encoded public key of the event creator>",
32 "created_at": <Unix timestamp in seconds>,
33 "kind": 1337,
34 "content": "function helloWorld() {\n console.log('Hello, Nostr!');\n}\n\nhelloWorld();",
35 "tags": [
36 ["l", "javascript"],
37 ["extension", "js"],
38 ["name", "hello-world.js"],
39 ["description", "A basic JavaScript function that prints 'Hello, Nostr!' to the console"],
40 ["runtime", "node v18.15.0"],
41 ["license", "MIT"],
42 ["repo", "https://github.com/nostr-protocol/nostr"]
43 ],
44 "sig": "<64-bytes signature of the id>"
45}
46```
47
48## Client Behavior
49
50Clients that support this NIP SHOULD:
51
521. Display code snippets with proper syntax highlighting based on the language.
532. Allow copying the full code snippet with a single action.
543. Render the code with appropriate formatting, preserving whitespace and indentation.
554. Display the language and extension prominently.
565. Provide "run" functionality for supported languages when possible.
576. Display the description (if available) as part of the snippet presentation.
58
59Clients MAY provide additional functionality such as:
60
611. Code editing capabilities
622. Forking/modifying snippets
633. Creating executable environments based on the runtime/dependencies
644. Downloading the snippet as a file using the provided extension
655. Sharing the snippet with attribution