[data-reveal]{opacity:1!important;transform:none!important}
Code block
Components

Code block

Read-only code with syntax highlighting, a copy button and a height cap — static, or read from a route.

CodeBlock shows read-only code in the code editor's look: a head with the title, the language and a copy button, then the code highlighted. Long lines scroll sideways unless wrap is on, and maxLines caps the height. The code is written in the options, or read from a route that answers { code, language? } — a generated snippet, a stored configuration, a request body.

CodeCodeBlock
Connecting to the DMS preview…
ConnectingDMS 0.9.53 options set

Usage

src/pages/media.ts
import { CodeBlock } from "@antelopejs/interface-dms/base/code-block";

static preset = CodeBlock({
  title: "$media.presets.config",
  language: "json",
  maxLines: 12,
  fetchUrl: "/api/media/presets/{{params.id}}/config",
});

Options

Options of the Code block
OptionTypeDefaultDescription
titleContentstring | object–Head of the block.
codeContentstring–The code, verbatim.
languageContent"json" | "javascript" | "typescript" | "html" | "sql" | "shell" | …"text"Highlighting language.
copyFeaturesbooleantrueA button copies the code.
wrapAppearanceboolean–Wraps long lines.
maxLinesLayoutnumber–Lines shown before the code scrolls.

A route may answer a language under a common alias — js, ts, bash, sh, plain — and the block reads it; an unknown one is shown as plain text. While the first answer loads the block draws placeholder lines; a failure shows an error with a retry, and a 404 the not-found state.

Pitfalls

  • In a custom component, show code with the DmsCodeSnippet component rather than a <pre> and a copy button of your own.

Next steps

Empty state

A snippet to start with, inside an empty state.

UI toolkit

The same look in your own Vue.