- Documentation
- Write content
- Runnable code
Runnable code
Let readers run JavaScript and Python in the page, and fill in their own values once.
Add run to a code block, and readers get a Run button that runs it in the page and shows the output.
const total = [3, 4, 5].reduce((sum, n) => sum + n, 0);console.log(`Total: ${total}`);total * 2;Run shows what the code logs, then the value of its last line. The code runs in a sandbox that can’t reach your page or your reader’s data, stops after 10 seconds, and has a Stop button.
Write one
Section titled “Write one”Put run right after the language, or after a file name:
```js runconsole.log('Hello');```
```js client.js runconsole.log('Hello from a file');```runflagMakes the block runnable. In JavaScript and Python, readers get Run. In JavaScript and TypeScript, they also get Open in StackBlitz and Open in CodeSandbox, which open the code as a small project. Packages the code imports are added to it.
norunflagKeeps one block from running, when its language runs everywhere.
JavaScript can use top-level await. Python loads the first time a reader runs it. TypeScript isn’t run in the page,
so a TypeScript block only gets the two Open buttons.
Run can’t load packages. If a JavaScript block imports one, Run says “Imports need packages: open the example in StackBlitz or CodeSandbox.”
Run every block of a language
Section titled “Run every block of a language”To make every block in a language runnable, list it in docs.json:
{ "specly": { "run": ["python"] }}JavaScript and Python are the languages that run in the page.
Your values
Section titled “Your values”An example with a placeholder, like an API key, is easier to use with a real value. List the placeholders in
docs.json:
{ "specly": { "placeholders": ["YOUR_API_KEY"] }}Any block that holds one of those names gets a Your values button:
curl https://<slug>.specly.xyz/api/example \ -H "Authorization: Bearer YOUR_API_KEY"A reader chooses Your values and types a value once. Copy and Run then use it in every example on the site. It’s kept in that reader’s tab, and the page doesn’t change for anyone else. Open in StackBlitz and Open in CodeSandbox never include it.
specly.placeholdersstring[]The names to replace: 1 to 64 characters each, and up to 30 names.
Filling in values from your own sign-in (specly.personalization.endpoint) needs your docs on your own domain, which is coming.