kzykhys/pygments
Thin PHP wrapper around the Python Pygments syntax highlighter. Highlight code to HTML/ANSI, generate CSS for styles (e.g., monokai), guess lexer by filename, and list available lexers/formatters/styles. Supports custom pygmentize path.
exec(), proc_open()) to call pygmentize, which may:
highlight($_GET['code'], $_GET['lexer'])).voku/highlight (pure PHP, actively maintained).php-pygments (abandoned but more active).AppServiceProvider:
$this->app->singleton(Pygments::class, function ($app) {
return new \KzykHys\Pygments\Pygments('/usr/bin/pygmentize');
});
PygmentsFacade for clean syntax:
use Facades\Pygments;
$html = Pygments::highlight($code, 'php');
@highlight:
Blade::directive('highlight', function ($code) {
return "<?php echo app('Pygments')->highlight($code[1], '$1'); ?>";
});
md5($code.$lexer) in Redis/Memcached:
$cacheKey = "pygments:{$lexer}:".md5($code);
$html = cache()->remember($cacheKey, now()->addHours(1), function () use ($code, $lexer) {
return app(Pygments::class)->highlight($code, $lexer);
});
/highlight endpoint).pip install Pygments).FROM php:8.1-apache
RUN apt-get update && apt-get install -y python python-pip
RUN pip install Pygments
pygmentize failures.try {
return app(Pygments::class)->highlight($code, $lexer);
} catch (\Exception $e) {
return "<pre><code>$code</code></pre>";
}
create_function).pygmentize path (default: /usr/bin/pygmentize).$pygments->getLexers().pygmentize failures and Python-related errors.pip install --upgrade Pygments).pygmentize path issues.pygmentize path misconfigured → highlighting failures.| Failure Scenario | Impact | Mitigation |
|---|
How can I help you explore Laravel packages today?