diff options
| author | fiatjaf <fiatjaf@gmail.com> | 2025-03-29 16:29:58 -0300 |
|---|---|---|
| committer | fiatjaf <fiatjaf@gmail.com> | 2025-03-29 16:29:58 -0300 |
| commit | f90101406592134e5f9c27c5e81fad3ee670e9c1 (patch) | |
| tree | cd01c495e81a667fd04b61d0d00ce5532d6feee1 /C0.md | |
| parent | 7dad42c1cffc0a32fa4eeb43631e12f6bc0091a4 (diff) | |
rename 95 to C0.
Diffstat (limited to 'C0.md')
| -rw-r--r-- | C0.md | 65 |
1 files changed, 65 insertions, 0 deletions
| @@ -0,0 +1,65 @@ | |||
| 1 | # NIP-C0: Code Snippets | ||
| 2 | |||
| 3 | `draft` `optional` | ||
| 4 | |||
| 5 | ## Abstract | ||
| 6 | |||
| 7 | 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. | ||
| 8 | |||
| 9 | ## Event Kind | ||
| 10 | |||
| 11 | This NIP defines `kind:1337` as a code snippet event. | ||
| 12 | |||
| 13 | The `.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 | |||
| 50 | Clients that support this NIP SHOULD: | ||
| 51 | |||
| 52 | 1. Display code snippets with proper syntax highlighting based on the language. | ||
| 53 | 2. Allow copying the full code snippet with a single action. | ||
| 54 | 3. Render the code with appropriate formatting, preserving whitespace and indentation. | ||
| 55 | 4. Display the language and extension prominently. | ||
| 56 | 5. Provide "run" functionality for supported languages when possible. | ||
| 57 | 6. Display the description (if available) as part of the snippet presentation. | ||
| 58 | |||
| 59 | Clients MAY provide additional functionality such as: | ||
| 60 | |||
| 61 | 1. Code editing capabilities | ||
| 62 | 2. Forking/modifying snippets | ||
| 63 | 3. Creating executable environments based on the runtime/dependencies | ||
| 64 | 4. Downloading the snippet as a file using the provided extension | ||
| 65 | 5. Sharing the snippet with attribution | ||