spatie/shiki-php
Bring Shiki's beautiful syntax highlighting to PHP. A simple static call highlights code using the same language engine as popular code editors, with 100+ languages and themes plus bundled Antlers and Blade support.
highlight.php, a Pygments port — no Node, but weaker fidelity to modern editor themes).highlightLines, addLines, deleteLines, focusLines) directly enables diff walkthroughs, tutorial step-throughs, "what changed in this release" changelogs, and annotated code review views. That's a roadmap unlock, not just a rendering detail — it's the difference between showing code and teaching code.spatie/laravel-markdown (which wraps this) versus a hand-rolled pipeline. That's a strong argument for not building custom Markdown-to-HTML rendering — the Blade grammar ships in the box, which matters for any product that documents Laravel code.Adopt when most of these hold:
npm install shiki step alongside Composer. This is the single biggest gate.laravel-markdown, commonmark-shiki-highlighter) already exist.Look elsewhere when:
highlight.php is the pragmatic fallback; Torchlight is the hosted fallback.Adoption risk to plan for: the Node-version coupling (NVM users are told to symlink into /usr/local/bin) and the Shiki major-version treadmill are the two operational failure modes seen in the changelog. Budget a CI job that exercises the highlight path, and pin both the Composer and npm sides.
For executives — one paragraph:
Code samples are a credibility surface for any developer-facing product, and today we either under-invest in them or pay a vendor per render. spatie/shiki-php lets us highlight code server-side using the same engine as VS Code, under an MIT license, with no vendor contract and no code leaving our infrastructure. It's a small, well-maintained Spatie package with an active changelog through 2026, and for Laravel projects it plugs into our existing Markdown pipeline rather than requiring a new one. The trade-off is a Node runtime in our deploy image — an operational cost, not a licensing or lock-in cost. Recommendation: adopt for pre-rendered docs and content, cache the output, and revisit only if we ever need per-request highlighting.
For engineering — the short version:
We add spatie/shiki-php plus the shiki npm package to the build image (Node 20+). Highlighting is a Node subprocess; treat it as a build-time or cache-warming operation, never a hot path. We get 100+ languages, Blade and Antlers grammars included, custom VS Code theme JSON, dual light/dark themes, and line-level annotations (highlightLines, addLines, deleteLines, focusLines) that we can style with our own CSS. On Laravel we use spatie/laravel-markdown and get most of this for free; on plain league/commonmark we use spatie/commonmark-shiki-highlighter. Two things to own explicitly: (1) pin both the Composer and npm versions — Shiki majors have broken us historically — and (2) add a smoke test in CI that highlights a large code block, since that path previously failed with an argument-list-too-long error before 2.3.3. Cache rendered HTML keyed on code hash + language + theme + line markers, and the performance question disappears.
Known alternatives, stated plainly: Torchlight if we'd rather pay than operate; highlight.php if Node is a hard no; client-side Shiki if highlighting never needs to be server-rendered.
How can I help you explore Laravel packages today?