A typed slip
Pass `code`, a `filename` and a language: the header, the copy button and the lines come with it. Keywords are typed in red, functions struck twice, strings underscored.
A typed slip taped to the page: the file name in a typewriter face, the code on a two-color ribbon (red keywords and numbers, black for the rest), line numbers in the margin and a diff mode where removed lines are struck through in red pencil and added ones ticked in green. Ships its own small lexer for tsx, ts, jsx, js, css, json and bash.
npx shadcn@latest add @wobko/code-block第一次使用?先把 registry 加进 components.json。 如何安装
Pass `code`, a `filename` and a language: the header, the copy button and the lines come with it. Keywords are typed in red, functions struck twice, strings underscored.
Removed lines are struck through in red pencil, added lines are ticked in green, and the header counts them. Copy puts the result on the clipboard.
The small lexer knows tsx, ts, jsx, js, css, json and bash. The language comes from the file name when you do not say. Long lines wrap with `wrap`.
A code slip inside a message: it takes the width of the column and scrolls sideways when a line is long.
A `figure` on a slip of paper, taped at the top. With `code` and no children it assembles a header (file name, `+/-` counts, copy button) and the content itself; with children you compose the parts.
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| code | string | - | The source. For a diff: unified diff lines (`+added`, `-removed`, ` context`). |
| language | "tsx" | "ts" | "jsx" | "js" | "css" | "json" | "bash" | "diff" | "text" | - | Default: from the file name, else plain text. Aliases (`typescript`, `sh`, `javascript`...) work. |
| filename | string | - | Typed at the top of the slip. |
| lineNumbers | boolean | false | Number the lines in the margin (generated content: never selected, never copied). |
| diff | boolean | - | Read the code as a diff. `language="diff"` turns it on too; give the code's own language with `filename`. |
| wrap | boolean | false | Wrap long lines instead of scrolling sideways. |
| startLine | number | 1 | The number of the first line. |
| copyable | boolean | true | Show the copy button of the default header. |
| stock / tape / edge / tilt / fastener / seed | PaperProps | - | It is a Paper: default `slip` stock with `tape="top"`. Any Paper prop works (a torn `receipt`, a kraft `stock`). |
The lines, in a scrolling `pre` (focusable, so the keyboard can scroll it) inside a host that draws the focus ring. Takes its own `code` and `language` to override the block's.
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| code | string | - | Show this instead of the block's code. |
| language | string | - | Language of `code`. |
CLI 会复制进你项目的文件。
正在加载源码