Code
Shiki-highlighted code that follows light and dark through light-dark() token colors, as a block, an inline one-liner or a tabbed file panel. Line numbers (from any start line), tinted lines with an accent bar, <mark>ed words or column ranges, and per-line notes in a tooltip that keyboard users can tab to. Optional Prettier at display time; copy hands out exactly what is shown.
import { Elysia, t } from "elysia";import { cors } from "@elysiajs/cors";Remember to add it: bun add @elysiajs/corsimport { db } from "./db";const app = new Elysia() .use(cors()) .get("/clips", () => db.clips.list()) .post("/clips", ({ body }) => db.clips.create(body), {The schema validates the body and types it for the handler. body: t.Object({ title: t.String({ minLength: 1 }), url: t.String({ format: "uri" }), }), }) .listen(3000);console.log(`Clips API on :${app.server?.port}`);import { Code } from "@/components/ui/code";const server = `import { Elysia, t } from "elysia";import { cors } from "@elysiajs/cors";new Elysia() .use(cors()) .post("/clips", ({ body }) => body, { body: t.Object({ title: t.String() }), }) .listen(3000);`;export function ServerSnippet() { return ( <Code code={server} language="ts" lineNumbers highlight={[[6, 8]]} marks={["t.Object", { line: 9, start: 2, end: 15 }]} notes={{ 2: "Remember to add it: bun add @elysiajs/cors" }} /> );}import { Code } from "@/components/ui/code";// An excerpt from line 42 of a file: numbers, highlights and notes use the shown numbers.export function Excerpt({ code }: { code: string }) { return <Code code={code} language="ts" lineNumbers={42} highlight={[44]} />;}<Code>
Syntax-highlighted code with light/dark themes, line annotations and an in-place copy button.
code*stringSource to highlight.
formatbooleanRun Prettier (default options) before highlighting; copy gets the formatted code too. Line numbers in
highlight,marksandnotesrefer to the formatted code.highlightLineRange[]Lines to tint, with a primary bar on the left.
languagedefault"tsx"stringShiki language id, e.g. "tsx", "bash", "json".
lineNumbersnumber | booleanGutter numbers; a number sets the first line's number (for excerpts).
marksCodeMark[]Words or ranges inside lines, wrapped in <mark>.
notesRecord<number, ReactNode>Hover/focus note per line number:
{ 4: "Remember to add it to the registry" }.tokensCodeToken[][]Lines from
highlightCode(code, language), made on the server or at build time: the code renders highlighted from the first paint and Shiki never loads. Ignored withformat.variantdefault"block""block" | "inline""block": header with language and copy. "inline": one line with a copy button.
| Prop | Type | Default |
|---|---|---|
code*Source to highlight. | string | — |
formatRun Prettier (default options) before highlighting; copy gets the formatted code too. Line numbers in | boolean | — |
highlightLines to tint, with a primary bar on the left. | LineRange[] | — |
languageShiki language id, e.g. "tsx", "bash", "json". | string | "tsx" |
lineNumbersGutter numbers; a number sets the first line's number (for excerpts). | number | boolean | — |
marksWords or ranges inside lines, wrapped in <mark>. | CodeMark[] | — |
notesHover/focus note per line number: | Record<number, ReactNode> | — |
tokensLines from | CodeToken[][] | — |
variant"block": header with language and copy. "inline": one line with a copy button. | "block" | "inline" | "block" |
<CopyButton>
Ghost "Copy" button that turns into "Copied" in place. Shared with Terminal.
code*stringText written to the clipboard.
labeldefault"Copy code"stringAccessible name of the button.
| Prop | Type | Default |
|---|---|---|
code*Text written to the clipboard. | string | — |
labelAccessible name of the button. | string | "Copy code" |
<CodePanel>
File panel: one tab per file, copy for the active one. Every file stays in the DOM.
files*CodeFile[]One tab per file, each with its own annotations. Switching animates the body.
collapsenumberFold files longer than this many lines (by at least 5) behind a "Show all" button. The body never scrolls vertically, so the wheel and touch keep scrolling the page.
formatbooleanRun Prettier on JS/TS files before highlighting; copy gets the formatted code too.
| Prop | Type | Default |
|---|---|---|
files*One tab per file, each with its own annotations. Switching animates the body. | CodeFile[] | — |
collapseFold files longer than this many lines (by at least 5) behind a "Show all" button. The body never scrolls vertically, so the wheel and touch keep scrolling the page. | number | — |
formatRun Prettier on JS/TS files before highlighting; copy gets the formatted code too. | boolean | — |
- type LineRange
- number | [from: number, to: number]
- type CodeMark
- | string | { text: string; line?: number } | { line: number; start: number; end: number }
- type CodeFile
- Annotations & { name: string; code: string; tokens?: CodeToken[][]; }
* required. Every component also takes className.