kzykhys / pygments
A Thin Wrapper for the Python Pygments
Installs: 14 050
Dependents: 4
Suggesters: 4
Security: 0
Stars: 10
Watchers: 2
Forks: 13
Open Issues: 7
pkg:composer/kzykhys/pygments
Requires
- php: >=5.3.2
- symfony/process: >=2.3
Requires (Dev)
- symfony/finder: >=2.3
This package is not auto-updated.
Last update: 2025-10-21 08:51:30 UTC
README
A PHP wrapper for the Python Pygments syntax highlighter
Requirements
- PHP5.3+
- Python 2.4+
- Pygments (sudo easy_install Pygments)
Installation
Create or update your composer.json and run composer update
{
    "require": {
        "kzykhys/pygments": ">=1.0"
    }
}
Usage
Highlight the source code
<?php use KzykHys\Pygments\Pygments; $pygments = new Pygments(); $html = $pygments->highlight(file_get_contents('index.php'), 'php', 'html'); $text = $pygments->highlight('package main', 'go', 'ansi');
Generate a CSS
<?php use KzykHys\Pygments\Pygments; $pygments = new Pygments(); $css = $pygments->getCss('monokai'); $prefixedCss = $pygments->getCss('default', '.syntax');
Guesses a lexer name
<?php use KzykHys\Pygments\Pygments; $pygments = new Pygments(); $pygments->guessLexer('foo.rb'); // ruby
Get a list of lexers/formatters/styles
<?php use KzykHys\Pygments\Pygments; $pygments = new Pygments(); $pygments->getLexers() $pygments->getFormatters(); $pygments->getStyles();
Custom pygmentize path
<?php use KzykHys\Pygments\Pygments; $pygments = new Pygments('/path/to/pygmentize');
License
The MIT License
Author
Kazuyuki Hayashi (@kzykhys)