lite-hl
lite-hl
lite-hl is a fast, universal syntax highlighter and code tokenizer requiring zero external configuration. It uses heuristic pattern tokenisation to provide accurate syntax highlighting across popular programming languages while remaining lightweight and self-contained.
Universal Highlighting
lite-hl runs identically in Node.js server environments and client-side browser runtimes, making it ideal for isomorphic documentation generators.
Installation
pnpm
npm
bun
pnpm add lite-hl
npm install lite-hl
bun add lite-hl
Usage
Server-Side Rendering
import { highlight } from 'lite-hl';
const code = `function calculateTotal(price, tax) {
return price * (1 + tax);
}`;
const html = highlight(code, 'javascript');
console.log(html);
Linking Styles
Import the accompanying stylesheet to style token classes:
<link rel="stylesheet" href="node_modules/lite-hl/dist/lite-hl.css">
Or in CSS:
@import "lite-hl/theme.css";
Supported Languages
lite-hl includes built-in tokenisers for over 30 languages, including:
- JavaScript, TypeScript, JSX, TSX
- Python, Rust, Go, C, C++, C#
- HTML, XML, CSS, SCSS, JSON, YAML
- Bash, Shell, SQL, Markdown, Dockerfile
API Reference
highlight(code, language, options?)
Tokenises the source code and returns an HTML string wrapped in syntax token spans.
tokenize(code, language)
Returns an array of token objects containing token types and textual values for custom renderer pipelines.