tempest/highlight
Fast, extensible server-side syntax highlighting for PHP. Tempest Highlight parses code with a simple Highlighter API and supports multiple languages for rendering highlighted output in apps, docs, and tooling—install via Composer and start highlighting in minutes.
spatie/laravel-markdown).larapack/dd in v2.8.2) suggest stability but require validation of symfony/var-dumper compatibility.{{ $highlighter->parse($code, 'php') }} directly in views.spatie/laravel-markdown to auto-highlight code blocks.booted event to pre-process code snippets during content creation.// app/Http/Middleware/HighlightCode.php
public function handle($request, Closure $next) {
$response = $next($request);
if ($request->is('docs/*')) {
$response->setContent(
preg_replace_callback(
'/<code>(.*?)<\/code>/s',
fn($matches) => '<code>' . $highlighter->parse($matches[1], 'php') . '</code>',
$response->getContent()
)
);
}
return $response;
}
highlighted_code column) to avoid reprocessing static content.| Step | Priority | Effort | Dependencies |
|---|---|---|---|
| Composer Install | High | Low | None |
| Benchmark Baseline | High | Medium | Existing client-side highlighter |
| Blade Template Hook | Medium | Low | Laravel views |
| API Response Hook | Medium | Medium | API routes |
| Caching Layer | Low | Medium | Redis/Memcached |
| Custom Language | Low | High | Tempest extension docs |
config/highlight.php) for consistency across projects.{{ highlight('php', $code) }}").language + code_hash to avoid reprocessing identical content.
// Example: Cache highlighted output for 1 hour
$cacheKey = "highlight_{$language}_{md5($code)}";
return Cache::remember($cacheKey, now()->addHours(1), function() use ($highlighter, $code, $language) {
return $highlighter->parse($code, $language);
});
| Failure Scenario | Impact | Mitigation Strategy |
|---|---|---|
| Unsupported language | Unhighlighted code blocks | Fallback to plain text or generic syntax |
| Parsing performance bottleneck | Slow API responses | Cache highlighted output + queue jobs |
| Theme CSS conflicts | Broken styling | Use inline CSS or isolate theme variables |
| Dependency vulnerabilities | Security risks | Monitor Tempest’s security advisories |
| Database bloat (cached HTML) | Storage overhead | Set TTLs and prune old cache entries |
$highlighter->parse($code, 'php')).php artisan highlight:test command to validate all code blocks in the codebase.// app/Console/Commands/TestHighlighting.php
public function handle() {
$files = File::allFiles(app_path());
foreach ($files as $file) {
$code = File::get($file);
$language = $file->extension();
$highlighted = $this->highlighter->parse($code, $language);
$this->info("✅ $file");
}
}
How can I help you explore Laravel packages today?