A PHP wrapper for the Python Pygments syntax highlighter
- PHP5.3+
- Python 2.4+
- Pygments (
sudo easy_install Pygments
)
Create or update your composer.json and run composer update
{
"require": {
"kzykhys/pygments": ">=1.0"
}
}
<?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');
<?php
use KzykHys\Pygments\Pygments;
$pygments = new Pygments();
$css = $pygments->getCss('monokai');
$prefixedCss = $pygments->getCss('default', '.syntax');
<?php
use KzykHys\Pygments\Pygments;
$pygments = new Pygments();
$pygments->guessLexer('foo.rb'); // ruby
<?php
use KzykHys\Pygments\Pygments;
$pygments = new Pygments();
$pygments->getLexers()
$pygments->getFormatters();
$pygments->getStyles();
<?php
use KzykHys\Pygments\Pygments;
$pygments = new Pygments('/path/to/pygmentize');
The MIT License
Kazuyuki Hayashi (@kzykhys)