0.3.0 • Published 3d ago
@pierre/highlights
Licence
apache-2.0
Version
0.3.0
Deps
0
Size
1.7 MB
Vulns
0
Weekly
0
Highlights, from Pierre
@pierre/highlights is a syntax highlighter written in WebAssembly Text (WAT).
It supports 120 built-in languages and Zed-compatible themes. It produces HTML
or themed tokens from complete input, input chunks, or document edits.
Read the Documentation.
Installation
pnpm add @pierre/highlights
The package runs in Node.js, browsers, and Cloudflare Workers. It initializes
WebAssembly at import. codeToHtml() and codeToTokens() run synchronously
after import.
Quick start
import { codeToHtml } from '@pierre/highlights';
import { pierreDark } from '@pierre/highlights/themes';
const htmlBytes = codeToHtml("console.log('Hello world!')", {
lang: 'js',
theme: pierreDark,
});
const html = new TextDecoder().decode(htmlBytes);
codeToHtml() returns UTF-8 HTML bytes that can share WebAssembly memory.
Decode the bytes before the next call to the highlighter. Use .slice() to keep
a copy for later use.
Read the API reference for tokens, input streams, document edits, and themes.
Development
moonx highlights:build
moonx highlights:dev
moonx highlights:test
moonx highlights:bench
moonx highlights:bench-live
moonx highlights:bench-memory
Benchmarks · Architecture · Bundled themes