YuhuanStudioYunUIDocs
Content

Code Block

Shiki-highlighted code block with a filename header, line numbers, line highlighting, copy and an optional edit action.

A syntax-highlighted code block powered by Shiki. The highlighter is loaded on demand the first time a block renders, so it never ships in the initial bundle. Shows an optional filename header, line numbers, highlighted lines, a copy button, and — when you pass onEdit — an "Edit" action that hands back the code payload. Pass the code as the child string.

Import

tsx
1import { CodeBlock, InlineCode } from "@yuhuanowo/yunui/content";

Example

CodeBlock

button.tsx
export function Button({ label }: { label: string }) {
return <button className="btn btn-primary">{label}</button>;
}

Inline code

InlineCode renders a single token inside prose.

InlineCode

Run pnpm build then restart the dev server.

Props

PropTypeDefaultDescription
children*stringThe code to render, as a string.
languagestringLanguage id for highlighting (e.g. tsx, python, bash).
filenamestringShown in the block header; also passed to onEdit.
showLineNumbersbooleanfalseRender a line-number gutter.
highlightLinesnumber[]1-based line numbers to emphasize.
onEdit(payload: CodeBlockEditPayload) => voidWhen set, shows an Edit button that calls this with { code, language, filename }.
classNamestringExtra classes on the wrapper.

On this page