PHPackages                             alto/code-highlight - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. alto/code-highlight

ActiveLibrary

alto/code-highlight
===================

A high-performance, semantic syntax highlighter for PHP 8.4+ with zero dependencies. Features context-aware parsing, language embedding, and compatibility with Highlight.js and Prism themes.

14↑1400%HTMLCI failing

Since Apr 6Pushed 2d agoCompare

[ Source](https://github.com/PhpAlto/code-highlight)[ Packagist](https://packagist.org/packages/alto/code-highlight)[ RSS](/packages/alto-code-highlight/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

ALTO \\ Code Highlight
======================

[](#alto--code-highlight)

**Syntax highlighting for PHP projects**

Server-side highlighting for the full PHP stack: [27 languages](#languages)covering PHP, HTML, Twig, JavaScript, CSS, YAML, and more. [Zero dependencies](#install), [semantic PHP syntax](#features)understanding definitions vs. calls, [embedded language support](#embeddings), and [490+ compatible themes](#compatibility). Works in [Twig templates](#integrations), Laravel Blade, Symfony controllers—anywhere PHP runs.

[![Tests](https://camo.githubusercontent.com/25e4c0634ebebfb8463db8d0db2d6f65555d07f78faeadeebbba744a725b24af/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f74657374732d3436332532307061737365642d73756363657373)](https://github.com/phpalto/code-highlight)[![PHPStan](https://camo.githubusercontent.com/022b70e6631d055205dfebf2aa7e53b3f63e7a3ea04a18e86429f279e29a29f1/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c25323031302d627269676874677265656e)](https://github.com/phpalto/code-highlight)[![PHP](https://camo.githubusercontent.com/25012e98b640e282284d84348b9c496c315c270928666c27e504e5fa10802102/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e342b2d3737374242343f6c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://www.php.net)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)

Features
--------

[](#features)

- **Built for PHP ecosystems:** Highlight the full stack—PHP, HTML, Twig, JavaScript, CSS, SQL, YAML, and 20+ more languages in a single library.
- **Zero dependencies:** No Node.js, Python, or external processes. Just Composer. Works in any PHP 8.4+ environment.
- **Full PHP syntax:** Semantic parser that understands context—distinguishes `class User` (definition) from `new User()` (usage), `function greet()` ( definition) from `greet()` (call).
- **Embedded languages:** Automatically switches parsers for `` and `` tags in HTML, fenced code blocks in Markdown, and `{% block css %}`in Twig.
- **Dark mode support:** Multiple dark themes included out of the box ( CupertinoDark, Dracula, Noctis) plus compatibility with 490+ Highlight.js and Prism themes.

Install
-------

[](#install)

```
composer require alto/code-highlight
```

Usage
-----

[](#usage)

```
use Alto\Code\Highlight\Highlighter;
use Alto\Code\Highlight\Theme\GitHubTheme;

// 1. Initialize with a theme
$highlighter = new Highlighter(new GitHubTheme());

// 2. Output the theme's CSS (typically in your )
echo "" . $highlighter->getTheme()->getStylesheet() . "";

// 3. Highlight your code
echo $highlighter->highlight($code, 'php');
```

Languages
---------

[](#languages)

### PHP

[](#php)

Alto uses a semantic parser for PHP that goes beyond pattern matching to understand code context. It correctly distinguishes between:

- **Definitions vs. usage:** `class User` vs. `new User()`, `function greet()`vs. `greet()`
- **Context-aware scoping:** Variables, function calls, class instantiation, method calls

### Embeddings

[](#embeddings)

Four languages support automatic embedded language detection:

- **HTML** — CSS in `` tags, JavaScript in `` tags
- **SVG** — CSS in `` tags, JavaScript in `` tags
- **Markdown** — Any language in fenced code blocks (````language`)
- **Twig** — Languages via block names (`{% block css %}`, `{% block javascript %}`)

### Full list

[](#full-list)

CategoryLanguages**Programming**Bash, C#, Go, Java, JavaScript, PHP, Python, Ruby, Rust, Swift, TypeScript**Markup**HTML, SVG, XML**Data**Diff, DotEnv, HTTP, JSON, YAML**Prose**Markdown**Query**SQL**Stylesheet**CSS, SCSS**Template**Twig**Config**Dockerfile, INI, MakefileThemes
------

[](#themes)

### Built-in themes

[](#built-in-themes)

Alto includes 7 built-in themes ready to use:

- **Light themes:** `Alto`, `GitHub`, `Polar`, `Solar`
- **Dark themes:** `CupertinoDark`, `Dracula`, `Noctis`

```
use Alto\Code\Highlight\Theme\DraculaTheme;

$highlighter = new Highlighter(new DraculaTheme());
```

### Dark mode

[](#dark-mode)

Three dark themes are included out of the box:

- **CupertinoDark** — macOS-inspired dark theme
- **Dracula** — Popular dark theme with vibrant colors
- **Noctis** — Low-contrast dark theme for extended coding sessions

### Compatibility

[](#compatibility)

Use existing CSS from the **Highlight.js** (240+ themes), **Prism** (250+ themes), or **TextMate** (.tmTheme) ecosystems:

```
use Alto\Code\Highlight\Adapter\HighlightJsThemeAdapter;

$theme = HighlightJsThemeAdapter::fromFile('/path/to/github-dark.css');
$highlighter = new Highlighter($theme);
```

```
use Alto\Code\Highlight\Adapter\TextMateThemeAdapter;

$theme = TextMateThemeAdapter::fromFile('/path/to/monokai.tmTheme', isDark: true);
$highlighter = new Highlighter($theme);
```

Integrations
------------

[](#integrations)

### Twig Extension

[](#twig-extension)

**[Twig Extension](https://github.com/phpalto/twig-code-highlight)** — Highlight code directly in Twig templates using blocks or filters.

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to [submit issues](https://github.com/phpalto/code-highlight/issues)or [pull requests](https://github.com/phpalto/code-highlight/pulls).

License
-------

[](#license)

Released by the [Alto project](https://github.com/phpalto) under the MIT License. See the [LICENSE](LICENSE) file for details.

###  Health Score

23

—

LowBetter than 28% of packages

Maintenance65

Regular maintenance activity

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/a8951d49b371d210280a58ce48969a07d1f49924810f8a1fab3a9343eb46fdc9?d=identicon)[simonandre](/maintainers/simonandre)

---

Top Contributors

[![smnandre](https://avatars.githubusercontent.com/u/1359581?v=4)](https://github.com/smnandre "smnandre (1 commits)")

### Embed Badge

![Health badge](/badges/alto-code-highlight/health.svg)

```
[![Health](https://phpackages.com/badges/alto-code-highlight/health.svg)](https://phpackages.com/packages/alto-code-highlight)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
