|
1 | 1 | Pygments.php - A Thin Wrapper for the Python Pygments |
2 | 2 | ===================================================== |
3 | 3 |
|
| 4 | +A PHP wrapper for the Python Pygments syntax highlighter |
| 5 | + |
4 | 6 | Requirements |
5 | 7 | ------------ |
6 | 8 |
|
7 | 9 | * PHP5.3+ |
8 | 10 | * Python 2.4+ |
9 | 11 | * Pygments (`sudo easy_install Pygments`) |
| 12 | + |
| 13 | +Installation |
| 14 | +------------ |
| 15 | + |
| 16 | +Create or update your composer.json and run `composer update` |
| 17 | + |
| 18 | +``` json |
| 19 | +{ |
| 20 | + "require": { |
| 21 | + "kzykhys/pygments": ">=1.0" |
| 22 | + } |
| 23 | +} |
| 24 | +``` |
| 25 | + |
| 26 | +Usage |
| 27 | +----- |
| 28 | + |
| 29 | +### Highlight the source code |
| 30 | + |
| 31 | +``` php |
| 32 | +<?php |
| 33 | + |
| 34 | +use KzykHys\Pygments\Pygments; |
| 35 | + |
| 36 | +$pygments = new Pygments(); |
| 37 | +$html = $pygments->highlight(file_get_contents('index.php'), 'php', 'html'); |
| 38 | +$text = $pygments->highlight('package main', 'go', 'ansi'); |
| 39 | +``` |
| 40 | + |
| 41 | +### Generate a CSS |
| 42 | + |
| 43 | +``` php |
| 44 | +<?php |
| 45 | + |
| 46 | +use KzykHys\Pygments\Pygments; |
| 47 | + |
| 48 | +$pygments = new Pygments(); |
| 49 | +$css = $pygments->getCss('monokai'); |
| 50 | +$prefixedCss = $pygments->getCss('default', '.syntax'); |
| 51 | +``` |
| 52 | + |
| 53 | +### Guesses a lexer name |
| 54 | + |
| 55 | +``` php |
| 56 | +<?php |
| 57 | + |
| 58 | +use KzykHys\Pygments\Pygments; |
| 59 | + |
| 60 | +$pygments = new Pygments(); |
| 61 | +$pygments->guessLexer('foo.rb'); // ruby |
| 62 | +``` |
| 63 | + |
| 64 | +### Get a list of lexers/formatters/styles |
| 65 | + |
| 66 | +``` php |
| 67 | +<?php |
| 68 | + |
| 69 | +use KzykHys\Pygments\Pygments; |
| 70 | + |
| 71 | +$pygments = new Pygments(); |
| 72 | +$pygments->getLexers() |
| 73 | +$pygments->getFormatters(); |
| 74 | +$pygments->getStyles(); |
| 75 | +``` |
| 76 | + |
| 77 | +### Custom `pygmentize` path |
| 78 | + |
| 79 | +``` php |
| 80 | +<?php |
| 81 | + |
| 82 | +use KzykHys\Pygments\Pygments; |
| 83 | + |
| 84 | +$pygments = new Pygments('/path/to/pygmentize'); |
| 85 | +``` |
| 86 | + |
| 87 | +License |
| 88 | +------- |
| 89 | + |
| 90 | +The MIT License |
| 91 | + |
| 92 | +Author |
| 93 | +------ |
| 94 | + |
| 95 | +Kazuyuki Hayashi (@kzykhys) |
0 commit comments