Code Blocks

Display code with syntax highlighting, line numbers, and highlighting.

Basic

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

Titles

Add a filename header with auto-detected language icons:

app.jsx
export default function App() {
  return <h1>Hello World</h1>
}
utils.py
def calculate(a, b):
    return a + b
deploy.sh
git push origin main

Line Numbers

Display line numbers for reference:

config.js
export default {
  title: "My Docs",
  description: "Documentation site",
  theme: "default"
}

Start from a specific line number:

app.js
function handleSubmit(event) {
  event.preventDefault();
  saveData(formData);
}

Line Highlighting

Draw attention to specific lines:

function example() {
  const highlighted = true;
  const normal = false;
  return highlighted;
}

Highlight ranges:

const first = 1;
const second = 2;
const third = 3;
const fourth = 4;
const fifth = 5;

Diff Markers

Show code changes with additions and deletions:

function greet(name) {
  return "Hello, " + name; 
  return `Hello, ${name}!`; 
}

Focus

Dim surrounding code to highlight what matters:

import { useState } from 'react';

function Counter() {
  const [count, setCount] = useState(0); 

  return (
    <button onClick={() => setCount(count + 1)}>
      Count: {count}
    </button>
  );
}

Error & Warning

Mark lines with errors or warnings:

const config = {
  title: "My Docs",
  descrption: "Typo here" 
}
const config = {
  legacyMode: true 
}

Annotations

Place (N) markers inside code comments and write a matching ordered list immediately after the code block. Both the markers and the list are removed from the rendered output – only the clickable icons and popovers remain.

docyard.yml
theme:
  name: docyard 
  features:
    - content.code.annotate 
    - navigation.tabs 

Annotation content supports full markdown. Use indentation (2+ spaces) to continue a list item across multiple lines:

server.js
const app = express(); 
app.listen(3000); 

Annotations work with all other code block features:

utils.ts
export function add(a: number, b: number) { 
  return a + b;
}
Important

The ordered list must immediately follow the code block. If there is other content between the closing fence and the list, the markers will render as plain text.


Combined Features

Mix and match any features:

utils.ts
export function calculate(a: number, b: number) {
  const sum = a + b;
  const product = a * b; 
  const diff = a - b; 
  return { sum, product, diff };
}

Code Imports

Import code directly from files in your docs directory:

<<< @/examples/config.js

Import a named region:

<<< @/examples/app.js#setup

Define regions in your source files:

// #region setup
const app = createApp();
app.use(router);
// #endregion setup

Import with line highlighting:

<<< @/examples/config.js {2-4}

Syntax

Basic fence:

```language
code here
```

With title:

```js [filename.js]
code here
```

With line numbers:

```js:line-numbers
code here
```

With highlights:

```js {1,3-5}
code here
```

Inline markers:

```js
const old = true; // [!code --]
const new = true; // [!code ++]
const focused = true; // [!code focus]
const broken = true; // [!code error]
const deprecated = true; // [!code warning]
```

Annotations:

```js
const app = createApp(); // (1)
```

1. Explanation for the annotated line.

Full syntax:

```language [title]:line-numbers {highlights}

Reference

Feature Syntax Description
Title [filename] Filename header with auto-detected icon
Line numbers :line-numbers Show line numbers
Start line :line-numbers=N Start numbering from N
Highlight {1,3-5} Highlight specific lines or ranges
Marker Syntax Effect
Addition // [!code ++] Green background
Deletion // [!code --] Red background
Focus // [!code focus] Dims other lines
Error // [!code error] Red error highlight
Warning // [!code warning] Yellow warning highlight
Annotation // (1) + ordered list Clickable popover with explanation
Import Syntax
File <<< @/path/file.js
Region <<< @/path/file.js#region-name
With highlights <<< @/path/file.js {1-3}
Edit this page
Last updated