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.

Source on GitHub

A file
Languages
Terminal, diff and long code
Data as it came

verbatim shows and copies the text untouched: a response body or a log keeps its indentation and its blank last line.

Bring your own highlighter

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.

Code

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.

PropertyAttributeTypeDefaultDescription
code—stringThe code, from script (the most convenient in React and Vue). Wins over the content.
languagelanguage reflectsstringThe 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.
filenamefilenamestringA file name or title in the header; also the scroll region's accessible name.
lineNumbersline-numbers reflectsbooleanNumbers each line (not copied, not selectable).
highlighthighlightstringLines to highlight: "3, 5-7".
wrapwrap reflectsbooleanWraps long lines instead of scrolling sideways.
verbatimverbatim reflectsbooleanShows 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.
maxHeightmax-heightstringHeight before it scrolls: px as a number, or a CSS length. A taller block gets a "Show all N lines" button.
expandedexpanded reflectsbooleanShown whole, past max-height.
hideCopyhide-copy reflectsbooleanNo copy button.
hideHeaderhide-header reflectsbooleanNo header bar (the copy button floats in the corner).
sizesize reflectsxs | sm | mdsmFont size.
radiusradius reflectsstringCorner radius: xs…xl, none, or a CSS length. Default: md.
copyLabelcopy-labelstringCopy code (text code.copy)Accessible name of the copy button.
copiedLabelcopied-labelstringCopied (text code.copied)Shown and announced after copying.
EventDescription
ray-copyThe code was copied.
SlotDescription
(default)The code: text, a <template> or a <script type="text/plain">.
PartDescription
frameThe box.
headerThe bar with the file name, the language and the copy button.
copyThe copy button.
scrollerThe scroll box (focusable, to scroll with the keyboard).
codeThe <code> with one .line per line.

Texts

What it writes itself, in English; setStrings() translates them (Getting started: Languages).

KeyEnglish
code.copyCopy code
code.copiedCopied
code.regionCode
code.region-language{language} code
code.show-allShow all {count} lines
code.show-lessShow less