rehype-highlight

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

Library
npm
v7.0.2
329stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
40/100Fair
Development Activity0
Maintenance20
Community60
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
81/100Excellent
Architecture75
Code Quality85
Innovation85
Learning Curve90

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 Qualitytest.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 16 apps in this directory

Python
54%
Other

authentik

Authentication · Security

24,980

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
68
Dependency
Built with
Python54%
TypeScript33%
Updated today
Python
68%
Other

AutoGPT

Automation · Productivity · AI Assistants

186,687

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
67
Dependency
Built with
Python68%
TypeScript31%
Updated today
TypeScript
97%
Apache 2.0

Cline

AI Code Assistants

66,453

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
67
Dependency
Built with
TypeScript97%
Updated today
TypeScript
84%
Apache 2.0

Continue

Developer Tools · AI Development · AI Code Assistants

35,532

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

View details
87
Repo Health
88
Technical
65
Dependency
Built with
TypeScript84%
Updated today
TypeScript
91%
Apache 2.0

Helicone

Monitoring · AI Development · Analytics

6,083

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
62
Repo Health
81
Technical
66
Dependency
Built with
TypeScript91%
Updated 3 days ago
TypeScript
79%
LGPL 3.0

Latitude

AI Agents · Monitoring

4,593

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
TypeScript79%
Python11%
Updated today
Python
51%
AGPL 3.0

LearnHouse

Learning Management · CMS

2,178

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

View details
89
Repo Health
77
Technical
67
Dependency
Built with
Python51%
TypeScript48%
Updated 3 days ago
TypeScript
80%
MIT

LibreChat

Developer Tools · AI Assistants

42,216

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
68
Dependency
Built with
TypeScript80%
JavaScript19%
Updated today
Rust
72%
Apache 2.0

mesh-llm

AI Development · AI Agents

3,258

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
83
Repo Health
91
Technical
70
Dependency
Built with
Rust72%
TypeScript16%
Updated today

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

Search