Code Blocks

CarvePress wraps fenced code in a consistent code-block UI, highlights with Shiki, and adds a copy button.

Highlighting

TypeScript
import { defineConfig } from '@markup-carve/carve-press'

export default defineConfig({
  title: 'Docs',
})

Highlight Lines

Use hl for one-based lines and ranges.

Highlighted Lines
const site = 'CarvePress'
const markup = 'Carve'
const output = 'static html'
console.log(site)
console.log(markup, output)

Line Numbers

Use .line-numbers on one fence, or set shiki.lineNumbers globally.

Numbered
export function build() {
  return 'site'
}

Use .no-line-numbers to opt out of global numbering.

Plain Text
This block stays unhighlighted and unnumbered.

Shiki Notation

Shiki notation comments style diffs, focused lines, highlighted lines, and errors. The copy payload strips the notation comments.

Notation
const removed = false
const added = true
const focused = 'important'
const marked = 'read this'
throw new Error('visible failure') 

Code Groups

Group alternatives with ::: code-group.

npm install --save-dev @markup-carve/carve-press
pnpm add -D @markup-carve/carve-press

Copy Button

Every block above has a copy button in the rendered site. The label can be localized through themeConfig.labels.copy and copied; see Internationalization.

Edit this page

Last updated