On this page
CodeBlock
Framed code with filename header and copy button.
Last updated:
codeBlock() renders a framed code figure with an optional filename header
and a ghost copy button. The copy button is wired by the runtime
([data-cpd-copy]).
With filename
Section titled “With filename”export const LAYOUT = {
sidebarWidth: 256,
tocWidth: 256,
pageMaxWidth: 800,
} as const;
codeBlock({ filename: 'src/lib/ui/tokens.ts', lang: 'ts', code: 'export const LAYOUT = {\n sidebarWidth: 256,\n tocWidth: 256,\n pageMaxWidth: 800,\n} as const;\n',});Without filename
Section titled “Without filename”bun install
bun run dev
codeBlock({ lang: 'bash', code: 'bun install\nbun run dev\n',});Snippet (multiple files)
Section titled “Snippet (multiple files)”Pass tabs to render a multi-file snippet: the header shows one tab per
file; the copy button copies the active tab.
export function renderDrawer(options) {
// ...
}
export function initDrawers(root) {
// ...
}
codeBlock({ lang: 'ts', tabs: [ { label: 'drawer.ts', code: 'export function renderDrawer(options) {\n // ...\n}\n' }, { label: 'runtime.ts', code: 'export function initDrawers(root) {\n // ...\n}\n' }, ],});code*string
tabs is omitted).filenamestring
''langstring
language-<lang>), no syntax highlighting.''tabsCodeBlockTab[]
{ label, code } per file; header renders tabs and the copy button copies the active tab.Markdown fences (Expressive Code)
Section titled “Markdown fences (Expressive Code)”Real docs pages render fences through Expressive Code (Shiki-based), themed
to match the kit: the frame follows --cpd-* tokens and the copy button is
the kit one. The codeBlock() builder above is for demo pages and other
non-Markdown surfaces; inside .md/.mdx prefer plain fences.
Titles, terminal frames and line numbers
Section titled “Titles, terminal frames and line numbers”A title meta renders a filename tab; shell languages get a terminal frame.
showLineNumbers enables line numbers per block:
export function greet(name) { return `Hello, ${name}!`;}Line marks and diffs
Section titled “Line marks and diffs”{lines} highlights whole lines or ranges; del={} / ins={} mark removed
and added lines — with optional labels for “before vs after” without a fake
diff fence:
const theme = 'light';const theme = 'dark';// keep an eye on this lineconst retries = 3;const cache = new Map();const TIMEOUT_MS = 5000;const CACHE_SIZE = 100;Use diff as the fence language for git-style blocks; -/+ prefixes get
removed/added styling. Attach a regular language to keep highlighting:
function greet(name: string) { return "Hello, " + name; return `Hello, ${name}!`;}Word marks highlight every occurrence of a quoted string; ins= / del=
mark inline additions and removals:
const retries = readConfig().attempts;log(`retrying, ${retries} attempts left`);Collapsible sections
Section titled “Collapsible sections”collapse={ranges} folds line ranges behind an expandable toggle:
2 collapsed lines
// …long header comment…// …another boilerplate line…function main() { console.log('visible');}// …trailing boilerplate…1 collapsed line
// …more trailing boilerplate…Theming
Section titled “Theming”Marker colors are driven by LCH hue tokens in astro.config.mjs
(insHue: 150, delHue: 25, gold mark background via customizeTheme),
aligned with the Plumest success / error / gold tokens — backgrounds, borders
and indicators derive per theme, no CSS overrides needed.
```js title="src/example.js" showLineNumbersexport function greet(name) { return `Hello, ${name}!`;}```File includes
Section titled “File includes”<!-- @include: … --> comments splice another file into the page at build
time — whole files, line slices, or named #region blocks. Include comments
are Markdown comments, so live expansion requires .md pages (MDX does not
support HTML comments); the forms:
<!-- @include: ./src/config/site.ts{10-25} --><!-- @include: ./src/config/site.ts{5-} --><!-- @include: ./src/config/site.ts{-4} --><!-- @include: ./src/example.ts#auth-config -->| Form | Meaning |
|---|---|
path | Whole file |
path{10-25} | Lines 10–25 (1-based, inclusive) |
path{5-} | Line 5 to the end |
path{-4} | Start to line 4 |
path#region | Between #region name and #endregion markers |
Notes:
- Paths resolve relative to the including file and must stay inside the workspace.
- Markdown targets (
md/mdx) splice as raw Markdown; any other target is wrapped in a code fence tagged with its extension. - Includes nest (recursively, with cycle detection); include comments inside fences stay literal; missing files and malformed ranges remain literal.
- The builder escapes
code— raw markup is never executed. - No syntax highlighting ships with the kit; the real docs pages use
astro-expressive-codeblocks instead (styled to match). - Copy uses
navigator.clipboardwith a fallbackexecCommand('copy').