1 cyberodin Mar 19, 2005 15:37
3 cyberodin Mar 19, 2005 16:07
OK - This is what I got so far (it is nearly a 1:1 port of the Serendipity plugin). Unfortunatly the inline source code of a blog post won't be highlighted - Don't know what's wrong :(
<?php
/**
* This file implements is a simple wrapper to the GeSHi syntax highlighting engine.
*
* b2evolution - {@link http://b2evolution.net/}
* Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
* @copyright (c)2003-2004 by Francois PLANQUE - b2evolution - {@link http://fplanque.net/}
* @copyright (c)2004 by Nigel McNie - GeSHi - {@link http://qbnz.com/highlighter/}
* @copyright (c)2004 by Daniel S. Haischt - b2evo renderer- {@link http://www.foobar.com/}
*
* @package plugins
*/
if( !defined('EVO_CONFIG_LOADED') ) die( 'Please, do not access this page directly.' );
// if( !defined('DB_USER') ) die( 'Please, do not access this page directly.' );
/**
* @package plugins
*/
class geshi_plugin extends Plugin
{
var $code = 'b2evGeshi';
var $name = 'Geshi';
var $priority = 80;
var $apply_when = 'opt-out';
var $apply_to_html = true;
var $apply_to_xml = false;
var $short_desc;
var $long_desc;
/**
* Constructor
*
* {@internal geshi_plugin::geshi_plugin(-)}}
*/
function geshi_plugin()
{
$this->short_desc = T_('Provides source code syntax highlighting');
$this->long_desc = T_('No description available');
}
/**
* Perform rendering
*
* {@internal geshi_plugin::Render(-)}}
*
* @param array Associative array of parameters
* (Output format, see {@link format_to_output()})
* @return boolean true if we can render something for the required output format
*/
function Render( & $params )
{
if( ! parent::Render( $params ) )
{ // We cannot render the required format
return false;
}
require_once(dirname(__FILE__). '/geshi.php');
$content = & $params['data'];
$content = preg_replace_callback(
"/\[geshi(\s)+lang=([A-Za-z]+)\](.*?)\[\/geshi\]/is",
"geshicallback",
$content);
return true;
}
function geshicallback($matches) {
$geshilang = strtolower($matches[2]);
//echo "\n<!-- lang: $geshilang -->\n";
$pathtogeshi = dirname(__FILE__). '/geshi';
//echo "\n<!-- PathtoGeshi: $pathtogeshi -->\n";
$geshi = new GeSHi($matches[3], $geshilang, 'geshi');
$geshi->set_header_type(GESHI_HEADER_DIV);
$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
// Have to get rid of newlines.
return str_replace("\n", '', $geshi->parse_code());
}
}
?>
I put the geshi.php file into the plugins directory. The GeSHi language files are located within a directory called geshi under plugins.
The following markup within a post for example, will be considered to be transformed by GeSHi:
[geshi lang=php]var $code = 'b2evMrkdwn';[/geshi]
4 mattbta Mar 19, 2005 16:14
Google is your friend:
http://www.google.com/search?q=b2evolution+geshi
The first link in that search:
http://richardleggett.co.uk/blog/index.php/2004/12/19/geshi_renderer_aamp_proxy_classes_for_b2
Nope. Would be a good tool though if anyone did it.