https://github.com/dedalozzo/pygmentize
Pygmentize is a wrapper to `pygmentize`, the command line interface provided by Pygments, a python syntax highlighter.
https://github.com/dedalozzo/pygmentize
php pygments syntax-highlighter wrapper
Last synced: 10 months ago
JSON representation
Pygmentize is a wrapper to `pygmentize`, the command line interface provided by Pygments, a python syntax highlighter.
- Host: GitHub
- URL: https://github.com/dedalozzo/pygmentize
- Owner: dedalozzo
- License: apache-2.0
- Created: 2013-08-05T17:44:44.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2017-11-29T15:08:08.000Z (about 8 years ago)
- Last Synced: 2025-04-26T18:48:54.374Z (10 months ago)
- Topics: php, pygments, syntax-highlighter, wrapper
- Language: PHP
- Homepage:
- Size: 58.6 KB
- Stars: 35
- Watchers: 1
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://packagist.org/packages/3f/pygmentize)
[](https://packagist.org/packages/3f/pygmentize)
[](https://scrutinizer-ci.com/g/dedalozzo/pygmentize/build-status/master)
[](https://scrutinizer-ci.com/g/dedalozzo/pygmentize/?branch=master)
[](https://packagist.org/packages/3f/pygmentize)
[](https://packagist.org/packages/3f/pygmentize)
Pygmentize
==========
Pygmentize is a wrapper to `pygmentize`, the command line interface provided by [Pygments](http://pygments.org), a
Python syntax highlighter. Pygmentize is smart enough to raise an exception in case Pygments returns an error.
Composer Installation
---------------------
To install Pygmentize, you first need to install [Composer](http://getcomposer.org/), a Package Manager for
PHP, following those few [steps](http://getcomposer.org/doc/00-intro.md#installation-nix):
```sh
curl -s https://getcomposer.org/installer | php
```
You can run this command to easily access composer from anywhere on your system:
```sh
sudo mv composer.phar /usr/local/bin/composer
```
Pygmentize Installation
-----------------------
Once you have installed Composer, it's easy install Pygmentize.
1. Edit your `composer.json` file, adding Pygmentize to the require section:
```sh
{
"require": {
"3f/pygmentize": "dev-master"
},
}
```
2. Run the following command in your project root dir:
```sh
composer update
```
Usage
-----
Pygmentize is really easy to use, having only one static method. You just call `highlight()` like follows:
```php
Pygmentize::highlight($code, $language);
```
Methods
-------
### Pygmentize::highlight()
```php
public static function highlight(
$source,
$language,
$encoding = "utf-8",
$formatter = "html",
$style = "borland"
)
```
Formats the provided source code using the specified formatter and style.
**Parameters**
* source
The source code.
* language
The programming language name of the source code.
* encoding
The file input and output encodings.
* formatter
The output will be created using the provided formatter.
* style
The style used by the formatter.
**Returns**
Returns the highlighted source code.
**Exceptions**
* RuntimeException
Cannot execute the `pygmentize` command.
* RuntimeException
Cannot create the temporary file with the source code.
Documentation
-------------
The documentation can be generated using [Doxygen](http://doxygen.org). A `Doxyfile` is provided for your convenience.
Requirements
------------
- PHP 5.4.0 or above.
- [Pygments](http://pygments.org) 1.6 or above.
Authors
-------
Filippo F. Fadda - -
License
-------
Pygmentize is licensed under the Apache License, Version 2.0 - see the LICENSE file for details.