@codemirror/lang-php

PHP language support for the CodeMirror 6 code editor

Library
npm
v6.0.2
21stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
23/100Needs Attention
Development Activity12
Maintenance0
Community12
Maturity56
Momentum12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
69/100Good
Architecture72
Code Quality70
Innovation55
Learning Curve80

@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 a LanguageSupport extension ready to pass into a CodeMirror EditorView
  • The underlying phpLanguage LRLanguage provider (built on the Lezer PHP parser) for lower-level composition
  • Automatic embedded HTML parsing for content outside <? / ?> markers, matching how real .php files mix markup and code
  • A baseLanguage config option to swap the embedded non-PHP language for something other than HTML
  • A plain config 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

Go
72%
GPL 3.0

1Panel

Devops · Hosting Control Panel · Monitoring

36,573

The only open-source VPS control panel with native AI agent runtime — deploy websites, Docker stacks, and local LLMs from one web interface.

View details
91
Repo Health
76
Technical
67
Dependency
Built with
Go72%
Vue28%
Updated today
Rust
69%
Other

GitButler

Developer Tools · Devops · AI Development

21,531

Git, but better — a modern version control client with stacked branches, parallel workflows, unlimited undo, and first-class support for AI-powered development.

View details
89
Repo Health
84
Technical
68
Dependency
Built with
Rust69%
TypeScript18%
Svelte12%
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
98%
Other

Sourcebot

Search · Developer Tools · AI Code Assistants

3,892

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.

View details
86
Repo Health
83
Technical
67
Dependency
Built with
TypeScript98%
Updated today
TypeScript
92%
Apache 2.0

superset

AI Code Assistants · AI Development

13,068

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.

View details
85
Repo Health
80
Technical
69
Dependency
Built with
TypeScript92%
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