lang-html
HTML language support for the CodeMirror code editor, with autocompletion, folding, and nested CSS/JS parsing.
Repository Health
Technical Analysis
@codemirror/lang-html is the official HTML language package for CodeMirror 6. It wires the Lezer HTML parser into CodeMirror as an LRLanguage, adding syntax-aware indentation, code folding, bracket matching, and context-aware autocompletion for tags and attributes.
Beyond plain HTML, the package transparently embeds the JavaScript and CSS language packages so that the contents of <script> and <style> blocks (including TypeScript, JSX, and JSON script types) are parsed and highlighted with their own grammars. A single html() call returns a ready-to-use LanguageSupport extension, and options let you register additional nested languages, extra tags, and custom attributes.
What You Get
- An
html()factory that returns a configured CodeMirrorLanguageSupportextension in one call - Context-aware completion for HTML tags, attributes, and attribute values via
htmlCompletionSource - Automatic insertion of closing tags as you type
>or/through theautoCloseTagsextension - Nested parsing of JavaScript, TypeScript, JSX, JSON, and CSS inside
<script>and<style>tags
Common Use Cases
- Building an in-browser HTML editor or template editor with rich highlighting and completion
- Adding an HTML editing mode to a CodeMirror-based IDE, CMS, or documentation tool
- Editing HTML fragments or email templates with embedded inline CSS and JavaScript
Under The Hood
Architecture
The core lives in src/html.ts, which defines an LRLanguage (htmlPlain) built on the @lezer/html parser and augmented with indentNodeProp, foldNodeProp, and bracketMatchingHandle node properties for indentation, folding, and tag matching. The exported htmlLanguage wraps this parser with configureNesting, mixing in nested NestedLang and NestedAttr definitions so <script>/<style> bodies and style/event attributes are parsed by the CSS and JavaScript grammars. The html() function assembles a LanguageSupport from the language plus the autocompletion source, autoCloseTags input handler, and the JavaScript/CSS support extensions, selecting a parser dialect based on matchClosingTags/selfClosingTags config.
Tech Stack
Written entirely in TypeScript and published as dual ESM/CJS with type declarations. It depends on the CodeMirror 6 packages (@codemirror/language, @codemirror/state, @codemirror/view, @codemirror/autocomplete, @codemirror/lang-css, @codemirror/lang-javascript) and the Lezer parsers (@lezer/html, @lezer/common, @lezer/css). Building is handled by @codemirror/buildhelper via the cm-buildhelper script.
Code Quality
The codebase is small and focused (html.ts plus a large complete.ts tag/attribute spec table) with thorough /// doc comments that also generate the README API reference. Types are precise (TagSpec, NestedLang, NestedAttr) and there is a dedicated test file (test/test-complete.ts) exercising completion behavior via cm-runtests.
API Design
The public surface is deliberately minimal and ergonomic: a single html(config) function covers the common case, while htmlCompletionSource, htmlCompletionSourceWith, htmlLanguage, and autoCloseTags are exported for finer control. Configuration options are well-named and documented inline, keeping the required boilerplate to a single extension entry in an editor’s setup.
Used by 37 apps in this directory
Ghost
Blogging · CMS
Open source headless Node.js CMS for professional publishing, paid memberships, and newsletters with a fully owned audience.
GitButler
AI Development · Developer Tools · Devops
Git, but better — a modern version control client with stacked branches, parallel workflows, unlimited undo, and first-class support for AI-powered development.
HyperFrames
AI Design Tools · AI Development
Turn plain HTML and CSS into deterministic, pixel-perfect MP4 videos — authored by humans or AI agents, rendered by headless Chrome and FFmpeg.
ILLA Builder
Design Tools · Developer Tools · Low Code Platforms
Open-source low-code platform for building internal tools with drag-and-drop UI, reactive data bindings, and real-time collaboration.
Joplin
Note Taking
The privacy-first, open-source note-taking app with end-to-end encrypted sync, AI assistance, and a powerful plugin ecosystem across every platform.
Keila
Marketing
Self-hosted newsletter platform with a visual block editor, Liquid personalization, and flexible email delivery — a privacy-respecting Mailchimp alternative you run on your own infrastructure.
Kener
Devops · Monitoring
Stunning, self-hosted status pages with real-time uptime monitoring, incident management, and multi-channel notifications in a single Docker container.
Laminar
AI Development · Monitoring
Open-source observability platform purpose-built for AI agents — trace, evaluate, debug, and monitor at scale with SQL access and real-time replay.
LimeSurvey
Forms Surveys
The world's most flexible open-source survey platform with 900+ templates, conditional logic, 80+ languages, and full GDPR compliance for any scale.