summaryrefslogtreecommitdiff
path: root/vendor/kzykhys/pygments/README.md
blob: 64ead7c77bbdf98169b945682cc3852be9076fc7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
Pygments.php - A Thin Wrapper for the Python Pygments
=====================================================

[![Latest Stable Version](https://poser.pugx.org/kzykhys/pygments/v/stable.png)](https://packagist.org/packages/kzykhys/pygments)
[![Build Status](https://travis-ci.org/kzykhys/Pygments.php.png?branch=master)](https://travis-ci.org/kzykhys/Pygments.php)
[![Coverage Status](https://coveralls.io/repos/kzykhys/Pygments.php/badge.png)](https://coveralls.io/r/kzykhys/Pygments.php)

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`

``` json
{
    "require": {
        "kzykhys/pygments": ">=1.0"
    }
}
```

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

use KzykHys\Pygments\Pygments;

$pygments = new Pygments();
$css = $pygments->getCss('monokai');
$prefixedCss = $pygments->getCss('default', '.syntax');
```

### Guesses a lexer name

``` php
<?php

use KzykHys\Pygments\Pygments;

$pygments = new Pygments();
$pygments->guessLexer('foo.rb'); // ruby
```

### Get a list of lexers/formatters/styles

``` php
<?php

use KzykHys\Pygments\Pygments;

$pygments = new Pygments();
$pygments->getLexers()
$pygments->getFormatters();
$pygments->getStyles();
```

### Custom `pygmentize` path

``` php
<?php

use KzykHys\Pygments\Pygments;

$pygments = new Pygments('/path/to/pygmentize');
```

License
-------

The MIT License

Author
------

Kazuyuki Hayashi (@kzykhys)