Code

A block for showing source code, highlighted with highlight.js for TypeScript, HTML and CSS. Whitespace and line breaks are kept as written.

Examples

Properties

NameTypeDefaultDescription
codestring''Source to display. Highlighted during server-side rendering when set; otherwise slotted text is highlighted after hydration.
language'ts' | 'html' | 'css'autoLanguage to highlight as. When omitted, text starting with < is treated as HTML and everything else as TypeScript.

CSS variables

NameTypeDefaultDescription
--code-bg<color>#eeeBlock background.
--code-fg<color>#1d0a0bPlain text colour.
--code-comment<color>#7a7a7aComments.
--code-string<color>#2e7d32Strings and regular expressions.
--code-keyword<color>#6a1b9aKeywords, built-ins and literals.
--code-decorator<color>#b26a00Decorators and other meta.
--code-number<color>#c62828Numbers.
--code-tag<color>#1565c0HTML tags and CSS selectors.
--code-attr<color>#00695cHTML attributes and CSS properties.

Usage

The block scrolls horizontally when a line is wider than its container.

Implementation