Code Block

Numbered Lines

A code block with line numbers drawn by a CSS counter in a pseudo-element, so selecting and copying takes the code only, without the digits.

  • code
  • line-numbers
  • counter
  • syntax

Preview

1440pxHost theme

Use it with AI

  1. 1. Copy the link.
  2. 2. Write to your agent in your own words and drop the link into the sentence.
  3. 3. The agent opens the link and installs the component from the registry.

put this in the header: https://vibeui.ru/c/codeblock-001?lang=en

lib/format.ts5 строк
export function formatPrice(value: number) {  // цены храним в копейках  const rubles = value / 100  return rubles.toFixed(2) + " ₽"}
Show the full instructions

What the link says, spelled out. Use it when your agent cannot open links — paste this text instead.

# Install and place "codeblock-001" (Numbered Lines) from VibeUI

## 1. Install first — do not skip, do not recreate
Run this exact command before writing any code:
npx shadcn@latest add https://vibeui.ru/r/codeblock-001.json

Registry item: https://vibeui.ru/r/codeblock-001.json
Installs to: components/vibeui/codeblock-001.tsx (the exact path follows this project's components.json aliases).
npm dependencies: none.
Registry dependencies: none.

Install it from the registry. Do not recreate it from the description,
do not substitute a similar component from another library, and do not
rewrite it to match the project's existing style.

## 2. What it is
A code block with line numbers drawn by a CSS counter in a pseudo-element, so selecting and copying takes the code only, without the digits.

A dark code block with line numbers that are not copied: they are CSS counter pseudo-elements. Highlighting comes from tokens in the data, zero dependencies, no client JS.

## 3. How to use it
import { Codeblock001 } from "@/components/vibeui/codeblock-001"

<Codeblock001 title="lib/format.ts" start={1} />

Read the installed file for the full prop list.

## 4. Where to place it
This is a small inline component. Put it exactly where the user asked,
inside the existing markup. Do not create a new page, section or
wrapper for it. If a similar control already sits in that spot,
replace it instead of adding a second one.

Placement: ___
(The user fills this line in. If it is still blank, ask where to put it
instead of guessing.)

## 5. Keep exactly as installed
- the local --vibeui-codeblock-001-* palette — do not swap it for your theme tokens
- line numbers in ::before: moved into the markup they end up in the clipboard with the code
- user-select:none on the numbers — otherwise a double click grabs the digit
- the monospaced face and tabular-nums: without them the number column keeps shifting
- horizontal scrolling instead of wrapping: with numbering a wrapped line lies about them
- the block's own dark surface: without it light code disappears on a light page

## 6. You may change
- the code and its highlighting through the lines array, where a token carries kind
- the block heading through title
- the first number through start when you show a fragment from the middle of a file
- the token colours and the maximum block width

## 7. Rules
- Highlighting parses nothing: token kind is set by hand or by a build-time generator.
- The counter resets on the whole pre, so two listings inside one block continue the same numbering.
- Very long lines go into horizontal scrolling — a deliberate trade for correct numbers.
- Do not lift the CSS variables into globals.css: the component has to stay a single file.

## 8. Verify
- it renders with no console errors;
- it looks like the preview on the VibeUI page you copied this from;
- if it does not, you changed something listed in section 5 — put it back.

For developers

npx shadcn@latest add https://vibeui.ru/r/codeblock-001.json
https://vibeui.ru/r/codeblock-001.json

Компонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-codeblock-001-*. Серверный: хуков нет. Каждая строка — span с display:block внутри pre > code; номер печатает ::before через counter-increment, поэтому он не входит в выделение и не уезжает в буфер обмена. Начало нумерации передаётся в counter-reset переменной, посчитанной из пропса start. Подсветка сделана разметкой, а не парсером: строки приходят массивом токенов с полем kind, цвета вешаются селекторами [data-token].

Component source

The same file your agent installs. Here in case you would rather copy it by hand.

import type { ComponentPropsWithoutRef, CSSProperties } from "react"

export type Codeblock001Token = {
  text: string
  kind?: "keyword" | "string" | "comment" | "number" | "entity"
}

export type Codeblock001Props = Omit<
  ComponentPropsWithoutRef<"figure">,
  "children" | "title"
> & {
  title?: string
  start?: number
  lines?: Codeblock001Token[][]
}

// Идея компонента: нумерация строк, которая не попадает в буфер обмена.
// Номера нарисованы счётчиком CSS в псевдоэлементе, поэтому выделение мышью
// захватывает только код — вставленный фрагмент остаётся рабочим.
const STYLES = `
:where([data-vibeui-block="codeblock-001"]){
--vibeui-codeblock-001-bg:oklch(0.21 0.028 275);
--vibeui-codeblock-001-head:oklch(0.25 0.03 275);
--vibeui-codeblock-001-fg:oklch(0.93 0.008 275);
--vibeui-codeblock-001-muted:oklch(0.68 0.018 275);
--vibeui-codeblock-001-gutter:oklch(0.52 0.03 275);
--vibeui-codeblock-001-rule:oklch(1 0 0 / 10%);
--vibeui-codeblock-001-border:oklch(1 0 0 / 14%);
--vibeui-codeblock-001-keyword:oklch(0.78 0.13 305);
--vibeui-codeblock-001-string:oklch(0.83 0.13 145);
--vibeui-codeblock-001-comment:oklch(0.61 0.02 275);
--vibeui-codeblock-001-number:oklch(0.84 0.12 72);
--vibeui-codeblock-001-entity:oklch(0.83 0.11 235);
--vibeui-codeblock-001-mono:ui-monospace,SFMono-Regular,Menlo,Consolas,"Liberation Mono",monospace;
--vibeui-codeblock-001-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="codeblock-001"]{
display:flex;flex-direction:column;
width:100%;max-width:34rem;box-sizing:border-box;margin:0;overflow:hidden;
border:1px solid var(--vibeui-codeblock-001-border);border-radius:0.75rem;
background:var(--vibeui-codeblock-001-bg);color:var(--vibeui-codeblock-001-fg);
font-family:var(--vibeui-codeblock-001-font);
}
[data-vibeui-block="codeblock-001"] [data-part="head"]{
display:flex;align-items:center;justify-content:space-between;gap:0.75rem;
padding:0.5rem 0.875rem;
background:var(--vibeui-codeblock-001-head);
border-bottom:1px solid var(--vibeui-codeblock-001-rule);
font-size:0.75rem;color:var(--vibeui-codeblock-001-muted);
}
[data-vibeui-block="codeblock-001"] [data-part="name"]{
font-family:var(--vibeui-codeblock-001-mono);letter-spacing:0.01em;
}
[data-vibeui-block="codeblock-001"] [data-part="count"]{
font-variant-numeric:tabular-nums;
}
[data-vibeui-block="codeblock-001"] pre{
margin:0;padding:0.75rem 0.875rem 0.875rem 0;
overflow-x:auto;counter-reset:line var(--vibeui-codeblock-001-start,0);
}
[data-vibeui-block="codeblock-001"] code{
display:block;min-width:max-content;
font-family:var(--vibeui-codeblock-001-mono);
font-size:0.8125rem;line-height:1.7;white-space:pre;
}
[data-vibeui-block="codeblock-001"] [data-part="row"]{
display:block;padding-inline-start:3.5rem;position:relative;
}
/* Номер живёт в ::before: выделение и копирование его не захватывают. */
[data-vibeui-block="codeblock-001"] [data-part="row"]::before{
counter-increment:line;content:counter(line);
position:absolute;left:0;width:2.75rem;
text-align:right;color:var(--vibeui-codeblock-001-gutter);
font-variant-numeric:tabular-nums;
user-select:none;-webkit-user-select:none;pointer-events:none;
}
[data-vibeui-block="codeblock-001"] [data-part="row"]:hover{background:oklch(1 0 0 / 5%)}
[data-vibeui-block="codeblock-001"] [data-token="keyword"]{color:var(--vibeui-codeblock-001-keyword)}
[data-vibeui-block="codeblock-001"] [data-token="string"]{color:var(--vibeui-codeblock-001-string)}
[data-vibeui-block="codeblock-001"] [data-token="comment"]{color:var(--vibeui-codeblock-001-comment);font-style:italic}
[data-vibeui-block="codeblock-001"] [data-token="number"]{color:var(--vibeui-codeblock-001-number)}
[data-vibeui-block="codeblock-001"] [data-token="entity"]{color:var(--vibeui-codeblock-001-entity)}
`

const LINES: Codeblock001Token[][] = [
  [
    { text: "export function ", kind: "keyword" },
    { text: "formatPrice", kind: "entity" },
    { text: "(value: " },
    { text: "number", kind: "entity" },
    { text: ") {" },
  ],
  [{ text: "  // цены храним в копейках", kind: "comment" }],
  [
    { text: "  const", kind: "keyword" },
    { text: " rubles = value / " },
    { text: "100", kind: "number" },
  ],
  [
    { text: "  return", kind: "keyword" },
    { text: " rubles.toFixed(" },
    { text: "2", kind: "number" },
    { text: ") + " },
    { text: '" ₽"', kind: "string" },
  ],
  [{ text: "}" }],
]

/** Блок кода с нумерацией строк, которая не копируется вместе с кодом. */
export function Codeblock001({
  title = "lib/format.ts",
  start = 1,
  lines = LINES,
  className,
  style,
  ...props
}: Codeblock001Props) {
  const palette = {
    "--vibeui-codeblock-001-start": start - 1,
    ...style,
  } as CSSProperties

  return (
    <>
      <style href="vibeui-codeblock-001" precedence="medium">
        {STYLES}
      </style>
      <figure
        {...props}
        data-vibeui-block="codeblock-001"
        className={className}
        style={palette}
      >
        <figcaption data-part="head">
          <span data-part="name">{title}</span>
          <span data-part="count">{lines.length} строк</span>
        </figcaption>
        <pre>
          <code>
            {lines.map((line, index) => (
              <span data-part="row" key={index}>
                {line.map((token, position) => (
                  <span key={position} data-token={token.kind}>
                    {token.text}
                  </span>
                ))}
              </span>
            ))}
          </code>
        </pre>
      </figure>
    </>
  )
}