X Enterprises
nuxt-x-marketing

CodeBlock

Syntax-highlighted code block powered by Shiki, with optional language badge, copy-to-clipboard button, and SSR-safe ClientOnly fallback.

CodeBlock

The XMarkCodeBlock component renders a code sample using Shiki for syntax highlighting. It is SSR-safe — the highlighter runs only on the client behind a ClientOnly boundary, with a <pre> fallback that keeps the page readable until Shiki mounts. An optional copy button copies the raw code to the clipboard with a 2-second "copied" confirmation state.

Components

<XMarkCodeBlock />

Basic usage:

<XMarkCodeBlock
  :code="`const greeting = 'Hello, world!'\nconsole.log(greeting)`"
  language="javascript"
/>

With copy button:

<XMarkCodeBlock
  :code="snippet"
  language="vue"
  :show-copy="true"
/>

Props

PropTypeDefaultDescription
codestring— (required)The raw code string to highlight.
languagestring''Language identifier passed to Shiki (e.g. 'javascript', 'vue', 'bash', 'html', 'css', 'json', 'yaml', 'sql', 'markdown', 'typescript'). When empty, no language label / code-theme padding is shown.
showCopybooleanfalseShow the copy-to-clipboard button in the top-right corner.

AI Context

category: UI Elements
package: "@xenterprises/nuxt-x-marketing"
components:
  - XMarkCodeBlock
use-when: >
  Rendering a single code snippet on a marketing / docs / blog page with
  syntax highlighting and a copy-to-clipboard action. For inline paragraphs
  of mixed prose + code prefer inline `<code>` tags; for a full docs site
  reach for the dedicated docs layer instead.
typical-page-section: Inside a features grid, blog post, pricing FAQ, or technical marketing page.
Copyright © 2026