Fine-tune light, shadows, borders, neumorphic
Light and shadows
Borders
Neumorphic
Display

CodeBlock <pm-code-block>

Code snippet with syntax colours, Wrap and Copy buttons, and optional line numbers. It sits in the page as a well of the surface in use, in the page's text colours, like the code on prismora.design.

Full screen
import { defineTheme } from '@prismora/theme'; // One seed colour makes the whole palette. export default defineTheme({ seed: '#7c5cff', surface: 'glass', radius: 'rounded', });

Props

<script type="module"> import '@prismora/css'; import '@prismora/elements/code-block'; </script> <pm-code-block label="theme.ts" line-numbers style="inline-size: min(100%, 34rem)">import { defineTheme } from '@prismora/theme'; // One seed colour makes the whole palette. export default defineTheme({ seed: '#7c5cff', surface: 'glass', radius: 'rounded', });</pm-code-block>

Overview

Put the code in the code property, or as text inside the element (escape < as &lt; in HTML). The language is detected when not given. Long snippets can start collapsed with max-lines.

Attributes

AttributeTypeDefaultDescription
codestring—The code to show. When not set, the element's text content is used.
language'markup' | 'js' | 'css' | 'shell' | 'json' | 'text'—markup (HTML, Vue, Svelte), js (also TypeScript and JSX), css, shell, json or text. Detected when omitted.
labelstring—File name or title shown in the bar instead of the language name.
line-numbers
prop: lineNumbers
booleanfalseNumber each line.
wrapbooleanfalseWrap long lines instead of scrolling sideways. The Wrap button in the bar turns it on and off.
max-lines
prop: maxLines
number—Collapse snippets longer than this many lines behind a "Show all" button.
hide-copy
prop: hideCopy
booleanfalseHide the copy button.

Also accepts the contextual attributes tone, surface, radius, density, motion, elevation. They are inherited from ancestors' data-* attributes.

Events

EventReact / Svelte propDescription
pm-copyonPmCopyThe code was copied.

Slots

SlotDescription
(default)The code, as text (used when code is not set).

Methods

copy()