Deprecated: Assigning the return value of new by reference is deprecated in /var/www/virtual/geshi.org/htdocs/wiki/inc/parser/xhtml.php on line 943

Deprecated: Function split() is deprecated in /var/www/virtual/geshi.org/htdocs/wiki/inc/parser/xhtml.php on line 494

Deprecated: Function split() is deprecated in /var/www/virtual/geshi.org/htdocs/wiki/inc/parser/xhtml.php on line 494

Deprecated: Function split() is deprecated in /var/www/virtual/geshi.org/htdocs/wiki/inc/parser/xhtml.php on line 494
Table of Contents

Theme Files

One of the limitations of GeSHi 1.0.X is that it’s very hard to get output that looks like your favourite IDE. You’re pretty much stuck to using the default colours, or you can change some of the colours for all languages. It would be much nicer if you could just tell GeSHi to theme your output like vim/eclipse/borland/other and it just worked :).

So GeSHi 1.1.X introduced theme files. These live in the geshi/themes/[theme-name] directory. The default theme is interestingly enough called “default”, and it’s in there where you should create a new directory named the same as your language. In the example, we would create a “test” directory, and in there we would create a “test.php” file.

The contents of the GeSHi theme file for PHP look something like this:

<?php
/**
 * GeSHi - Generic Syntax Highlighter
 * 
 * For information on how to use GeSHi, please consult the documentation
 * found in the docs/ directory, or online at http://geshi.org/docs/
 * 
 *  This file is part of GeSHi.
 *
 *  GeSHi is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  GeSHi is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with GeSHi; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * You can view a copy of the GNU GPL in the COPYING file that comes
 * with GeSHi, in the docs/ directory.
 *
 * @package    geshi
 * @subpackage theme
 * @author     Nigel McNie <nigel@geshi.org>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 2004 - 2006 Nigel McNie
 * @version    $Id: php.php,v 1.9 2006/06/24 07:46:10 oracleshinoda Exp $
 *
 */

/*
 * PHP styles for default theme
 */
$this->setStyle('start', 'font-weight:bold;color:#000;');
$this->setStyle('end', 'font-weight:bold;color:#000;');

$this->setStyle('keyword', 'color:#a1a100;');
$this->setStyle('type', 'color:#7f0055;');
$this->setStyle('constant', 'font-weight:bold;color:#000;');
$this->setStyle('function', 'color:#006;');

$this->setStyle('symbol', 'color:#008000;');
$this->setStyle('varstart', 'color:#33f;');
$this->setStyle('var', 'color:#33f;');

$this->setStyle('num/int', 'color:#11e;');
$this->setStyle('num/dbl', 'color:#c6c;');

$this->setStyle('oodynamic', 'color:#933;');
$this->setStyle('oostatic', 'color:#933;font-weight:bold;');

$this->setStyle('single_string', 'color:#f00;');
$this->setStyle('single_string/esc', 'color:#006;font-weight:bold;');
$this->setStyle('double_string', 'color:#f00;');
$this->setStyle('double_string/esc', 'color:#006;font-weight:bold;');

$this->setStyle('double_string/var', 'color:#22f;');
$this->setStyle('double_string/symbol', 'color:#008000;');
$this->setStyle('double_string/oodynamic', 'color:#933;');

$this->setStyle('heredoc', 'color:#f00;');
$this->setStyle('heredoc/start', 'color:#006;font-weight:bold;');
$this->setStyle('heredoc/end', 'color:#006;font-weight:bold;');
$this->setStyle('heredoc/esc', 'color:#006;font-weight:bold;');
$this->setStyle('heredoc/var', 'color:#22f;');
$this->setStyle('heredoc/symbol', 'color:#008000;');
$this->setStyle('heredoc/oodynamic', 'color:#933;');

$this->setStyle('single_comment', 'color:#888;font-style:italic;');
$this->setStyle('multi_comment', 'color:#888;font-style:italic;');
$this->setStyle('phpdoc_comment', 'color:#555;font-style:italic;');
$this->setStyle('phpdoc_comment/tag', 'color:#ca60ca;font-weight:bold;');
$this->setStyle('phpdoc_comment/link', 'color:#0095ff;font-weight:bold;');
$this->setStyle('phpdoc_comment/htmltag', 'color:#000;font-weight:bold;');

// Stuff set in the code parser
$this->setStyle('classname', 'color:#933;');
$this->setStyle('definedconstant', 'font-weight:bold;color:#444;');
$this->setStyle('phpdoc_comment/tagvalue', 'color:#0095ff;font-weight:bold;');
$this->setStyle('phpdoc_comment/var', 'color:#33f;');
$this->setStyle('functioncall', 'color:#600;font-weight:bold;');
$this->setStyle('functionname', 'color:#600;');

$this->loadStyles('html/html');

?>

As you can see, there’s just a bunch of calls to the $this→setStyle method, and one call to $this→loadStyles.

setStyle

The setStyle method is called like so:

<?php
$this->setStyle('context_name', 'styles');
?>

So following on from our example, we would need to do something like this:

<?php
$this->setStyle('keyword', 'color:#b1b100;');
?>

To make our keywords a yellow colour.

For the most part, theme files will consist entirely of calls to ‘‘setStyle’

loadStyles

This method is called to load the styles from another theme file. In the case of PHP, remember that PHP is embedded inside HTML, so the HTML styles are loaded by that call.


Previous | Up | Next

 
lang/dev/tutorial/5.txt · Last modified: 2011/09/01 13:03
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki