Code
A block of source code: header with file name and language, copy button, line numbers, highlighted lines, diff lines, wrapping and a "show more" height. A small built-in highlighter, or any library through setHighlighter(), painted with the --ray-code-* tokens.
verbatim shows and copies the text untouched: a response body or a log keeps its indentation and its blank last line.
setHighlighter() hands every block to a library; its classes are painted with the ray-elements tokens, so the colors stay the same. Returning nothing falls back to the built-in one.
API
For AI agents: this API as Markdown, or every component in llms-full.txt.
<ray-code> · RayCode
The code comes from the code property, a <script type="text/plain"> child (raw text: anything but a closing script tag), a <template> child (parsed as HTML: the easiest for markup, but a < that is not a tag, as in Promise<void>, breaks it), or the element's text; common indentation and blank edges are removed (not with verbatim). Built-in languages: js/ts (jsx, tsx), json, html/xml/svg/vue, css, shell, ray and diff; others show as plain text. Library classes painted with the tokens: Prism's .token.*, highlight.js's .hljs-*, and Shiki's css-variables theme.
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
code | — | string | The code, from script (the most convenient in React and Vue). Wins over the content. | |
language | language reflects | string | The language: js, ts, jsx, tsx, json, html, xml, svg, vue, css, sh, ray, diff… (also shown in the header). Not lang: that is the human language of the text. | |
filename | filename | string | A file name or title in the header; also the scroll region's accessible name. | |
lineNumbers | line-numbers reflects | boolean | Numbers each line (not copied, not selectable). | |
highlight | highlight | string | Lines to highlight: "3, 5-7". | |
wrap | wrap reflects | boolean | Wraps long lines instead of scrolling sideways. | |
verbatim | verbatim reflects | boolean | Shows and copies the text exactly as given: no common indentation or blank first and last lines removed. For data (a response body, a log) rather than code written in the page. | |
maxHeight | max-height | string | Height before it scrolls: px as a number, or a CSS length. A taller block gets a "Show all N lines" button. | |
expanded | expanded reflects | boolean | Shown whole, past max-height. | |
hideCopy | hide-copy reflects | boolean | No copy button. | |
hideHeader | hide-header reflects | boolean | No header bar (the copy button floats in the corner). | |
size | size reflects | xs | sm | md | sm | Font size. |
radius | radius reflects | string | Corner radius: xs…xl, none, or a CSS length. Default: md. | |
copyLabel | copy-label | string | Copy code (text code.copy) | Accessible name of the copy button. |
copiedLabel | copied-label | string | Copied (text code.copied) | Shown and announced after copying. |
| Event | Description |
|---|---|
ray-copy | The code was copied. |
| Slot | Description |
|---|---|
| (default) | The code: text, a <template> or a <script type="text/plain">. |
| Part | Description |
|---|---|
frame | The box. |
header | The bar with the file name, the language and the copy button. |
copy | The copy button. |
scroller | The scroll box (focusable, to scroll with the keyboard). |
code | The <code> with one .line per line. |
Texts
What it writes itself, in English; setStrings() translates them (Getting started: Languages).
| Key | English |
|---|---|
code.copy | Copy code |
code.copied | Copied |
code.region | Code |
code.region-language | {language} code |
code.show-all | Show all {count} lines |
code.show-less | Show less |