Skip to main content
VelinStyle v1.3.0
⌂ Home

Syntax highlighting 1.2.2

Token-based syntax highlighting without Prism or CDN. OKLCH token colors, lazy in-view highlighting, and velin-code-block. Deutsch: Syntax-Highlighting Leitfaden

Maturity: Documented as stable in VelinStyle 1.2.0. Design Intelligence (plan / review / agent meta) is separate and beta / foundation where noted.

When to use

When not

Overview

Languages

Each lexer is a separate module, loaded only when a block using it comes into view.

LanguageAccepted names
JavaScriptjs, javascript, jsx
TypeScriptts, typescript, tsx
HTMLhtml, markup, xml, svg
CSScss
JSONjson
Markdownmd, markdown
Shellshell, bash, sh, zsh
SQLsql
PHPphp, blade
Pythonpython, py, python3
YAMLyaml, yml
Gogo, golang
Rustrust, rs
Plain texttext, plain, txt, console

A language- prefix is accepted everywhere, so class="language-rust" resolves the same as rust. Call velinSyntax.listLanguages() for the current list at runtime. Anything unrecognised falls back to unstyled plain text rather than failing.

<velin-code-block language="python" line-numbers>
def greet(name: str = "world") -> None:
    print(f"hello {name}")
</velin-code-block>

YAML notes

Mapping keys use the attr-name token so they stay distinguishable from string values, and block scalar headers (|, >), anchors (&name) and aliases (*name) are tokenised as operators.

Custom languages

Register your own lexer for anything not listed. A lexer takes source text and returns tokens; token types map onto the velin-token--* classes.

import { registerLanguage } from '@birdapi/velinstyle/highlight';

registerLanguage('toml', (code) => [{ type: 'plain', value: code }]);

JavaScript API

import { initHighlight, velinSyntax } from '@birdapi/velinstyle/highlight';

initHighlight(document);
// velinSyntax.highlightElement(document.querySelector('pre'));

HTML attribute

<pre velin-code="js" language="js"><code>const x = 42;</code></pre>

Web component

<velin-code-block language="css" line-numbers highlight="1-2">
.btn { padding: 0.5rem 1rem; }
.btn--primary { background: var(--velin-color-primary); }
</velin-code-block>

Load with bootFromDOM(document, { attributes: true, highlight: true }).