Code Block
Display syntax-highlighted code snippets using Shiki.
Shiki Reference ThemesExamples
Code Block Basics
@chatcn/codeblock
Line Selection Highlight
Use highlight
property for the line-selection highlight
@chatcn/codeblock-selection
Installation
pnpm dlx shadcn@latest add https://shadcn-collections.vercel.app/c/codeblock
Show Line Numbers
To show line numbers in your code block, add the following styles to your global.css
:
code {
counter-reset: step;
counter-increment: step 0;
margin: 0;
width: 100%;
}
code .line::before {
content: counter(step);
counter-increment: step;
width: 1rem;
margin-right: 1.5rem;
display: inline-block;
text-align: right;
color: gray;
}