OrbitDocs packages are coming to npm soon. Until then, run it from the GitHub repo →
Customize

Code blocks

Titles, tabs, line numbers, highlights and package-manager tabs in guide code blocks, and how to change the syntax theme or add MDX plugins.

Code blocks in guides are highlighted at build time with Shiki, through Fumadocs' default MDX pipeline. Everything on this page works in any .mdx file under content/, with no setup. The last sections show how to change the pipeline itself.

This page covers code blocks in guides. Code samples in the API reference are generated: see Code samples.

Add a title

```ts title="src/main.ts"
await app.listen(3000);
```

The title shows above the block, with an icon for the language.

Group blocks as tabs

Give consecutive code blocks a tab and they become one block with tabs:

```ts tab="TypeScript"
const res = await fetch('/v1/bookings');
```

```python tab="Python"
res = requests.get('/v1/bookings')
```

For tabs that mix code and prose, use the <Tabs> component. See Components.

Package-manager tabs

A block with the language npm becomes tabs for npm, pnpm, yarn and bun, with the command translated for each:

```npm
npm install @orbitdocs/nestjs
```

Line numbers and copy button

```ts lineNumbers
const a = 1;
const b = 2;
```

```ts lineNumbers=10
// numbering starts at 10
```

```bash noCopy
echo "no copy button on this block"
```

Highlight, diff and focus lines

Add a comment at the end of a line. The comment is removed from the output. word: goes on its own line and applies to the lines after it.

```ts
const client = createClient(); 
const key = process.env.API_KEY;
const old = 'v1'; 
const next = 'v2'; 
await client.connect(); 
```
CommentEffect
[!code highlight]Highlights the line.
[!code word:<text>]Highlights every occurrence of <text> in the lines that follow.
[!code ++] / [!code --]Marks the line as added or removed.
[!code focus]Blurs the other lines until the reader hovers over the block.

Use the comment syntax of the block's language: # [!code highlight] in Python or Bash.

Change the syntax theme

The default themes are github-light and github-dark. Pick others with codeBlocks in the config:

orbitdocs.config.ts
codeBlocks: {
  themes: { light: 'catppuccin-latte', dark: 'catppuccin-mocha' },
  // Language of a fence without one (default `plaintext`).
  defaultLanguage: 'ts',
},

Any Shiki theme name works. codeBlocks applies to guides and to the MDX files in reference/; the API reference highlights its own samples. Restart orbitdocs dev after changing it.

The other Shiki options (langs, langAlias, inline, transformers, …) go in lib/source.ts, as rehypeCodeOptions of orbitMdxOptions(). They are merged over codeBlocks:

lib/source.ts
import { orbitMdxOptions } from '@orbitdocs/next/mdx-plugins';
import { defineDocs } from 'fumadocs-mdx/macro';

const docs = defineDocs({
  dir: 'content',
  docs: {
    // …keep the schema, postprocess and lastModified options that are already here
    mdxOptions: orbitMdxOptions({
      rehypeCodeOptions: { langAlias: { conf: 'ini' } },
    }),
  },
  meta: { schema: metaSchema },
});

Always start from orbitMdxOptions

Setting mdxOptions replaces Fumadocs' default MDX options. orbitMdxOptions() takes the same options as Fumadocs' applyMdxPreset: it starts from the defaults, adds GitHub alerts and applies your changes. Without it you lose syntax highlighting, heading anchors, code tabs, the search structure and the alerts. Change it on both collections (content/ and reference/) to keep them alike.

Add MDX plugins

The default pipeline includes GitHub-flavored Markdown, heading anchors, image sizes, code tabs, package-manager tabs, search structure and Shiki highlighting. Math, diagrams and other syntax need a plugin.

Example: LaTeX math with KaTeX.

npm install remark-math rehype-katex katex
lib/source.ts
import rehypeKatex from 'rehype-katex';
import remarkMath from 'remark-math';

mdxOptions: orbitMdxOptions({
  remarkPlugins: [remarkMath],
  // rehypeKatex must run before Shiki: put it first.
  rehypePlugins: (plugins) => [rehypeKatex, ...plugins],
}),
app/global.css
@import 'katex/dist/katex.css';

remarkPlugins and rehypePlugins take a list, added to the defaults, or a function that receives the default list and returns the final one.

Plugins change how guides compile. They don't affect the API reference, or Ask AI and the docs MCP, which read the raw MDX source.

Code block options

WhereOptionDefault
Code fence metatitle="…"none
Code fence metatab="…"none
Code fence metalineNumbers, lineNumbers=<start>off
Code fence metanoCopycopy button shown
Languagenpmpackage-manager tabs
codeBlocks.themes in the config{ light, dark }github-light, github-dark
codeBlocks.defaultLanguage in the configlanguage of fences without oneplaintext
rehypeCodeOptions in lib/source.tsany other Shiki optionFumadocs' defaults

Next steps

Last updated on

On this page