mirror of
https://github.com/nostr-protocol/nips.git
synced 2025-08-13 06:20:47 -04:00
01.md
02.md
03.md
04.md
05.md
06.md
07.md
08.md
09.md
10.md
11.md
12.md
13.md
14.md
15.md
16.md
17.md
18.md
19.md
20.md
21.md
22.md
23.md
24.md
25.md
26.md
27.md
28.md
29.md
30.md
31.md
32.md
33.md
34.md
35.md
36.md
37.md
38.md
39.md
40.md
42.md
44.md
45.md
46.md
47.md
48.md
49.md
50.md
51.md
52.md
53.md
54.md
55.md
56.md
57.md
58.md
59.md
60.md
61.md
62.md
64.md
65.md
66.md
68.md
69.md
70.md
71.md
72.md
73.md
75.md
78.md
7D.md
84.md
86.md
88.md
89.md
90.md
92.md
94.md
96.md
98.md
99.md
BREAKING.md
C0.md
C7.md
README.md
2.6 KiB
2.6 KiB
NIP-C0: Code Snippets
draft
optional
Abstract
This 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.
Event Kind
This NIP defines kind:1337
as a code snippet event.
The .content
field contains the actual code snippet text.
Optional Tags
l
- Programming language name (lowercase). Examples: "javascript", "python", "rust"name
- Name of the code snippet, commonly a filename. Examples: "hello-world.js", "quick-sort.py"extension
- File extension (without the dot). Examples: "js", "py", "rs"description
- Brief description of what the code doesruntime
- Runtime or environment specification (e.g., "node v18.15.0", "python 3.11")license
- License under which the code is shared (e.g., "MIT", "GPL-3.0", "Apache-2.0")dep
- Dependency required for the code to run (can be repeated)repo
- Reference to a repository where this code originates
Format
{
"id": "<32-bytes lowercase hex-encoded SHA-256 of the the serialized event data>",
"pubkey": "<32-bytes lowercase hex-encoded public key of the event creator>",
"created_at": <Unix timestamp in seconds>,
"kind": 1337,
"content": "function helloWorld() {\n console.log('Hello, Nostr!');\n}\n\nhelloWorld();",
"tags": [
["l", "javascript"],
["extension", "js"],
["name", "hello-world.js"],
["description", "A basic JavaScript function that prints 'Hello, Nostr!' to the console"],
["runtime", "node v18.15.0"],
["license", "MIT"],
["repo", "https://github.com/nostr-protocol/nostr"]
],
"sig": "<64-bytes signature of the id>"
}
Client Behavior
Clients that support this NIP SHOULD:
- Display code snippets with proper syntax highlighting based on the language.
- Allow copying the full code snippet with a single action.
- Render the code with appropriate formatting, preserving whitespace and indentation.
- Display the language and extension prominently.
- Provide "run" functionality for supported languages when possible.
- Display the description (if available) as part of the snippet presentation.
Clients MAY provide additional functionality such as:
- Code editing capabilities
- Forking/modifying snippets
- Creating executable environments based on the runtime/dependencies
- Downloading the snippet as a file using the provided extension
- Sharing the snippet with attribution