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 Shiki core and JavaScript regex engine are part of the statically imported /content entry; supported grammar and theme modules load on demand. Unknown languages render as escaped plain text. 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. Importing any named component from @yuhuanowo/yunui/content requires the entry's static peer dependencies listed in the Content install guide.
Import
The compact surface uses 14px code and no decorative window dots. Up to 16 lines remain fully visible; longer blocks start with 8 lines. Expand/collapse preserves reading position. Copy and Edit always receive the full original string, including indentation and blank lines. Hosts can override disclosure, scroll and failure messages through the content.codeBlock.* translation keys.
import { CodeBlock, InlineCode } from "@yuhuanowo/yunui/content";Example
CodeBlock
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
| Prop | Type | Default | Description |
|---|---|---|---|
| children* | string | — | The code to render, as a string. |
| language | string | — | Language id for highlighting (e.g. tsx, python, bash). |
| filename | string | — | Shown in the block header; also passed to onEdit. |
| showLineNumbers | boolean | false | Render a line-number gutter. |
| highlightLines | number[] | — | 1-based line numbers to emphasize. |
| onEdit | (payload: CodeBlockEditPayload) => void | — | When set, shows an Edit button that calls this with { code, language, filename }. |
| className | string | — | Extra classes on the wrapper. |