@codemirror/lang-php
PHP language support for the CodeMirror 6 code editor
Repository Health
Technical Analysis
@codemirror/lang-php adds PHP language support to CodeMirror 6, providing syntax highlighting and indentation via a Lezer-based PHP parser. Because PHP files typically mix PHP code with surrounding HTML, the package treats everything outside <? and ?> markers as HTML by default, embedding CodeMirror’s HTML language support automatically so a .php file gets correct highlighting for both the PHP and markup portions in one editor instance.
It exposes a small php() extension function plus the underlying phpLanguage provider, following the same lightweight, composable pattern used across CodeMirror’s other @codemirror/lang-* packages, so it drops into any CodeMirror 6 setup alongside basicSetup with a single import and function call.
What You Get
- A
php(config?)function that returns aLanguageSupportextension ready to pass into a CodeMirrorEditorView - The underlying
phpLanguageLRLanguage provider (built on the Lezer PHP parser) for lower-level composition - Automatic embedded HTML parsing for content outside
<?/?>markers, matching how real.phpfiles mix markup and code - A
baseLanguageconfig option to swap the embedded non-PHP language for something other than HTML - A
plainconfig option to start PHP parsing from the beginning of the document instead of waiting for the first<?marker
Common Use Cases
- Adding PHP syntax highlighting to a browser-based code editor built on CodeMirror 6
- Building a live PHP template editor where PHP logic is interspersed with HTML markup
- Embedding a lightweight PHP snippet editor in a documentation site or admin tool without a full IDE
- Composing PHP support alongside other CodeMirror language packages in a multi-language code playground
Under The Hood
Architecture - The package is a minimal single-file adapter (src/php.ts, ~70 lines) that wires the external @lezer/php grammar into CodeMirror’s LRLanguage abstraction and configures embedded-language parsing so HTML markup outside PHP tags is delegated to @codemirror/lang-html. This mirrors the standard structure used across every @codemirror/lang-* package: a thin language-definition layer on top of a shared Lezer parser, rather than an independent parsing implementation.
Tech Stack - Written in TypeScript, built with the shared @codemirror/buildhelper tooling used across the CodeMirror monorepo family, and tested via cm-runtests, the CodeMirror project’s shared cross-package test runner. Its only real dependencies are other CodeMirror core packages (@codemirror/lang-html, @codemirror/language, @codemirror/state) and the Lezer PHP grammar (@lezer/php), so it adds negligible weight beyond the parser itself.
Code Quality - Given its narrow scope, the file is small and easy to audit in full; correctness mostly rests on the shared, separately maintained @lezer/php grammar rather than logic in this package. There is no dedicated PHP-specific test suite visible in this package’s own repo — testing for language packages in the CodeMirror ecosystem is typically exercised indirectly through the shared cm-runtests harness and the parser’s own grammar tests rather than per-package fixtures.
API Design - The API follows CodeMirror’s consistent language-package convention exactly: call php() and drop the result into your extensions array alongside basicSetup, with two clearly named optional config keys (baseLanguage, plain) for the only two behaviors worth customizing. This consistency across CodeMirror’s language packages means a developer who has used any other @codemirror/lang-* package already knows how to use this one.
Used by 5 apps in this directory
1Panel
Devops · Hosting Control Panel · Monitoring
The only open-source VPS control panel with native AI agent runtime — deploy websites, Docker stacks, and local LLMs from one web interface.
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.
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.
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.
superset
AI Code Assistants · AI Development
Orchestrate an army of AI coding agents—Claude Code, Codex, Gemini CLI, and more—running simultaneously in isolated git worktrees from a single Electron desktop app.