Code block guidelines
To create a code block:
- Use triple-grave characters (
```) as a fence, and enter a language name after the first```fence - Indent lines by four spaces or one tab
Learn about conventions for code blocks
Learn about code block special formatting and functionality
Here is an example of a JSON code block:
```json{ "firstName": "John", "lastName": "Smith", "age": 25}```The rendered output looks like this:
{ "firstName": "John", "lastName": "Smith", "age": 25}To add the output of your code block, create a second code block below the first and add the output property to the opening code fence, like this:
npx wrangler vectorize create tutorial-index --dimensions=3 --metric=cosine✅ Successfully created index 'tutorial-index'
[[vectorize]]binding = "VECTORIZE_INDEX" # available in your Worker on env.VECTORIZE_INDEXindex_name = "tutorial-index"```shnpx wrangler vectorize create tutorial-index --dimensions=3 --metric=cosine```
```txt output✅ Successfully created index 'tutorial-index'
[[vectorize]]binding = "VECTORIZE_INDEX" # available in your Worker on env.VECTORIZE_INDEXindex_name = "tutorial-index"```To define the language of your code block, enter the name of the language after the first ``` fence.
If there is no appropriate syntax language, use txt (for example, a fragment of an Apache configuration file).
Make sure you enter the language name in lower case, since other capitalizations of these names are not supported. For example, entering JavaScript would use the txt language.
Here is a list of supported languages:
bash(alias:curl) Learn more about terminal commandscdiffgographqlhcl(alias:tf)htmlinijavajs(alias:javascript)jsonLearn more about JSON commandskotlinphppowershellLearn more about terminal commandspython(alias:py)ruby(alias:rb)rust(alias:rs)sh(alias:shell) Learn more about terminal commandssqlswifttomlts(alias:typescript)txt(aliases:text,plaintext, no language name)xmlyaml(alias:yml)
Use sh for one-line commands executed in the Linux/macOS terminal.
- Each command must be in a single line
- Use "
$"(dollar sign, space) or "FOLDER_NAME $ " (folder name, space, dollar sign, space) - Examples:
$command-to-run- ~/my-folder
$command-to-run (where~means the home folder of the current user)
Use bash for other Linux/macOS/generic commands.
- For example:
- Commands that span multiple lines (usually each line ends with a
\) and may include one or more lines of JSON content - Commands for specific shells (for example, a command specifically for the zsh shell, where the prompt is usually
%)
- Commands that span multiple lines (usually each line ends with a
- If a code block contains only one (multi-line) command, do not include a
$prefix so that the user can run the command immediately after copying and pasting without having to remove the prefix - If a code block includes several commands or it includes output, consider including a prefix before each command to help differentiate between commands and their output
- For zsh-specific instructions you can use a
%command prefix instead of$
Use the powershell language for Windows PowerShell commands.
- By default, do not use any prompt prefixes for PowerShell commands
- If you need to establish context (for example, you must be in a specific folder before running a command), use the following prompt:
- "PS FOLDER_NAME> " (the
>is part of the prompt, and there is a space after it) - Examples:
- PS C:\> command-to-run.exe
- PS C:\Users\JohnDoe> command-to-run.exe
- "PS FOLDER_NAME> " (the
- If you need to establish context (for example, you must be in a specific folder before running a command), use the following prompt:
Use the txt language for Windows console commands.
- Use "FOLDER_NAME>" (folder name, greater than symbol, no space after)
- Alternatively, do not include any prompt and start the line with the command the user must enter (knowing that it will be harder to understand what must be entered and what is example output)
- Examples:
- C:> command-to-run.exe
- C:\Program Files> command-to-run.exe
- C:\Users\JohnDoe> command-to-run.exe
Use json for JSON code blocks or JSON fragments.
Multi-line curl commands with a JSON body should use bash syntax highlighting instead.
You can add special formatting to code blocks, such as collapsed sections, line numbers, and highlighting. Here is a showcase of some of the functionality. You can find more options at Expressive Code ↗, a project by Astro.
Write-Output "This one has a title"// Collapsingconst foo = {3 collapsed lines
1: 1, 2: 2, 3: 3,};// Line numbersconst foo = "bar";const bar = "baz";// Example with wrapfunction getLongString() { return "This is a very long string that will most probably not fit into the available space unless the container is extremely wide";}function demo() { console.log("These are inserted and deleted marker types"); // The return statement uses the default marker type return true;}function thisIsJavaScript() { // This entire block gets highlighted as JavaScript, // and we can still add diff markers to it! console.log('Old code to be removed') console.log('New and shiny code!')}```powershell title="Write string example"Write-Output "This one has a title"```
```js collapse={3-5}// Collapsingconst foo = { 1: 1, 2: 2, 3: 3,};```
```js showLineNumbers// Line numbersconst foo = "bar";const bar = "baz";```
```js wrap// Example with wrapfunction getLongString() { return "This is a very long string that will most probably not fit into the available space unless the container is extremely wide";}```
```js "return true;" ins="inserted" del="deleted"function demo() { console.log("These are inserted and deleted marker types"); // The return statement uses the default marker type return true;}```
```diff lang="js" function thisIsJavaScript() { // This entire block gets highlighted as JavaScript, // and we can still add diff markers to it!- console.log('Old code to be removed')+ console.log('New and shiny code!') }```If you add the playground option to the opening code fence for a Worker example, it will add a "Run Worker in Playground" link that will take the user to the Worker's playground.
export default { fetch() { return new Response("Test!"); },};```js playgroundexport default { fetch() { return new Response("Test!"); },};```Add graphql-api-explorer to the opening code fence to create a graphql code block with a Run in GraphQL API Explorer button that leads to GraphQL API Explorer ↗.
query ASingleDatasetExample($zoneTag: string, $start: Time, $end: Time) { viewer { zones(filter: { zoneTag: $zoneTag }) { firewallEventsAdaptive( filter: { datetime_gt: $start, datetime_lt: $end } limit: 2 orderBy: [datetime_DESC] ) { action datetime host: clientRequestHTTPHost } } }}```graphql graphql-api-explorer title="A GraphQL query"query ASingleDatasetExample($zoneTag: string, $start: Time, $end: Time) { viewer { zones(filter: { zoneTag: $zoneTag }) { firewallEventsAdaptive( filter: { datetime_gt: $start, datetime_lt: $end } limit: 2 orderBy: [datetime_DESC] ) { action datetime host: clientRequestHTTPHost } } }}```In the GraphQL API Explorer, the Variables section is automatically filled based on the names and types of the variables defined in your query:
- Variables that include
startand are of typeTimeare set to six hours before the current time - Variables that include
endand are of typeTimeare set to the current time - Variables that include
startand are of typeDateare set to 24 hours before the current date - Variables that include
endand are of typeDateare set to the current date - Variables that include
zoneTagand are of typestringare set to "ZONE_ID" - Variables that include
accountTagand are of typestringare set to "ACCOUNT_ID" - Variables that include
idand are of typestringare set to "REPLACE_WITH_ID" - Variables that include
limitand are of typeintare set to 100 - Any other variable with a type of
stringis set to "REPLACE_WITH_STRING"
You can also add custom variables by setting their values as a JSON string in the graphql-api-explorer metadata. The custom variables will be merged with the automatically populated variables.
In the following example, the custom value is custom-variable:
```graphql graphql-api-explorer='{"uID": "custom-variable"}' title="A GraphQL query"query GraphqlExample($zoneTag: string, $start: Time, $end: Time) { viewer { zones(filter: { zoneTag: $zoneTag }) { ... } }}```So, the Variables would look something like this:
{"zoneTag":"ZONE_ID", "start":"2025-09-11T14:00:00Z", "end":"2025-09-11T20:00:00Z", "uId": "custom-variable"}Was this helpful?
- Resources
- API
- New to Cloudflare?
- Directory
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- © 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark
-