rehype-highlight
Rehype plugin that syntax-highlights code blocks at build time using lowlight and highlight.js.
Repository Health
Technical Analysis
rehype-highlight is a rehype plugin that walks the HTML syntax tree (hast) a unified pipeline has already parsed, finds <pre><code> blocks, and applies syntax highlighting to them with lowlight, a virtual/AST-based wrapper around highlight.js. It looks for language-* or lang-* classes to decide which grammar to apply, and can optionally guess a language automatically with detect: true.
Because the highlighting happens once on the AST at build time rather than in the browser, pages ship with no client-side highlighter and no highlighting-related layout shift or flash of unstyled code. It bundles 37 common highlight.js languages out of the box, supports registering the full ~190-language set or custom grammars, and composes safely with rehype-sanitize for untrusted HTML.
What You Get
- A default-exported unified/rehype plugin usable as
unified().use(rehypeHighlight, options) - 37 bundled highlight.js languages via lowlight’s
commonset, with opt-in access to the full ~190-languageallset or custom grammars - A fully typed
Optionsobject (aliases, detect, languages, plainText, prefix, subset) generated from JSDoc via TypeScript’scheckJs/declaration emit - Zero client-side runtime cost — highlighting is computed once at build time and baked into the output HTML
Common Use Cases
- Highlighting fenced code blocks in statically generated documentation and blog sites
- Adding syntax highlighting to Markdown-to-HTML pipelines built on remark/rehype
- Composing with rehype-sanitize for safe highlighting of untrusted or CMS-authored HTML
Under The Hood
Architecture — The plugin is a single factory function (lib/index.js, ~182 lines) that returns a unified transformer. The transformer uses unist-util-visit to walk the hast tree looking for <code> elements directly inside <pre>, reads the code’s text with hast-util-to-text, and delegates the actual tokenization to a lowlight instance created via createLowlight(languages). Highlighted output replaces the node’s children in place and a hljs/language-* class is added — the whole transform is synchronous and side-effect-free outside the tree it’s given.
Tech Stack — The package is ESM-only ("type": "module"), depends on @types/hast, hast-util-to-text, lowlight (^3), unist-util-visit, and vfile, and targets Node.js 16+. Types are authored as JSDoc comments and compiled to .d.ts/.d.ts.map via tsc --build with checkJs and exactOptionalPropertyTypes enabled, so there’s no separate TypeScript source tree to maintain — the JS is the source of truth for both runtime and types.
Code Quality — test.js (508 lines) uses Node’s built-in node:test/node:assert runner against real unified/rehype pipelines (parse → highlight → stringify) rather than mocking internals, and c8 --100 enforces full statement/branch coverage on every test run. type-coverage is configured with atLeast: 100 in strict mode, so the JSDoc-derived types must fully cover the code — a notably rigorous bar for a project this size.
API Design — The public surface is a single default export with an optional Options object whose defaults (detect: false, prefix: 'hljs-') are safe no-ops, so .use(rehypeHighlight) with zero configuration is a valid starting point. Escape hatches (aliases, languages, plainText, subset) are additive rather than required, keeping the common case boilerplate-free while still supporting advanced registration and sanitization scenarios documented with runnable examples in the README.
Used by 17 apps in this directory
Onyx
AI Agents · AI Assistants · Knowledge Management
Self-hostable AI platform with agentic RAG, 50+ connectors, deep research, code execution, and support for every major LLM provider.
OpenKB
Knowledge Management
An open-source CLI that compiles raw documents into a structured, interlinked wiki-style knowledge base using LLMs — powered by vectorless, reasoning-based retrieval (PageIndex) instead of a vector database.
Orca
AI Agents · AI Code Assistants
An open-source Agent Development Environment that orchestrates fleets of parallel AI coding agents — Claude Code, Codex, Gemini and more — each running in its own isolated git worktree.
Refly
AI Development · Automation · No Code Platforms
Build deterministic, versioned agent skills from natural language—run them anywhere from Claude Code to Slack.
Temps
Analytics · Devops · Monitoring
A self-hosted Rust PaaS that replaces Vercel, Sentry, PostHog, Pingdom, Resend, and E2B with one binary — plus 440+ CLI operations agents like Claude Code can drive directly.
Tolaria
Note Taking
A free, open-source, local-first desktop app for managing markdown knowledge bases on macOS, Windows, and Linux — for second brains, company docs, or AI assistant memory and procedures.
Tolgee
Developer Tools
In-context localization platform that lets developers and translators edit app strings directly in the running application, with AI-powered machine translation and framework SDKs for React, Angular, Vue, and Svelte.
Vibe Kanban
AI Agents · AI Code Assistants · Project Management
A kanban board for planning work and dispatching Claude Code, Codex, Gemini CLI, and eight other coding agents into isolated git worktrees, then reviewing and merging their diffs from one UI.