```
### registerLanguage
_function_
Adds your own language or replaces a built-in one. Rules are ordered; the
first rule matching at a position wins. Call it once at app start.
```ts
registerLanguage(name: string, grammar: CodeGrammar, label?: string): void
```
- name - Name used in the `language` prop (case insensitive).
- grammar - The language rules. See `CodeRule`.
- label - Name shown in the header. @defaultValue `name`
```ts
registerLanguage("prisma", [
{ type: "comment", pattern: /\/\/.+/ },
{ type: "keyword", pattern: /\b(?:model|enum|datasource|generator)\b/ },
{ type: "type", pattern: /\b(?:String|Int|Boolean|DateTime)\b/ },
{ type: "meta", pattern: /@@?\w+/ },
], "Prisma");
```
### CodeLineSelection
_type_
Line selection: line numbers and ranges. An array (`[1, [4, 6]]`) or a
string (`"1,4-6"`). Numbers are the line numbers shown on screen (relative
to `startLine`).
```ts
type CodeLineSelection = string | readonly (number | readonly [number, number])[]
```
### CodeBlockClassNames
_type_
Classes that can be given to the inner parts of `CodeBlock`.
| Property | Type | Default | Description |
| --- | --- | --- | --- |
| `header?` | `string` | | Top strip holding the title, language name and copy button. |
| `title?` | `string` | | Title text. |
| `viewport?` | `string` | | Area where the code scrolls (e.g. padding). |
| `pre?` | `string` | | The `` element (e.g. font size: `text-sm`). |
| `line?` | `string` | | Each line. |
| `copyButton?` | `string` | | Copy button. |
### CodeBlockProps
_type_
Props of the `CodeBlock` component.
Also accepts the properties of: `Omit, "title" | "children" | "onCopy">`
| Property | Type | Default | Description |
| --- | --- | --- | --- |
| `code` | `string` | | Code to show. A single leading and trailing blank line is trimmed. |
| `language?` | `CodeLanguage` | | Highlighting language: `tsx`, `ts`, `js`, `json`, `html`, `css`, `bash`, `python`, `sql`, `md`, `yaml`, `diff`, `go`, `rust`, `java`, `kotlin`, `c`, `cpp`, `csharp`, `php`, `ruby`, `swift`, `graphql`, `dockerfile`, `toml`… Each language loads only when used. An unknown name or `"text"` shows as plain text. For your own language see `registerLanguage`. |
| `title?` | `ReactNode` | | Title shown in the top strip, usually a file name (`"app/page.tsx"`). |
| `icon?` | `IconProp` | | Icon left of the title: a name or an element. When given, the top strip is shown. |
| `lineNumbers?` | `boolean` | `false`; `true` in diff mode (when `original` is given)` | Show line numbers. Numbers aren't selected or copied. |
| `startLine?` | `number` | `1` | Number of the first line. |
| `highlightLines?` | `CodeLineSelection` | | Lines to highlight: `[3, [5, 7]]` or `"3,5-7"`. Ignored in diff mode. |
| `addedLines?` | `CodeLineSelection` | | Lines shown as inserted (green). With `language="diff"` `+` lines are marked automatically. |
| `removedLines?` | `CodeLineSelection` | | Lines shown as deleted (red). With `language="diff"` `-` lines are marked automatically. |
| `wrap?` | `boolean` | `false` | Wrap long lines instead of scrolling. |
| `maxHeight?` | `number \| string` | | Code taller than this scrolls vertically (`320`, `"50vh"`). |
| `maxLines?` | `number` | | If the code is longer than this many lines only the first lines are shown, with a "Show all" button below. So long examples don't take over the page (especially on mobile). |
| `original?` | `string` | | Old code to compare with. When given the block switches to diff mode: `code` is the new state, deleted lines are red, inserted ones green, and changed words within a line are also highlighted. The diff is found with the library's own algorithm (Myers, the one git uses); the code is still highlighted with `language`. The header shows `+inserted −deleted` counts. |
| `diffView?` | `CodeDiffView` | `"unified"` | Diff view: `"unified"` shows old and new lines stacked in one column, `"split"` shows old on the left and new on the right. `"split"` becomes `"unified"` automatically on narrow screens (below 640 px). |
| `contextLines?` | `number \| false` | `3` | Number of unchanged lines shown around changes in diff mode; longer unchanged regions collapse as "12 unchanged lines" and expand on click. `false` shows everything. |
| `copyable?` | `boolean` | `true` | Show the copy button. |
| `onCopy?` | `(code: string) => void` | | Called with the copied text when the code is copied. |
| `classNames?` | `CodeBlockClassNames` | | Classes added to the inner parts. |
### CodeDiffView
_type_
Diff view: one column (`unified`) or side by side (`split`).
```ts
type CodeDiffView = "unified" | "split"
```
### CodeLanguageName
_type_
Canonical names of the languages built into the library.
```ts
type CodeLanguageName = keyof typeof loaders
```
### CodeLanguage
_type_
The `language` prop of `CodeBlock`: a built-in language name or alias
(`ts`, `py`, `sh`, `yml`…), a language added with `registerLanguage`,
or plain text that is not colored (`"text"`).
```ts
type CodeLanguage = CodeLanguageName | keyof typeof aliases | "text" | (string & {})
```
### CodeTokenType
_type_
Highlighted token kinds. Each kind is colored by a `--ui-code-*` theme
variable (e.g. `keyword` → `--ui-code-keyword`).
```ts
type CodeTokenType = "comment" | "keyword" | "string" | "number" | "constant" | "function" | "type" | "builtin" | "variable" | "property" | "operator" | "punctuation" | "tag" | "attr" | "regex" | "meta" | "inserted" | "deleted" | "heading" | "bold" | "italic" | "link"
```
### CodeRule
_type_
A language rule.
| Property | Type | Default | Description |
| --- | --- | --- | --- |
| `type?` | `CodeTokenType` | | Kind of the matched text; plain text when `undefined`. With `inside`, text the inner language cannot match gets this kind. |
| `pattern` | `RegExp` | | Pattern to match. All rules combine into one expression with the `gm` flags (`^` and `$` are line start/end); the `i` flag is supported, others are ignored. Do not use back references (`\1`): numbers shift when combined; capture groups are fine. |
| `inside?` | `CodeGrammar \| (() => CodeGrammar)` | | Also highlight the matched text with this language (e.g. `${…}` in a template string, `