Skip to main content
CodivDocs

Code Blocks

Syntax highlighting, copy button, and language badge on every fenced code block.

What you get for free

Any fenced code block in your MDX gets three things automatically — no imports, no wrapper components, no config.

Syntax highlighting

Theme-aware colors via Prism, scoped to each tenant's --docs-* tokens.

Copy button

Hover-revealed copy button in the top-end corner. Success state for 1.8 seconds.

Language badge

Small monospace label in the top-start corner showing the language name.

Writing code blocks

Standard markdown fences with a language tag. The language tag drives both the syntax highlighter and the badge.

```typescript
export function greet(name: string): string {
  return `Hello, ${name}!`;
}
```

Produces:

export function greet(name: string): string {
  return `Hello, ${name}!`;
}

Supported languages

The Prism grammar set is loaded client-side on docs sites. Current set:

Shell

bash

Data

json, yaml

Web

typescript, tsx, jsx, css

Systems

go, rust, java

Scripting

python

Other

sql, markdown

Need another language? Open an issue on GitHub — Prism has grammars for most popular languages and adding one is a single import line.

Grouping multiple languages

Use <CodeGroup> to show the same code in different languages with tabs. See the CodeGroup component docs.

Theme integration

Syntax colors are not hard-coded. Prism token classes (.token.keyword, .token.string, etc.) are mapped to --docs-* CSS variables in prose-docs, so the highlighting:

  • Automatically adapts to the reader's light/dark theme choice

  • Uses your tenant primary color for keywords

  • Uses your configured success/warning colors for strings and numbers

  • Stays subtle (Linear-style muted hues, not a "christmas tree" explosion)

Copy button behavior

The copy button sits in the top-end corner of every code block. It is hidden until the reader hovers over the block (or focuses it via keyboard), then reveals. Clicking copies the raw code (without the language tag or badge) to the system clipboard via the Clipboard API. On success the icon swaps to a checkmark for ~2 seconds.

The button relies on navigator.clipboard.writeText, which requires HTTPS or localhost. If the Clipboard API is blocked by the browser (very rare), the button silently fails — the code still renders normally.

Last updated April 12, 2026