Code Blocks Reference

Multi-language code tabs, Rosettes syntax themes, and advanced options

4 min read 767 words
Edit this page

Was this page helpful?

Advanced code presentation — multi-language tabs and syntax theme configuration.

Note

Do I need this? Use forcode-tabs, theme tuning, or Rosettes configuration. For everyday fenced code blocks, see Code Blocks.

Multi-Language Examples

Show the same concept in multiple languages with code tabs. Usecode-tabsfor a streamlined, code-first experience with auto-sync, language icons, and copy buttons.

Syntax

Tab labels are automatically derived from the code fence language—no extra markers needed:

MARKDOWN
:::{code-tabs}

```python
print("Hello")
```

```javascript
console.log("Hello");
```

```bash
echo "Hello"
```

:::

Result

PYTHON
def greet(name):
    """Say hello to someone."""
    print(f"Hello, {name}!")

greet("World")
JAVASCRIPT
function greet(name) {
    // Say hello to someone
    console.log(`Hello, ${name}!`);
}

greet("World");
BASH
# Say hello
greet() {
    echo "Hello, $1!"
}

greet "World"

With Filenames and Highlights

Add filenames and line highlights directly in the code fence info string:

PYTHON
import requests

def get_users():
    response = requests.get("/api/users")
    return response.json()
JAVASCRIPT
import fetch from 'node-fetch';

async function getUsers() {
    const response = await fetch('/api/users');
    return response.json();
}
BASH
# Get all users
curl -X GET "https://api.example.com/users" \
  -H "Authorization: Bearer $API_KEY"

Custom Tab Labels

Usetitle="..."to override the default language-derived label:

MARKDOWN
:::{code-tabs}

```javascript title="React"
const [count, setCount] = useState(0);
```

```javascript title="Vue"
const count = ref(0);
```

:::

Files Without Extensions

For files likeDockerfile that have no extension, use title=:

MARKDOWN
:::{code-tabs}

```dockerfile title="Dockerfile"
FROM python:3.14-slim
```

```yaml docker-compose.yml
services:
  web:
    build: .
```

:::

Code Tabs vs Tab-Set

Feature code-tabs tab-set
Syntax Just code fences Nested:::{tab-item}
Auto sync ✅ All code-tabs sync by language Manual with:sync:
Language icons ✅ Automatic Manual with:icon:
Copy button ✅ Built-in ❌ None
Line numbers ✅ Auto for 3+ lines ❌ None
Best for Code examples Mixed content

Tip

Usecode-tabs when you're showing the same concept in multiple programming languages. Use tab-setwhen tabs contain mixed content (text, images, etc.) or aren't code-focused.

Syntax Themes

Bengal's syntax highlighting uses Rosettes, which provides configurable themes that adapt to light/dark mode.

Available Themes

Theme Description Mode
bengal-tiger Bengal brand theme with orange accents Dark
bengal-snow-lynx Light variant with warm teal Adaptive
bengal-charcoal Minimal dark variant Dark
bengal-blue Blue accent variant Dark
monokai Classic warm, vibrant theme Dark
dracula Purple accent theme Dark
github GitHub's syntax theme Adaptive
github-light GitHub light mode only Light
github-dark GitHub dark mode only Dark

Configuration

Configure syntax highlighting inconfig/_default/theme.yaml:

YAML
theme:
  # Site palette (syntax inherits from this when theme is "auto")
  default_palette: "snow-lynx"

  syntax_highlighting:
    # Theme selection:
    # - "auto": Inherit from default_palette (recommended)
    # - Specific theme name: "monokai", "dracula", etc.
    theme: "auto"

    # CSS class output style:
    # - "semantic": Human-readable classes (.syntax-function, .syntax-string)
    # - "pygments": Pygments-compatible short classes (.nf, .s)
    css_class_style: "semantic"

Palette Inheritance

Whentheme: "auto" is set, the syntax theme automatically inherits from your site's default_palette:

Site Palette Syntax Theme
default/ empty bengal-tiger
snow-lynx bengal-snow-lynx
brown-bengal bengal-tiger
silver-bengal bengal-charcoal
charcoal-bengal bengal-charcoal
blue-bengal bengal-blue

CSS Class Styles

Rosettes supports two CSS class naming conventions:

Human-readable class names that describe the code element's purpose:

HTML
<span class="syntax-function">greet</span>
<span class="syntax-string">"Hello"</span>
<span class="syntax-keyword">def</span>

Best for: New projects, custom themes, semantic CSS.

Short class names compatible with existing Pygments themes:

HTML
<span class="nf">greet</span>
<span class="s">"Hello"</span>
<span class="k">def</span>

Best for: Migrating from Pygments, using existing Pygments CSS themes.

Note

Rosettes is designed for Python 3.14t free-threading with zero global mutable state. It provides thread-safe syntax highlighting with O(n) guaranteed parsing. See Rosettes Performance for benchmarks.

Seealso

Rosettes Documentation: