Skip to content

Code ​

A code block component (self-developed regex token highlighting, no third-party highlighting engine) supporting basic coloring for common languages, line numbers, and a copy button.

JavaScript ​

JavaScript highlighting

Basic coloring for keywords / strings / comments / numbers / functions / operators.

TypeScript ​

TypeScript highlighting

HTML ​

HTML highlighting

Tag names and attribute names are colored separately.

CSS ​

CSS highlighting

JSON ​

JSON highlighting

Line Numbers + Copy ​

Show line numbers

show-line-number displays the line number column; the copy button in the top-right corner (disable with copyable="false") copies the source on click and emits the oas-copy event.

Copy Button Toggle ​

copyable copy button

copyable controls the top-right copy button (default true): setting it to false hides the button; clicking the button writes the source to the clipboard and briefly shows "Copied".

Unknown Language ​

Unknown language rendered as plain text

When the language is unknown, the content is rendered as plain text (escaped) without errors.

Inline Code (inline) ​

inline renders inline code (monospace with a light background box, non-block, no line breaks — for code snippets inside prose):

Inline code

Declare a constant with and print it with .

Word Wrap (word-wrap) ​

With word-wrap, long code wraps instead of scrolling horizontally:

Long code wrapping

Trimming (trim) ​

trim defaults to true (strips leading/trailing whitespace); trim="false" preserves it:

trim comparison

Inline Size (size) ​

size has four tiers (xs/small/medium/large — font-size tiers in inline context):

Inline sizes

Inline Variant (variant) ​

variant has four styles (subtle light background by default / outline bordered / plain text only / solid filled):

Inline variants

Inline Color (color) ​

color accepts 11 preset color names (auto-adapting to light/dark themes) or any CSS color value (takes effect directly, overriding presets and the default). Controls the text color in inline context:

Inline colors

Font Size ​

Font size defaults to 0.875× the outer context (0.875em); override with the CSS variable --oas-code-font.

Line Highlight (highlight-lines) ​

highlight-lines highlights lines using the "1,3-5" range syntax (1-based, comma-separated points or inclusive ranges; whitespace ignored, invalid fragments skipped):

Line highlight

Line Focus (focus-lines) ​

focus-lines focuses the given lines and dims the rest by blending them toward the theme text color (color-mix, not opacity) — handy for walking through key code:

Line focus

Diff Mode (diff) ​

With diff, lines are colored by their first character: + lines green (added), - lines red (removed):

Diff coloring

Content Folding (max-rows) ​

max-rows caps the visible lines and shows an expand/collapse tail row when exceeded (0 means unlimited, invalid values ignored):

max-rows folding

API ​

oas-code ​

Attributes ​

AttributeDescriptionTypeDefault
codeRaw source codestring—
colorInline text color: accepts 11 preset names (magenta / red / volcano / orange / gold / lime / green / cyan / blue / geekblue / purple, mapped to --oas-preset-*-text tokens) or any CSS color valuestring—
copyableShow the copy buttonstringtrue
diffDiff mode: colors lines by leading +/- (semantic color tokens)boolean—
focus-linesLine focus: focused lines stay, the rest dimstring—
highlight-linesLine highlight: "1,3-5" range syntax for highlighted lines (1-based)string—
inlineInline code mode: renders as a monospace light-background box for code snippets inside proseboolean—
languageLanguage: js/ts/html/css/json; unknown falls back to plain textstring—
max-rowsMax visible lines; overflow folds with an expand/collapse tail row (0 = unlimited)string—
show-line-numberShow the line number columnboolean—
sizeInline font-size tier: xs / small / medium (default) / large; invalid values fall back to medium with a warningstring—
trimStrip leading/trailing whitespace (default true; trim="false" preserves it)stringtrue
variantInline style: subtle (default light background) / outline (bordered) / plain (text only) / solid (filled); invalid values fall back to subtle with a warning——
word-wrapWrap long code instead of horizontal scrollingboolean—

Events ​

EventDescription
oas-copyCopy succeeded, detail: { text }
oas-copy-errorCopy failed, detail: { text }

CSS Variables ​

CSS VariableDefault
--oas-code-colorvar(--oas-color-text-primary)
--oas-code-focus-dim-strength58%
--oas-code-font0.875em
--oas-code-highlight-bgcolor-mix(in srgb, var(--oas-color-primary) 8%, transparent)
--oas-code-on-colorvar(--oas-color-bg)

Released under the MIT OR Apache-2.0 License.