[data-reveal]{opacity:1!important;transform:none!important}
AntelopeJS DMS
DocumentationCode block

Code block

Read-only code with syntax highlighting, a copy button and a height cap. The code is 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? }, such as a generated snippet, a stored configuration or a request body.

Code CodeBlock
Connecting to the DMS preview…
Connecting DMS 0.25.8 3 options set

Usage

src/pages/media.ts 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
title Contentstring | object–Head of the block.
code Contentstring–The code, verbatim.
language Content"json" | "javascript" | "typescript" | "html" | "sql" | "shell" | …"text"Highlighting language.
copy FeaturesbooleantrueA button copies the code.
wrap Appearanceboolean–Wraps long lines.
maxLines Layoutnumber–Lines shown before the code scrolls.

A route may answer a language under a common alias (js, ts, bash, sh or 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.