UI.MD

Code Block

An opinionated, server-highlighted code block. Ships Shiki with the One Light / One Dark Pro theme pair, a copy button, optional line numbers, and dual-theme dark mode with zero client-side highlighting JavaScript.

Installation

$
npx shadcn@latest add https://ui.mattdowney.com/r/code-block.json

Usage

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

Examples

Default

import { Button } from "@/components/ui/button"

export function Example() {
  return <Button variant="outline">Click me</Button>
}

Line numbers

Prefix each line with its number via showLineNumbers.

import { Button } from "@/components/ui/button"

export function Example() {
  return <Button variant="outline">Click me</Button>
}

Languages

Bundled languages: tsx, ts, jsx, js, bash, css, json, html. An unknown language renders as plain text.

npx shadcn@latest add https://ui.mattdowney.com/r/button.json
{
  "name": "ui.md",
  "type": "registry:ui"
}

API Reference

PropTypeDefaultDescription
code*CodeBlockstring-The source to highlight. Leading and trailing whitespace is trimmed.
languageCodeBlockstring"tsx"Language grammar to highlight with. Bundled: tsx, ts, jsx, js, bash, css, json, html. Extend the LANGUAGES list in the source to add more; an unknown language falls back to plain text.
showLineNumbersCodeBlockbooleanfalsePrefixes each line with its line number.
classNameCodeBlockstring-Merged onto the Card frame.