Skip to content
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

PHPygments - PHP syntax highlighter based on Pygments

Server side syntax highlighter based on Pygments highlighter software.


To use this plugin you need pygments in your server:

sudo apt-get install python-setuptools
easy_install Pygments

That's all. Now you can download the plugin via Composer or as independent library and use it.


require "../PHPygments.php";

$code = file_get_contents("test.js");
$result = PHPygments::render($code, "js");

//Load CSS for this highlighted code
foreach ($result["styles"] as $style) {
  print '<link href="' . $style . '" media="all" rel="stylesheet" type="text/css" />';

//and print the code.
echo $result["code"];


PHPygments::render($code, $language, $style, $linenumbers)

  • $code: the source code to highlight
  • $language: Language type. see section "Languages and filetypes supported" in this doc.
  • $style: Color style to use (default to "default" style). see "Color styles" un this doc.
  • $linenumbers: inline or table, the line numbers will be added as independent table column or as part of the line.


//comment line
var foo = "foo";
var bar = function(){
	var baz;

Outputs highlighted js with default style, and no line numbers.

[javascript style="monokai" linenumbers="inline"]
//comment line
var foo = "foo";
var bar = function(){
	var baz;

Outputs highlighted js with monokai style with line numbers (as part of the line).

[javascript style="monokai" linenumbers="table"]
//comment line
var foo = "foo";
var bar = function(){
	var baz;

Outputs highlighted js with monokai style with line numbers (as new column).

Color styles

These are supported color styles:

  • monokai
    monokai example

  • manni
    monokai example

  • rrt
    monokai example

  • perldoc
    monokai example

  • borland
    monokai example

  • colorful
    monokai example

  • default
    monokai example

  • murphy
    monokai example

  • vs
    monokai example

  • trac
    monokai example

  • tango
    monokai example

  • fruity
    monokai example

  • autumn
    monokai example

  • bw
    monokai example

  • emacs
    monokai example

  • vim
    monokai example

  • pastie
    monokai example

  • friendly
    monokai example

  • native
    monokai example

Languages and filetypes supported

Pygments not only highlights languages. also highlights filetypes like .conf Nginx configuration file, Apache (filenames .htaccess, apache.conf, apache2.conf), etc.

NOTE: to use see "Usage" section

  • apacheconf: (.htaccess, apache.conf, apache2.conf)
  • bash, sh, ksh: (*.sh, *.ksh, *.bash, *.ebuild, *.eclass, .bashrc, bashrc)
  • ini, cfg: (*.ini, *.cfg)
  • makefile: (.mak, Makefile, makefile, Makefile., GNUmakefile)
  • nginx: Nginx configuration file
  • yaml: (*.yaml, *.yml)
  • perl: Perl (*.pl, *.pm)
  • (*.vb, *.bas)
  • console: Bash Session (*.sh-session)
  • javascript: Pure Javascript
  • coffeescript: Pure CoffeeScript
  • json: Pure JSON
  • cssphp: PHP embedded in CSS
  • htmlphp: PHP embedded in HTML
  • jsphp: PHP embedded in JS
  • php: Pure PHP
  • xmlphp: PHP embedded in XML
  • ruby, duby: Ruby (*.rb, *.rbw, *.rake, *.gemspec, *.rbx, *.duby)
  • csserb, cssruby: Ruby embedded in CSS
  • xmlerb, xmlruby: Ruby embedded in XML
CSS and CSS compilers
  • css: CSS (*.css)
  • sass: Sass (*.sass)
  • scss: SCSS (*.scss)
HTML and HTML template systems
  • html: HTML (*.html, *.htm, *.xhtml, *.xslt)
  • haml: Haml (*.haml)
  • jade: Jade (*.jade)
  • sql: SQL (*.sql)
  • sqlite3: sqlite3con (*.sqlite3-console)
  • mysql: MySQL
Python, jinja & Django
  • python: Pure Python
  • python3: Pure Python 3
  • xmldjango, xmljinja: Django/Jinja embedded in XML
  • cssdjango, cssjinja: Django/Jinja embedded in CSS
  • django, jinja: Pure Django/Jinja
  • htmldjango, htmljinja: Django/Jinja embedded in HTML
  • jsdjango, jsjinja: Django/Jinja embedded in Javascript
Java && family
  • java: Java (*.java)
  • clojure: clojure (*.clj)
  • groovy: Groovy (*.groovy)
  • jsp: Java Server Page (*.jsp)
C, C++, Objetive-c, C Sharp
  • cobjdump: c-objdump (*.c-objdump)
  • c: C (*.c, *.h, *.idc)
  • cpp: C++ (*.cpp, *.hpp, *.c++, *.h++, *.cc, *.hh, *.cxx, *.hxx)
  • csharp: C# (*.cs)
  • objectivec: (*.m)
  • xml: (*.xml, *.xsl, *.rss, *.xslt, *.xsd, *.wsdl)
  • xslt: (*.xsl, *.xslt)
You can’t perform that action at this time.