Skip to content
aq-ui
Back to EditorsEditor

Code Block

SSR-safe syntax-highlighted code with line numbers, diffs, emphasis, filenames, and copy support.

Preview

This is a live example. Interact with the available controls and use the keyboard to inspect the component's states and behavior.

Loading interactive preview…

Installation

pnpm dlx aq-ui@alpha add code-block

API reference

SSR-safe

Import the parts you need, then jump to an export for its contract.

View full source

Quick start

import { CodeBlock } from "@/components/ui/code-block"

<CodeBlock />

CodeBlock

functionSource L30

SSR-safe syntax-highlighted code with line numbers, diffs, emphasis, filenames, and copy support.

function CodeBlock({ code, language = "plaintext", filename, lineNumbers = false, wrapLines = false, highlightedLines: emphasizedLines = [], diff = "none", copyButton = true, maxHeight, onCopyError, className, style, ...props }: CodeBlockProps)
Props type
CodeBlockProps
<CodeBlock />

CodeBlockDiff

typeSource L12

Type contract for CodeBlockDiff.

type CodeBlockDiff = "none" | "added" | "removed" | "mixed"

CodeBlockLanguage

type

Type contract for CodeBlockLanguage.

export type { CodeBlockLanguage } from "@/lib/code-highlighter"
Provenance
Re-exported from @/lib/code-highlighter

CodeBlockProps

interfaceSource L14

Type contract for CodeBlockProps.

interface CodeBlockProps extends Omit< React.ComponentProps<"figure">, "children" >

Members

NameTypeDefault
codestring—
language?CodeBlockLanguage"plaintext"
filename?string—
lineNumbers?booleanfalse
wrapLines?booleanfalse
highlightedLines?readonly number[][]
diff?CodeBlockDiff"none"
copyButton?booleantrue
maxHeight?string | number—
onCopyError?(error: Error) => void—

normalizeHighlightLanguage

function

Public function export from Code Block.

export { normalizeHighlightLanguage } from "@/lib/code-highlighter"
Provenance
Re-exported from @/lib/code-highlighter

Registry dependencies

code-block-copy-button, code-highlighter, utils

Files

  • components/ui/code-block.tsx

Source