Skip to content

Mermaid options, redirects and announcements are new.See the diagrams

ZenithDocs
English

Code blocks

Syntax highlighting, titles, line highlights, diffs and more.

On this page

Code blocks are highlighted at build time with Shiki, using a light and a dark theme that follow the site color scheme. No highlighting code is sent to the browser.

Titles

Add title="..." after the language to show a file name.

src/utils/greet.ts
export function greet(name: string) {
  return `Hello, ${name}!`;
}

Highlighting lines

Add // [!code highlight] at the end of a line, or list line numbers in the meta, like {1,3-4}.

const answer = 42;
const question = 'What is the meaning of life?';
console.log(question, answer);

Highlighting words

Use // [!code word:name] to highlight every occurrence of a word in the following line.

const config = defineConfig({ site: 'https://example.com' });
export default config;

Diffs

Mark added and removed lines with // [!code ++] and // [!code --].

astro.config.mjs
export default defineConfig({
  integrations: [
    starlight({ title: 'My Docs' }),
    zenith({ title: 'My Docs' }),
  ],
});

Focus

Blur everything but the important lines with // [!code focus]. Hover the block to reveal the rest.

import { defineCollection } from 'astro:content';
import { docsLoader, docsSchema } from 'zenith-docs/content';

export const collections = {
  docs: defineCollection({ loader: docsLoader(), schema: docsSchema() }), 
};

Line numbers

Add lineNumbers to the meta, optionally with a starting number: lineNumbers=10.

:root {
  --brand-500: oklch(58% 0.18 268);
  --radius-main: 0.625rem;
}

Copy button

Every code block gets a copy button, shown on hover. It is only rendered when JavaScript is available.

Package managers

Write a command once for npm, in a block whose language is npm, and readers get it for npm, pnpm, Yarn and Bun, in tabs:

```npm
npm install zenith-docs
npx astro dev
```

npm

npm install zenith-docs
npx astro dev

pnpm

pnpm add zenith-docs
pnpm dlx astro dev

yarn

yarn add zenith-docs
yarn dlx astro dev

bun

bun add zenith-docs
bunx astro dev

install, uninstall, run, exec and npx are rewritten for each package manager, and other commands keep their name. The tabs of a site switch together, and the choice is remembered across pages. Without JavaScript, every variant is shown with its name.

Last updated on