@lezer/highlight
Syntax highlighting framework that maps Lezer parse trees to styleable highlighting tags
Repository Health
Technical Analysis
@lezer/highlight is the syntax highlighting layer of the Lezer parser system used by CodeMirror. It defines a mostly closed vocabulary of highlighting tags, lets language packages associate tree nodes with those tags, and provides highlighters that turn tagged nodes into CSS classes or inline styles.
Rather than matching raw token strings, it works over structured Lezer parse trees, so highlighting stays consistent across languages and themes. It ships as a tiny, dependency-light TypeScript library that powers highlighting for every CodeMirror 6 language mode.
What You Get
- A closed, extensible vocabulary of highlighting tags (
tags) shared across all Lezer languages styleTagsto associate syntax tree node types with highlighting tags in a language grammartagHighlighterand the ready-madeclassHighlighterfor turning tags into CSS classeshighlightTreeandhighlightCodeto walk a parse tree and emit styled ranges or DOM- Tag modifiers and inheritance so themes can fall back from specific to general tags
Common Use Cases
- Adding syntax highlighting to a CodeMirror 6 editor via a language package
- Authoring a new Lezer language mode that exposes highlighting metadata
- Rendering static, highlighted code snippets outside an editor with highlightCode
- Building custom editor themes that map highlighting tags to CSS classes
Under The Hood
Architecture - The entire library lives in a single src/highlight.ts module built around a Tag class whose instances form a specificity-ordered set of parent tags, with Modifier instances lazily generating modified tags and caching them via a power-set of parent configurations. styleTags compiles a selector spec into a Rule linked list stored on nodes through a ruleNodeProp NodeProp; highlightTree and highlightCode then drive a HighlightBuilder that walks the tree with a TreeCursor, resolves the active tags via getStyleTags, and calls a Highlighter to emit class names for each styled range. Tech Stack - Written in TypeScript targeting both ESM and CommonJS (dist/index.js and dist/index.cjs), its only runtime dependency is @lezer/common for tree and NodeProp primitives, and it builds with @marijn/buildtool and TypeScript 5. Code Quality - The code is dense but carefully commented with /// doc comments feeding the generated API reference, uses precise readonly types and internal markers, and favors small pure helpers (sameArray, powerSet); there is no test directory in the repository, so correctness relies on the broader Lezer/CodeMirror integration suite rather than local unit tests. API Design - The public surface is small and composable - tags, styleTags, tagHighlighter/classHighlighter, and highlightTree/highlightCode - with a closed tag vocabulary and inheritance that lets themes cover many languages with minimal boilerplate, though understanding the tag/modifier model takes some reading of the reference docs.
Used by 47 apps in this directory
Langfuse
AI Development · Monitoring
Open source AI engineering platform for LLM observability, prompt management, evaluation, and debugging — self-host in minutes or use Langfuse Cloud.
listmonk
Blogging · Marketing
High-performance, self-hosted newsletter and mailing list manager packaged as a single binary with built-in analytics, transactional messaging, and multi-channel delivery.
marimo
Data Engineering · Developer Tools
A reactive Python notebook that eliminates hidden state, runs reproducibly, and deploys as a web app or script — stored as pure Python, built for the AI era.
massCode
Code Editors · Developer Tools · Productivity
A free, local-first developer workspace unifying snippets, notes, HTTP requests, calculations, drawings, and dev tools in one desktop app.
Mastra Code
AI Code Assistants
"A coding agent that never compacts" — a terminal-based AI coding agent built on the Mastra framework, with Observational Memory instead of context compaction, multi-model support, and OAuth login for Claude Max or ChatGPT Plus.
memos
Note Taking
Open-source, self-hosted note-taking built for quick capture — Markdown-native, lightweight, and fully yours.
Metabase
Analytics
The open-source BI platform that lets anyone ask questions and build dashboards without writing SQL — with an embedded analytics SDK and AI-powered query assistant included.
n8n
Automation · No Code Platforms
Code when you need it, UI when you don't — the workflow automation platform built for technical teams who refuse to choose.
Novu
Developer Tools
Open-source communication infrastructure that connects your products and AI agents to every channel your users live on — Inbox, Email, SMS, Push, Chat, and more.