### datastore.batchGet example Source: https://silverbullet.md/API/datastore Gets multiple values from the key-value store. Returns values in key order, with nil for missing keys. ```lua local values = datastore.batchGet({{"user", "1"}, {"user", "2"}}) ``` -------------------------------- ### YAML syntax highlighting example Source: https://silverbullet.md/Markdown/Syntax%20Highlighting YAML example showing a simple key-value pair. ```yaml name: Pete ``` -------------------------------- ### datastore.get example Source: https://silverbullet.md/API/datastore Gets a value from the key-value store. Returns the stored value or nil when absent. ```lua local user = datastore.get({"user", "123"}) ``` -------------------------------- ### Define a service with service.define + minimal match Source: https://silverbullet.md/API/service Second example from the Architecture section. Defines two service.define calls with the same selector, where the second has a match function that returns priority 10 only for name 'Pete'. The second example shows how to give a service a higher priority. ```lua service.define { selector = "greeter-service", match = {}, run = function(name) return "Hello " .. name end } service.define { selector = "greeter-service", match = function(name) if name == "Pete" then return {priority=10} else return nil end end, run = function(name) return "Hello Pete, so happy to see you!" end } ``` -------------------------------- ### Custom task statuses example Source: https://silverbullet.md/Markdown/Basics Example of custom task states placed between brackets. Clicking cycles through the states seen in the space. ```markdown * [IN PROGRESS] This task is in progress * [DONE] This task is done * [TO DO] This task is still to be done ``` -------------------------------- ### Install dependencies and build plug Source: https://silverbullet.md/Plugs/Development Commands to set up a plug project from the silverbullet-plug-template and build it, producing a *.plug.js bundle. ```bash npm install npm run build ``` -------------------------------- ### mq.send example Source: https://silverbullet.md/API/mq Sends a message to the specified queue. ```lua mq.send("tasks", "my task") ``` -------------------------------- ### Frontmatter with tags example Source: https://silverbullet.md/Guide/Best%20Practices Example of frontmatter with a 'role' field and a 'tags' field listing multiple tags. ```yaml --- role: Data analyst tags: sometag anothertag --- ``` -------------------------------- ### datastore.batchSet example Source: https://silverbullet.md/API/datastore Sets multiple key-value entries in one operation. Entries have key and value fields. ```lua datastore.batchSet({ {key = {"user", "1"}, value = {name = "Alice"}}, {key = {"user", "2"}, value = {name = "Bob"}}, }) ``` -------------------------------- ### Run SilverBullet server Source: https://silverbullet.md/Install/Server%20Binary Starts the server, pointing it at the data folder. The server listens on http://localhost:3000 by default. ```bash ./silverbullet sb-data ``` -------------------------------- ### Example: Ordered list Source: https://silverbullet.md/Markdown/Basics A sample ordered list using numbers followed by a period. ```markdown 1. This is the first item 2. This is the second item ``` -------------------------------- ### Frontmatter example Source: https://silverbullet.md/Frontmatter Example of a markdown document with frontmatter at the top, showing YAML attributes and the document body. ```markdown --- status: Draft tags: - tag1 - tag2 seeAlso: "[YAML]()" --- ## This is a section This is content ``` -------------------------------- ### Invoke best match with service.invokeBestMatch Source: https://silverbullet.md/API/service Simple invocation example for `service.invokeBestMatch` using the selector 'greeter' and data 'Pete'. ```lua local greeting = service.invokeBestMatch("greeter", "Pete") ``` -------------------------------- ### datastore.set example Source: https://silverbullet.md/API/datastore Sets a value in the key-value store. Takes a key as a list of segments and a value to store. ```lua datastore.set({"user", "123"}, {name = "John"}) ``` -------------------------------- ### mq.subscribe example Source: https://silverbullet.md/API/mq Subscribes a callback to a message queue to process incoming messages. ```lua mq.subscribe { queue = "tasks", batchSize = 1, run = function(messages) print(messages[1].body) end } ``` -------------------------------- ### Example: Unordered list using * Source: https://silverbullet.md/Markdown/Basics A sample unordered list using the asterisk bullet. SilverBullet prefers the asterisk for styling. ```markdown * This is an unordered list * And this is a second item ``` -------------------------------- ### datastore.batchDelete example Source: https://silverbullet.md/API/datastore Deletes multiple values from the key-value store. Takes a list of keys to delete. ```lua datastore.batchDelete({{"user", "1"}, {"user", "2"}}) ``` -------------------------------- ### mq.subscribe with notification example Source: https://silverbullet.md/API/mq Subscribes to a queue and displays a notification for each received message. ```lua mq.subscribe { queue = "testqueue", batchSize = 1, run = function(messages) for _, msg in ipairs(messages) do editor.flashNotification("Received message: " .. msg.body) end end } ``` -------------------------------- ### Rust main function example Source: https://silverbullet.md/Markdown/Syntax%20Highlighting Rust main function that prints a message to the console. ```rust fn main() { // Print text to the console println!("Hello World!"); } ``` -------------------------------- ### Run server on custom port Source: https://silverbullet.md/Install/Server%20Binary Starts the server on a different port using the -p flag. ```bash ./silverbullet -p 3001 sb-data ``` -------------------------------- ### Bind server to custom address Source: https://silverbullet.md/Install/Server%20Binary Starts the server bound to an address other than 127.0.0.1 using the -L flag. ```bash ./silverbullet -L 0.0.0.0 sb-data ``` -------------------------------- ### Get file metadata with asset.getFileMeta Source: https://silverbullet.md/API/asset Retrieves metadata for an asset embedded in a plug. The function takes a plug name and asset path, returning a table with file metadata. The example prints the lastModified field. ```lua local meta = asset.getFileMeta("myplug", "data.txt") print(meta.lastModified) ``` -------------------------------- ### Define a service with service.define Source: https://silverbullet.md/API/service Example for `service.define` showing a default match and a run function that returns a greeting. The match field is an empty table, so the service matches without priority. ```lua service.define { selector = "greeter", match = {}, run = function(name) return "Hello " .. name end } ``` -------------------------------- ### Custom task states example: NOT STARTED and IN PROGRESS Source: https://silverbullet.md/Task Shows custom task states in checkboxes. States cannot contain `:` to avoid ambiguity with Attribute syntax. Define custom states explicitly using the taskState API. ```markdown * [NOT STARTED] Task 1 Fix having global variables work in markdown.expandMarkdown * [IN PROGRESS] Task 2 ``` -------------------------------- ### Array attribute example Source: https://silverbullet.md/Attribute Example of an array attribute value. ```markdown [attribute3: [sup, yo]] ``` -------------------------------- ### Number attribute example Source: https://silverbullet.md/Attribute Example of a numeric attribute value. ```markdown [attribute2: 10] ``` -------------------------------- ### String attribute example Source: https://silverbullet.md/Attribute Example of a string attribute value. ```markdown [attribute1: sup] ``` -------------------------------- ### Create data folder Source: https://silverbullet.md/Install/Server%20Binary Creates a directory to hold server configuration and space files. ```bash mkdir sb-data ``` -------------------------------- ### Task list example with standard states Source: https://silverbullet.md/Markdown/Basics A sample task list using empty checkboxes. Clicking replaces the space with x. ```markdown * [ ] This is a task * [ ] And this is another ``` -------------------------------- ### hello.plug.yaml manifest Source: https://silverbullet.md/Plugs/Development Minimal plug manifest defining a helloCommand function with a command hook. ```yaml name: hello functions: helloCommand: path: "./hello.ts:helloCommand" command: name: "Hello: World" ``` -------------------------------- ### Bundling assets Source: https://silverbullet.md/Plugs/Development/Reference Describes how to bundle files into the plug binary using the `assets:` manifest key, and how to read them at runtime with the asset syscall. ```APIDOC ## Bundling assets ### Description The `assets:` manifest key bundles files into the plug binary. They can be read at runtime using the `asset` syscall. ### Syscall Usage import { asset } from "@silverbulletmd/silverbullet/syscalls"; const css = await asset.readAsset("myplug", "styles.css", "utf8"); ### Parameters - **plug** (string) - The name of the plug. - **path** (string) - Path to the asset within the plug. - **encoding** (string) - Optional encoding (e.g., "utf8"). ### Returns The file content as a string (or binary depending on encoding). ``` -------------------------------- ### datastore.get Source: https://silverbullet.md/API/datastore Gets a value from the key-value store. ```APIDOC ## datastore.get ### Description Gets a value from the key-value store. ### Method N/A (Lua function) ### Endpoint N/A (Lua function) ### Parameters - **key** (`table`) - Required - Key segments. ### Returns - Value - Stored value, or nil when absent. ### Request Example ```lua local user = datastore.get({"user", "123"}) ``` ### Response Example ```lua {name = "John"} ``` ``` -------------------------------- ### Task attribute example Source: https://silverbullet.md/Attribute Attaches an attribute to a task. ```markdown * Task with an attribute, I’m so cool [taskAttribute: hello] ``` -------------------------------- ### Docker Compose configuration and commands Source: https://silverbullet.md/Install/Docker Basic Docker Compose setup for SilverBullet. Replace the password in SB_USER with something sensible. The ./data directory is auto-created and used for data. Boot up with 'docker compose up -d' and watch logs with 'docker compose logs -f'. ```yaml services: silverbullet: image: ghcr.io/silverbulletmd/silverbullet:latest restart: unless-stopped environment: - SB_USER=admin:password volumes: - ./data:/data ports: - 3000:3000 ``` ```bash docker compose up -d ``` ```bash docker compose logs -f ``` -------------------------------- ### Minimal library frontmatter with Hello world command Source: https://silverbullet.md/Library/Development Defines a library page with required frontmatter (name, tags) and a space-lua command that flashes a notification. The name must match the page's full path or a validation error appears. ```markdown --- name: Library/myuser/My Library tags: meta/library --- This implements my super awesome hello world library! ```space-lua command.define { name = "Hello world", run = function() editor.flashNotification "Hello world!" end } ``` ``` -------------------------------- ### datastore.batchGet Source: https://silverbullet.md/API/datastore Gets multiple values from the key-value store. ```APIDOC ## datastore.batchGet ### Description Gets multiple values from the key-value store. ### Method N/A (Lua function) ### Endpoint N/A (Lua function) ### Parameters - **keys** (`table`) - Required - List of keys to read. ### Returns - `table` - Values in key order, with nil for missing keys. ### Request Example ```lua local values = datastore.batchGet({{"user", "1"}, {"user", "2"}}) ``` ### Response Example ```lua {value1, value2, ...} ``` ``` -------------------------------- ### Swift function example Source: https://silverbullet.md/Markdown/Syntax%20Highlighting Swift function that prints a message. ```swift func myFunc() { print("Hello World!") } ``` -------------------------------- ### GET /.logout Source: https://silverbullet.md/HTTP%20API Clears authentication cookies and redirects to /.auth. ```APIDOC ## GET /.logout ### Description Clears authentication cookies and redirects to /.auth. ### Method GET ### Endpoint /.logout ### Response #### Success Response (302) - Redirects to /.auth. ``` -------------------------------- ### Minimal events-only manifest (hello.plug.yaml) Source: https://silverbullet.md/Plugs/Development/Reference A minimal manifest with a single function `greet` that listens to the `editor:init` event. The function is defined with a `path` pointing to `./hello.ts:greet` and an `events` hook. ```yaml name: hello functions: greet: path: "./hello.ts:greet" events: - editor:init ``` -------------------------------- ### mq.getQueueStats Source: https://silverbullet.md/API/mq Gets queued, processing, and dead-letter counts for a queue. ```APIDOC ## mq.getQueueStats ### Description Gets queued, processing, and dead-letter counts for a queue. ### Method mq.getQueueStats ### Parameters - `queue?` (string) - Optional - Queue name. ### Returns - `table` - Queue statistics. ``` -------------------------------- ### Repository page with library list Source: https://silverbullet.md/Library/Development Creates a repository page under Repository/ with meta/repository tag and a list of library data objects. Required keys: name and uri; recommended: description, author, website. ```markdown --- tags: meta/repository --- This is my curated list of awesome libraries! ```#meta/library/remote name: Library1 description: This is my first awesome library website: http://url.com/to/docs uri: https://github.com/myuser/silverbullet-libraries/blob/main/Library1.md --- name: Library2 description: This is my second awesome library uri: https://github.com/myuser/silverbullet-libraries/blob/main/Library2.md ``` ``` -------------------------------- ### C++ class example Source: https://silverbullet.md/Markdown/Syntax%20Highlighting C++ class definition with an empty body. ```c++ class MyClass { } ``` -------------------------------- ### SQL select example Source: https://silverbullet.md/Markdown/Syntax%20Highlighting SQL query selecting all rows from a table. ```sql select * from my_table; ``` -------------------------------- ### JavaScript function example Source: https://silverbullet.md/Markdown/Syntax%20Highlighting JavaScript function that logs a message to the console. ```javascript function myFunc() { console.log("Hello World!"); } ``` -------------------------------- ### hello.ts plug implementation Source: https://silverbullet.md/Plugs/Development TypeScript source for the hello plug, importing the editor syscall to flash a notification. ```typescript import { editor } from "@silverbulletmd/silverbullet/syscalls"; export async function helloCommand() { await editor.flashNotification("Hello, world!"); } ``` -------------------------------- ### Invoke best match with service.invokeBestMatch Source: https://silverbullet.md/API/service The invocation line shown after the second example: `${service.invokeBestMatch("greeter-service", "Pete")}` and ${service.invokeBestMatch("greeter-service", "Hank")}. Note that this is a template expression, not a standalone Lua script; it appears after the full example. ```lua ${service.invokeBestMatch("greeter-service", "Pete")} and ${service.invokeBestMatch("greeter-service", "Hank")} ``` -------------------------------- ### TypeScript function example Source: https://silverbullet.md/Markdown/Syntax%20Highlighting TypeScript function with a typed parameter that logs a greeting. ```typescript function myFunc(name: string) { console.log("Hello", name); } ``` -------------------------------- ### List files with asset.listFiles Source: https://silverbullet.md/API/asset Lists the assets embedded in a plug. The function takes a plug name and returns a table of file metadata. The example iterates over the list and prints each file name. ```lua for _, file in ipairs(asset.listFiles("myplug")) do print(file.name) end ```