Formatter: GeSHi Code Highlighting

Compatible with: R6.0
Current version: 0.2

Repo: community/formatter/highlight/geshi.php
GeSHi Documentation

1. Usage

Call via (geshi [formatter])

%%(geshi php numbers=1 start=35 lines=37) source%%

2. Install

  1. place the GeSHi lib under the lib/geshi/ folder
  2. add the GeSHi class to autoload.conf
    lib/geshi/geshi.php 			GeSHi
  3. add geshi.php highlighter to the formatter/highlight/ folder



# require_once 'lib/geshi/geshi.php'; // -> autoload.conf

if ($options['_default'])
$language    $options['_default'];
$lines        = [];
$start        = (int)($options['start'] ?? 1);
$header        GESHI_HEADER_PRE_VALID;

$geshi = new GeSHi($text$language);

    if (!empty(
$lines array_map('intval'explode(','$options['lines']));
$lines array_unique($lines);

    if (!empty(

        switch (
$header false;

$geshi->enable_classes();            // use classes for highlighting (must be first after creating object)
$geshi->set_overall_class('code');    // enables using a single stylesheet for multiple code fragments
$geshi->set_tab_width(4);            // default: 8


$geshi->enable_line_numbers((bool) $numbers); // GESHI_NORMAL_LINE_NUMBERS GESHI_FANCY_LINE_NUMBERS, 2 GESHI_NO_LINE_NUMBERS
$geshi->start_line_numbers_at((int) abs($start));

    // get the stylesheet -> geshi.css
echo '<style type="text/css">';

echo '<!--notypo-->' "\n";
'<!--/notypo-->' "\n";

2.1. External stylesheet

GeSHi comes with a contrib/ directory, which in it contains a “wizard” script for creating a stylesheet.

geshi.css (incomplete)
/* GeSHi – syntax highlighting code */

.code .de1, .code .de2 {font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align\top;}
.code  {font-family:monospace;}
.code .imp {font-weight: bold; color: red;}
.code li, .code .li1 {font-weight: normal; vertical-align\top;}
.code .ln width:1px;text-align\right;margin:0;padding:0 2px;vertical-align\top;}
.code .li2 {font-weight: bold; vertical-align\top;}
.code .kw2 {color: #000000; font-weight: bold;}
.code .kw3 {color: #000066;}
.code .es0 {color: #000099; font-weight: bold;}
.code .br0 {color: #66cc66;}
.code .sy0 {color: #66cc66;}
.code .st0 {color: #ff0000;}
.code .nu0 {color: #cc66cc;}
.code .sc-2 {color: #404040;}
.code .sc-1 {color: #808080; font-style: italic;}
.code .sc0 {color: #00bbdd;}
.code .sc1 {color: #ddbb00;}
.code .sc2 {color: #009900;}
.code .ln-xtra, .code li.ln-xtra, .code div.ln-xtra {background-color: #ffc;}
.code span.xtra { display:block; } 

// add to theme/_common/_header.php
$this->add_html('header', '<link rel="stylesheet" href="' . $this->db->theme_url . 'css/geshi.css">');

3. Supported Formats

# Language Formatter
Actionscript actionscript
ADA  ada
Apache Log  apache
AppleScript applescript
ASM  asm
ASP  asp
AutoIT autoit
Bash bash
BlitzBasic blitzbasic
bnf  bnf
C for Macs c_mac
C# csharp
C++ cpp
C++ (+QT) cpp-qt
CAD DCL caddcl
CadLisp cadlisp
CFDG cfdg
ColdFusion cfm
CSS  css
Delphi delphi
Diff-Output diff
DIV  div
DOS  dos
Eiffel eiffel
Fortran fortran
FreeBasic freebasic
GML  gml
Groovy groovy
HTML html4strict
INI  ini
Inno Script inno
Io  io
Java 5 java5
Java java
Javascript javascript
LaTeX latex
Lisp lisp
Lua  lua
Matlab matlab
mIRC Scripting mirc
Microchip Assembler mpasm
Microsoft Registry reg
MySQL mysql
NSIS nsis
Objective C  objc
OpenOffice BASIC oobas
Objective Caml ocaml
Objective Caml (brief) ocaml-brief
Oracle 8 oracle8
Pascal pascal
Perl perl
PHP  php
PHP (brief) php-brief
PL/SQL plsql
Python phyton
Q(uick)BASIC qbasic
robots.txt robots
Ruby ruby
SAS  sas
Scheme scheme
sdlBasic sdlbasic
Smarty smarty
SQL  sql
TCL/iTCL tcl
T-SQL tsql
Text text
thinBasic thinbasic
Unoidl idl
VB.NET vbnet
VHDL vhdl
Visual BASIC vb
Visual Fox Pro visualfoxpro
WinBatch winbatch
XML  xml
ZiLOG Z80 Assembler z80