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.
Overview
Put the code in the code property, or as text inside the element (escape < as < in HTML). The language is detected when not given. Long snippets can start collapsed with max-lines.
Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
code | string | — | 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. |
label | string | — | File name or title shown in the bar instead of the language name. |
line-numbersprop: lineNumbers | boolean | false | Number each line. |
wrap | boolean | false | Wrap long lines instead of scrolling sideways. The Wrap button in the bar turns it on and off. |
max-linesprop: maxLines | number | — | Collapse snippets longer than this many lines behind a "Show all" button. |
hide-copyprop: hideCopy | boolean | false | Hide the copy button. |
Also accepts the contextual attributes tone, surface, radius, density, motion, elevation. They are inherited from ancestors' data-* attributes.
Events
| Event | React / Svelte prop | Description |
|---|---|---|
pm-copy | onPmCopy | The code was copied. |
Slots
| Slot | Description |
|---|---|
(default) | The code, as text (used when code is not set). |
Methods
copy()