Octri

Code blocks

A fenced code block becomes a code panel, with syntax highlighting, a header naming the language, and a copy button. Name the language after the opening fence.

Example

python
client = Acme(api_key="sk_test_123")
customer = client.customers.get(id="cus_1")
mdx
```python
client = Acme(api_key="sk_test_123")
customer = client.customers.get(id="cus_1")
```

Options

languagestringdefault: plaintext

Written straight after the opening fence, such as ```bash. It picks the highlighting, and labels the panel. A language that isn't listed below shows as plain text, unhighlighted.

titlestringdefault: the language

A label for the panel's header instead of the language, such as a file name. Write it after the language: ```json title="package.json".

package.json
{ "dependencies": { "acme-api": "^2.4.0" } }
mdx
```json title="package.json"
{ "dependencies": { "acme-api": "^2.4.0" } }
```

Languages

LanguageWrite
Shellbash, or sh, shell, zsh, console, curl
PowerShellpowershell, or ps1
JavaScriptjavascript, or js
TypeScripttypescript, or ts
Pythonpython, or py
Gogo, or golang
Javajava
Kotlinkotlin, or kt
PHPphp
Rustrust, or rs
Rubyruby, or rb
Dartdart
Swiftswift
JSONjson, or jsonc
YAMLyaml, or yml
TOMLtoml
INIini
XMLxml
HTMLhtml
CSScss
SQLsql
GraphQLgraphql
Dockerfiledocker, or dockerfile
Diffdiff
Markdownmarkdown, or md
MDXmdx
Plain textplaintext, or text, txt

Colours

The highlighting follows your site's code theme, which you choose separately for light and dark in Appearance.

Showing backticks in a code block

A code block ends at the first line of three backticks, so it can't show three backticks as text. To write about Markdown itself, open and close the block with four backticks instead. The three-backtick lines inside then show as plain text:

What you write
````mdx
```bash
npm install acme-api
```
````

What readers see:

mdx
```bash
npm install acme-api
```
  • CodeGroup: several code blocks as tabs.
  • Tabs: when a tab also needs words.