@pierre/highlights is a syntax highlighter written in WebAssembly Text (WAT).
It supports 152 built-in languages and Zed-compatible themes. It produces HTML
or themed tokens from complete input, input chunks, or document edits.
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.