Imported from pierrecomputer/pierre (
skills/highlights/SKILL.md). Install upstream withnpx skills add pierrecomputer/pierre --skill highlights. Copyright stays with the author.
@pierre/highlights
Use @pierre/highlights for standalone syntax highlighting with built-in
WebAssembly lexers. Choose HTML for a complete code block, tokens for a custom
renderer, StreamTokenizer for append-only input, or LiveTokenizer for an
editable document.
Install
pnpm add @pierre/highlights
@pierre/highlights contains all lexers in one Wasm module, initialized at
import, and all themes. Import shared output functions, StreamTokenizer, and
LiveTokenizer from it. registerLanguages(langs) adds custom lexers to its
shared output functions.
@pierre/highlights/core contains no lexers or themes. Import
createHighlighter from it, select language modules from
@pierre/highlights/langs/*, and supply theme objects. Await the factory once.
Its output methods then run synchronously. Use the combined langs export from
@pierre/highlights/langs when the application needs all languages.
Use the main entry by default. Use /core with selected modules when download
size matters. Embedded code and Markdown fences are plain text there until their
languages are in langs; see Rendering.
Select a reference
| Task | Reference |
|---|---|
| Generate HTML or tokens, select or add languages, or manage a Wasm module | Rendering |
| Load or customize themes, switch CSS variables, or render multiple schemes | Themes |
| Tokenize streamed strings or bytes | Streaming |
| Apply edits, prioritize a viewport, or read packed token records | Incremental editing |
Write a lexer for a new language in WAT with @pierre/wat-tools |
Custom lexers |
For file, diff, or editor components, read the diffs skill.
