@codemirror/lang-xml
XML language support package for the CodeMirror 6 code editor
Repository Health
Technical Analysis
@codemirror/lang-xml plugs XML support into the CodeMirror 6 editor: it wires the Lezer XML grammar into CodeMirror’s language framework to provide syntax highlighting and indentation, and layers on editor-specific conveniences like automatic tag closing and schema-aware autocompletion for elements and attributes.
Calling xml() returns a LanguageSupport extension that can be dropped straight into a CodeMirror EditorView’s extensions array. Developers who want intelligent completions (suggesting valid child elements or attribute values as the user types) can optionally pass an ElementSpec/AttrSpec schema describing their XML dialect, which the bundled completeFromSchema helper turns into a CompletionSource.
What You Get
- The
xml()function returning aLanguageSupportextension ready to drop into a CodeMirrorEditorView xmlLanguage, a language provider based on the Lezer XML parser with highlighting and indentation baked inautoCloseTags, an extension that inserts closing tags automatically when>or/is typedcompleteFromSchema(elements, attributes)to build schema-aware completions for elements and attribute valuesElementSpec/AttrSpectypes for describing an XML dialect’s allowed elements, children, and attributes
Common Use Cases
- Adding XML editing support (highlighting, indentation, auto-close tags) to a CodeMirror-based web code editor
- Building a schema-aware XML editor that autocompletes valid child elements and attribute values for a known dialect
- Embedding an XML/XHTML/config-file editing experience inside a documentation or admin tool built on CodeMirror 6
- Providing structured editing for XML-based formats (SVG, RSS, custom config schemas) in a browser-based tool
Under The Hood
Architecture - The package is small and cleanly split in two: src/xml.ts (113 lines) defines the xml() entry point, wiring the Lezer-XML-based xmlLanguage together with the autoCloseTags view extension and, when a schema is supplied, a completion source; src/complete.ts (241 lines) implements completeFromSchema, which walks the current syntax tree position to determine valid completions (element names, attribute names, attribute values) based on the caller-supplied ElementSpec/AttrSpec schema. All actual XML parsing is delegated to the separate @lezer/xml grammar package, keeping this package focused purely on editor integration (highlighting, indentation, completion) rather than parsing. Tech Stack - TypeScript, built with the shared @codemirror/buildhelper tooling used across all official CodeMirror 6 language packages. Runtime dependencies are the core CodeMirror 6 modules (@codemirror/autocomplete, @codemirror/language, @codemirror/state, @codemirror/view) plus @lezer/common and @lezer/xml, reflecting its role as a thin adapter layer over the shared CodeMirror/Lezer ecosystem rather than a standalone implementation. Code Quality - test/test-complete.ts specifically exercises the schema-driven completion logic, the most algorithmically interesting part of the package; the parsing and highlighting behavior is implicitly covered by the shared Lezer XML grammar’s own tests. The package has a single primary contributor (Marijn Haverbeke, the CodeMirror/Lezer author), consistent with it being one of many small, focused @codemirror/lang-* packages maintained as part of that ecosystem rather than independently. API Design - The public surface is intentionally minimal: one factory function (xml(conf?)) covers the common case with zero configuration, while power users opt into schema-aware completions by passing typed elements/attributes config objects. This mirrors the consistent, predictable API shape shared across every official @codemirror/lang-* package, so switching between supported languages requires no relearning.
Used by 10 apps in this directory
authentik
Authentication · Security
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.
GitButler
Developer Tools · Devops · AI Development
Git, but better — a modern version control client with stacked branches, parallel workflows, unlimited undo, and first-class support for AI-powered development.
Hoppscotch
Developer Tools
A lightweight, offline-capable API development ecosystem for testing HTTP, GraphQL, WebSocket, MQTT, and SSE endpoints across web, desktop, and CLI.
ILLA Builder
Developer Tools · Low Code Platforms · No Code Platforms
Open-source low-code platform for building internal tools with drag-and-drop UI, reactive data bindings, and real-time collaboration.
LearnHouse
Learning Management · CMS
Open-source LMS with AI tutoring, real-time collaboration boards, live code execution, and built-in course monetization — self-hosted in minutes.
nginx ignition
Developer Tools · Devops
A modern web UI for nginx that eliminates config file editing with visual virtual hosts, SSL automation, Docker integrations, and real-time traffic analytics.
OpenViking
Databases · AI Development
An open-source context database that gives AI agents a unified filesystem for memory, resources, and skills with hierarchical tiered retrieval.
Scalar
Developer Tools
Beautiful, interactive OpenAPI documentation with a built-in offline-first API client and multi-language code generation — all in one open-source platform.
Sourcebot
Search · Developer Tools · AI Code Assistants
A self-hosted, AI-powered code search engine that indexes every repo across GitHub, GitLab, Bitbucket, Gitea, Gerrit, and Azure DevOps, so both engineers and coding agents can search, browse, and ask questions about your codebase from one place.