The Wayback Machine - https://web.archive.org/web/20200916125746/https://github.com/ramsey/pygments
Skip to content
master
Go to file
Code
This branch is 47 commits ahead of kzykhys:master.

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

ramsey/pygments

Source Code Latest Version Software License Build Status Coverage Status Total Downloads

ramsey/pygments is a PHP wrapper for Pygments, the Python syntax highlighter, forked from the Pygments.php project.

This project adheres to a Contributor Code of Conduct. By participating in this project and its community, you are expected to uphold this code.

Requirements

  • PHP 5.5.9 or greater (including PHP 7)
  • Python
  • Pygments (pip install Pygments)

Python and Pygments versions supported:

Pygments: 1.6 2.0 2.1 2.2
Python 2.6 -
Python 2.7
Python 3.2 - - -
Python 3.3
Python 3.4
Python 3.5
Python 3.6

Installation

The preferred method of installation is via Packagist and Composer. Run the following command to install the package and add it as a requirement to your project's composer.json:

composer require ramsey/pygments

Usage

Highlight source code

use Ramsey\Pygments\Pygments;

$pygments = new Pygments();
$html = $pygments->highlight(file_get_contents('index.php'), 'php', 'html');
$text = $pygments->highlight('package main', 'go', 'ansi');

Generate CSS

use Ramsey\Pygments\Pygments;

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

Guesses lexer name

use Ramsey\Pygments\Pygments;

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

Get a list of lexers/formatters/styles

use Ramsey\Pygments\Pygments;

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

Set a custom pygmentize path

use Ramsey\Pygments\Pygments;

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

Copyright and license

Copyrights for portions of ramsey/pygments are held by Kazuyuki Hayashi as part of Pygments.php. All other copyrights for ramsey/pygments are held by Ben Ramsey. Please see LICENSE for more information.

About

A PHP wrapper for Pygments, the Python syntax highlighter, forked from the Pygments.php project

Topics

Resources

License

Packages

No packages published

Languages

You can’t perform that action at this time.