Skip to content

Installation

phil/highlight

Requirements

RequirementWhy
PHP 8.5 or laterReadonly classes, typed constants, array_find() and array_any()

The library has no other dependency, not even an extension beyond PHP's core.

Installing

composer require phil/highlight

It is a library, not a bundle: there is nothing to register. Build a Highlighter where code is shown, once, and keep it: Highlighter::default() builds every tokenizer, which is cheap, and none holds state between two sources.

The themes

The HTML holds classes only; a theme colours them. Three ship in themes/:

FileColours
themes/light.cssFor a light background
themes/dark.cssFor a dark background
themes/auto.cssLight or dark as the system prefers, unless an ancestor carries data-theme="light" or data-theme="dark"

Serve the one you want from vendor/phil/highlight/themes/, copy it into the application's assets, or write your own (html-and-themes.md). phil/ux-bundle's stylesheet colours the same classes with its own colour roles: an application that loads it needs no theme from here.