clone

every nostr nip as a chapter of an illustrated, early-2000s printed game manual

main
nip.guide / source-nips / C0.md
C0.md 3.3K rendered
1NIP-C02======34Code Snippets5-------------67`draft` `optional`89## Abstract1011This 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.1213## Event Kind1415This NIP defines `kind:1337` as a code snippet event.1617The `.content` field contains the actual code snippet text.1819## Optional Tags2021- `l` - Programming language name (lowercase). Examples: "javascript", "python", "rust"22- `name` - Name of the code snippet, commonly a filename. Examples: "hello-world.js", "quick-sort.py"23- `extension` - File extension (without the dot). Examples: "js", "py", "rs"24- `description` - Brief description of what the code does25- `runtime` - Runtime or environment specification (e.g., "node v18.15.0", "python 3.11")26- `license` - License under which the code (along with any related data contained within the event, when available, such as the description) is shared. This MUST be a standard [SPDX](https://spdx.org/licenses/) short identifier (e.g., "MIT", "GPL-3.0-or-later", "Apache-2.0") when available. An additional parameter containing a reference to the actual text of the license MAY be provided. This tag can be repeated, to indicate multi-licensing, allowing recipients to use the code under any license of choosing among the referenced ones27- `dep` - Dependency required for the code to run (can be repeated)28- `repo` - Reference to a repository where this code originates. This MUST be either a standard URL or, alternatively, the address of a [NIP-34](34.md) Git repository announcement event in the form `"30617:<32-bytes hex a pubkey>:<d tag value>"`. If a repository announcement is referenced, a recommended relay URL where to find the event should be provided as an additional parameter2930## Format3132```json33{34 "id": "<32-bytes lowercase hex-encoded SHA-256 of the the serialized event data>",35 "pubkey": "<32-bytes lowercase hex-encoded public key of the event creator>",36 "created_at": <Unix timestamp in seconds>,37 "kind": 1337,38 "content": "function helloWorld() {\n console.log('Hello, Nostr!');\n}\n\nhelloWorld();",39 "tags": [40 ["l", "javascript"],41 ["extension", "js"],42 ["name", "hello-world.js"],43 ["description", "A basic JavaScript function that prints 'Hello, Nostr!' to the console"],44 ["runtime", "node v18.15.0"],45 ["license", "MIT"],46 ["repo", "https://github.com/nostr-protocol/nostr"]47 ],48 "sig": "<64-bytes signature of the id>"49}50```5152## Client Behavior5354Clients that support this NIP SHOULD:55561. Display code snippets with proper syntax highlighting based on the language.572. Allow copying the full code snippet with a single action.583. Render the code with appropriate formatting, preserving whitespace and indentation.594. Display the language and extension prominently.605. Provide "run" functionality for supported languages when possible.616. Display the description (if available) as part of the snippet presentation.6263Clients MAY provide additional functionality such as:64651. Code editing capabilities662. Forking/modifying snippets673. Creating executable environments based on the runtime/dependencies684. Downloading the snippet as a file using the provided extension695. Sharing the snippet with attribution