Markdown Code Block

Fence renderer for the markdown item: the shadcn/ui code block with a language title and copy, highlighted with shiki. A fence that streams is tokenized line by line, so finished lines are never re-highlighted.

UImarkdown-code-blockView JSON

Fences render inside the shadcn/ui code block: a card with the language in the header and a copy action, so an answer looks like the docs code panels instead of a bare `<pre>`. Copy takes the current source, including while the fence is still streaming. The card is a typeset component, so typeset supplies the block spacing and the old `pre > code` rules no longer apply to fences. Tokens still arrive line by line: finished lines keep their tokens and only the open line is tokenized again, starting from the grammar state of the line before it, so the cost of a token is one line, not the block. The shipped languages are bash, css, diff, html, javascript, json, jsx, markdown, python, sql, tsx, typescript and yaml, with the usual aliases; anything else renders as plain text.

Preview

A fence carries its language into the renderer:

ts
export function greet(name: string) {  return `Hello, ${name}`}

Inline code and links stay in the flow.

Installation

Add the item with the shadcn CLI, or copy the source manually.

pnpm dlx shadcn@latest add litingyes/blocove/markdown-code-block

Requires a shadcn/ui project set up with Base UI primitives. Blocove is developed against the b0 preset, but it installs no base config or theme tokens: your own preset, fonts and colors stay in place.

Or install from the namespace after adding the registry: npx shadcn@latest add @blocove/markdown-code-block

This example also uses: markdown

pnpm dlx shadcn@latest add litingyes/blocove/markdown
Typography is provided by shadcn/typeset. Copy typeset.css next to your stylesheet, import it after Tailwind and add the .typeset-docs preset. See the Rich text editor setup.

API Reference

Props accepted by the exported components.

MarkdownCodeBlock

The fence renderer. The shell passes `language`, `code`, `streaming` and `complete`; register it through the shell's `components` map. The card root carries `data-language` and the header shows the language; the copy action copies the current source, including while the fence streams. Typeset supplies the block spacing, and the code block itself styles the fence.

Extends MarkdownCodeProps.

PropTypeDefault
languagestringRequired
codestringRequired
streamingboolean-
completeboolean-
classNamestring-