rehype-highlight

Rehype plugin that syntax-highlights code blocks at build time using lowlight and highlight.js.

Library
npm
v7.0.2
332 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
40 /100 Fair
Development Activity 0
Maintenance 20
Community 60
Maturity 60
Momentum 20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
81 /100 Excellent
Architecture 75
Code Quality 85
Innovation 85
Learning Curve 90

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 common set, with opt-in access to the full ~190-language all set or custom grammars
  • A fully typed Options object (aliases, detect, languages, plainText, prefix, subset) generated from JSDoc via TypeScript’s checkJs/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

Python
55%
Other

authentik

Authentication · Security

25,758

The self-hosted Identity Provider that replaces Okta, Auth0, and Entra ID with a unified SSO platform supporting SAML, OAuth2/OIDC, LDAP, RADIUS, and WebAuthn.

View details
92
Repo Health
81
Technical
66
Dependency
Built with
Python 55%
TypeScript 36%
Updated 1 weeks ago
Python
66%
Other

AutoGPT

AI Assistants · Automation · Productivity

187,596

Build, deploy, and run autonomous AI agents that automate complex multi-step workflows using a visual block-based graph editor.

View details
93
Repo Health
78
Technical
66
Dependency
Built with
Python 66%
TypeScript 33%
Updated 1 weeks ago
TypeScript
98%
Apache 2.0

Cline

AI Code Assistants

69,455

An open-source AI coding agent that lives in your editor and terminal — reads and edits your codebase, runs commands, browses the web, and requires human approval for every action by default.

View details
90
Repo Health
74
Technical
65
Dependency
Built with
TypeScript 98%
Updated 1 weeks ago
TypeScript
84%
Apache 2.0

Continue

AI Code Assistants · AI Development · Automation

36,049

Open-source coding agent for VS Code, JetBrains, and CLI with support for 30+ LLM providers.

View details
73
Repo Health
88
Technical
62
Dependency
Built with
TypeScript 84%
Updated 1 weeks ago
TypeScript
91%
Apache 2.0

Helicone

AI Development · Analytics · Monitoring

6,182

An open-source AI gateway and LLM observability platform that routes requests to 100+ models while logging cost, latency, and full traces for every call.

View details
70
Repo Health
81
Technical
65
Dependency
Built with
TypeScript 91%
Updated 3 weeks ago
TypeScript
78%
LGPL 3.0

Latitude

AI Agents · Monitoring

4,686

Open-source AI agent monitoring that catches what will break next before your users do.

View details
86
Repo Health
88
Technical
67
Dependency
Built with
TypeScript 78%
Rust 11%
Python 11%
Updated 2 weeks ago
Python
51%
AGPL 3.0

LearnHouse

CMS · Learning Management

2,301

Open-source LMS with AI tutoring, real-time collaboration boards, live code execution, and built-in course monetization — self-hosted in minutes.

View details
90
Repo Health
77
Technical
66
Dependency
Built with
Python 51%
TypeScript 48%
Updated 1 weeks ago
TypeScript
82%
MIT

LibreChat

AI Assistants · Developer Tools

45,009

Unite every major AI model in one self-hosted chat platform with agents, code execution, MCP tools, and enterprise authentication.

View details
93
Repo Health
81
Technical
65
Dependency
Built with
TypeScript 82%
JavaScript 17%
Updated 1 weeks ago
Rust
71%
Apache 2.0

mesh-llm

AI Agents · AI Development

3,463

Mesh LLM pools GPUs and memory across every machine you own into one OpenAI-compatible API, so agents tap distributed compute instead of a single GPU box or a metered cloud bill.

View details
84
Repo Health
91
Technical
69
Dependency
Built with
Rust 71%
TypeScript 13%
Python 10%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers