Pygments.php - A Thin Wrapper for the Python Pygments
, (*1)
A PHP wrapper for the Python Pygments syntax highlighter, (*2)
Requirements
- PHP5.3+
- Python 2.4+
- Pygments (
sudo easy_install Pygments
)
Installation
Create or update your composer.json and run composer update
, (*3)
``` json
{
"require": {
"kzykhys/pygments": ">=1.0"
}
}, (*4)
Usage
-----
### Highlight the source code
``` php
<?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
<?php, (*5)
use KzykHys\Pygments\Pygments;, (*6)
$pygments = new Pygments();
$css = $pygments->getCss('monokai');
$prefixedCss = $pygments->getCss('default', '.syntax');, (*7)
### Guesses a lexer name
``` php
<?php
use KzykHys\Pygments\Pygments;
$pygments = new Pygments();
$pygments->guessLexer('foo.rb'); // ruby
``` php
<?php, (*8)
use KzykHys\Pygments\Pygments;, (*9)
$pygments = new Pygments();
$pygments->getLexers()
$pygments->getFormatters();
$pygments->getStyles();, (*10)
### Custom `pygmentize` path
``` php
<?php
use KzykHys\Pygments\Pygments;
$pygments = new Pygments('/path/to/pygmentize');
License
The MIT License, (*11)
Author
Kazuyuki Hayashi (@kzykhys), (*12)