# Code blocks

> Every code block variant bitidocs supports.

## Title and highlighting

```ts title="client.ts" {3-4}
import Acme from "acme";

const acme = new Acme({ apiKey: process.env.ACME_KEY });
const payment = await acme.payments.retrieve("pay_3Jk2Lm");
console.log(payment.status, 42);
```

```js
console.log("hello acme");
```

## Focus and notations

```javascript focus={2-3}
const client = createClient();
const result = await client.search("rate limits");
render(result.hits);
client.close();
```

```ts title="config.ts"
export default defineConfig({
  theme: "classic", // [!code --]
  theme: "modern", // [!code ++]
  accent: "#7C5CFF", // [!code ++]
  retries: 3, // [!code highlight]
});
```

```py
def total(items):
    return sum(item.price for item in item)  # [!code error]
    print("unreachable")  # [!code warning]
```

## Shell prompts

```bash
curl -X POST https://api.acme.dev/v1/payments \
     -H "Authorization: Bearer $ACME_KEY" \
     -d amount=2500
npm install @acme/node
```

```bash showLineNumbers={false}
pnpm add acme
acme login
```

## Long lines

```txt title="Without wordWrap"
A very very very long line of text that may cause the code block to overflow and scroll as a result of its length.
```

```txt title="With wordWrap" wordWrap
A very very very long line of text that may cause the code block to overflow and scroll as a result of its length.
```

## Max lines and start line

```python maxLines=8
def is_prime(num):
    """Check if a number is prime."""
    if num <= 1:
        return False
    for i in range(2, num):
        if num % i == 0:
            return False
    return True

start = 10
end = 50
print(f"Prime numbers between {start} and {end} are:")
for num in range(start, end + 1):
    if is_prime(num):
        print(num)
```

```yaml title="docs.yml" maxLines=5 collapsible
title: Acme Payments
colors:
  accent-primary:
    light: "#7C5CFF"
    dark: "#9E8AFF"
navigation:
  - tab: guides
  - tab: api
```

```javascript startLine={12}
console.log("Line 1");
console.log("Line 2");
console.log("Line 3");
console.log("Line 4");
console.log("Line 5");
console.log("Line 6");
console.log("Line 7");
console.log("Line 8");
console.log("Line 9");
console.log("Line 10");
console.log("Line 11");
console.log("Line 12");
console.log("Line 13");
console.log("Line 14");
console.log("Line 15");
console.log("Line 16");
console.log("Line 17");
console.log("Line 18");
console.log("Line 19");
console.log("Line 20");
console.log("Line 21");
console.log("Line 22");
console.log("Line 23");
console.log("Line 24");
```

## CodeBlock component and links

**charge.ts**

```ts
import Acme from "acme";
const acme = new Acme(process.env.ACME_KEY);
```

## Embedded file

`snippets/example-code.js`

`snippets/example-code.js`

## Code groups (synced)

```python title="Python"
print("First code block!")
```

```typescript title="TypeScript"
console.log("First code block!");
```

```go title="Go"
fmt.Println("First code block!")
```

```python Python
print("Second code block - syncs with the one above!")
```

```typescript TypeScript
console.log("Second code block - syncs with the one above!");
```

```go Go
fmt.Println("Second code block - syncs with the one above!")
```

## Mermaid

```mermaid
graph LR
  A[Write MDX] --> B[biti build]
  B --> C[Publish]
```
