svn: /phd/trunk/phpdotnet/phd/ Highlighter/GeSHi.php

From: Date: Wed, 21 Oct 2009 06:03:01 +0000
Subject: svn: /phd/trunk/phpdotnet/phd/ Highlighter/GeSHi.php
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-5177@lists.php.net to get a copy of this message
cweiske Wed, 21 Oct 2009 06:03:01 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=289819 Log: geshi highlighter, for use in own package Changed paths: A phd/trunk/phpdotnet/phd/Highlighter/ A phd/trunk/phpdotnet/phd/Highlighter/GeSHi.php Added: phd/trunk/phpdotnet/phd/Highlighter/GeSHi.php =================================================================== --- phd/trunk/phpdotnet/phd/Highlighter/GeSHi.php (rev 0) +++ phd/trunk/phpdotnet/phd/Highlighter/GeSHi.php 2009-10-21 06:03:01 UTC (rev 289819) @@ -0,0 +1,78 @@ +<?php +/** + * Syntax highlighting using GeSHi, the generic syntax highlighter. + * + * PHP version 5.3+ + * + * @category PhD + * @package PhD_GeSHi + * @author Christian Weiske <cweiske@php.net> + * @license http://www.opensource.org/licenses/bsd-license.php BSD Style + * @version SVN: $Id$ + * @link http://doc.php.net/phd/ + */ +namespace phpdotnet\phd; + +require 'geshi/geshi.php'; + +/** + * Syntax highlighting using GeSHi, the generic syntax highlighter. + * + * Note that this highlighter is particularly slow, because + * we need to instantiate a new geshi instance for each single code + * snippet. + * + * @category PhD + * @package PhD_GeSHi + * @author Christian Weiske <cweiske@php.net> + * @license http://www.opensource.org/licenses/bsd-license.php BSD Style + * @link http://doc.php.net/phd/ + */ +class Highlighter_GeSHi extends Highlighter +{ + /** + * Create a new highlighter instance for the given format. + * + * We use a factory so you can return different objects/classes + * per format. + * + * @param string $format Output format (pdf, xhtml, troff, ...) + * + * @return PhDHighlighter Highlighter object + */ + public static function factory($format) + { + if ($format != 'xhtml') { + return parent::factory($format); + } + + return new self(); + }//public static function factory(..) + + + + /** + * Highlight a given piece of source code. + * Works for xhtml only. Falls back to original highlighter for + * other formats. + * + * @param string $text Text to highlight + * @param string $role Source code role to use (php, xml, html, ...) + * @param string $format Output format (pdf, xhtml, troff, ...) + * + * @return string Highlighted code + */ + public function highlight($text, $role, $format) + { + $geshi = new \GeSHi($text, $role); + $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); + return $geshi->parse_code(); + }//public function highlight(..) + +} + +/* +* vim600: sw=4 ts=4 syntax=php et +* vim<600: sw=4 ts=4 +*/ +

« previous php.doc.cvs (#5177) next »