User:Orso/Geshi highlighter hack
From Vectorlab
Modified Geshi hightlighter. For the original code visit GeSHiHighlight
<?php
# GeSHiHighlight.php
#
# By: E. Rogan Creswick (aka: Largos), modified by: Orso B. Schmid (NIL)
# creswick@gmail.com
# wiki.ciscavate.org
#
# License: GeSHi Highlight is released under the Gnu Public License (GPL), and comes with no warranties.
# The text of the GPL can be found here: http://www.gnu.org/licenses/gpl.html
# Loosely based on SyntaxHighlight.php by Coffman, (www.wickle.com)
# you want to change the below two lines
require_once("geshi.php"); // i asume geshi.php is in the same directory as GeSHiHighlight.php (that is 'extensions' dir)
define("GESHI_PATH","extensions/geshi");// definition where are stored geshi language parsing files
define("_LANG_DEFAULT", "vss");
# ok, end of editing :)
class SyntaxSettings {};
$wgSyntaxSettings = new SyntaxSettings;
$wgExtensionFunctions[] = "wfSyntaxExtension";
$wgExtensionCredits['parserhook'][] = array(
'name' => 'GeSHi (version 1.0.7.16b) through GeSHiHighlight',
'author' => '[http://qbnz.com/highlighter/ Nigel McNie] (Geshi), [http://meta.wikimedia.org/wiki/GeSHiHighlight Rogan Creswick] (GeSHiHighlight), (patch: [http://vcor.net/wiki/index.php/User:Orso Orso B. Schmid])',
'description' => 'Generic Syntax Highlighter modified for supporting camelCase and inline code',
'url' => 'http://qbnz.com/highlighter/'
);
function wfSyntaxExtension() {
global $wgParser, $lang_default;
$langArray = geshi_list_languages(GESHI_PATH);
foreach ( $langArray as $lang ){
if ($lang == "") continue;
# Orso B. Schmid : preserve inline <code> tag.
$wgParser->setHook('code='.$lang,
create_function(
'$text',
'$geshi = new GeSHi(rtrim(ltrim($text,"\n\r")), ' ."$lang". ', GESHI_PATH);
$geshi->set_header_type(GESHI_HEADER_CODE);
$geshi->enable_classes(true);
return $geshi->parse_code();'
)
);
# Orso B. Schmid : Add this for block elements.
$wgParser->setHook('pre='.$lang,
create_function(
'$text',
'$geshi = new GeSHi(rtrim(ltrim($text,"\n\r")), ' ."$lang". ', GESHI_PATH);
$geshi->set_header_type(GESHI_HEADER_PRE);
$geshi->enable_classes(true);
return $geshi->parse_code();'
)
);
}
}
/*
$geshi->enable_classes(true);*/
/* Orso B. Schmid
With the following a separate tag is created for each language. Code doesn't function.
function wfSyntaxExtension() {
global $wgParser;
$langArray = geshi_list_languages(GESHI_PATH);
foreach ( $langArray as $lang ){
if ($lang == "") continue;
$wgParser->setHook( $lang,
create_function( '$text', '$geshi = new GeSHi(rtrim(ltrim($text,"\n\r")), ' ."$lang". ', GESHI_PATH);
return $geshi->parse_code();'));
}
}
*/
/**
* function: geshi_list_languages
* -------------------------
* List supported languages by reading the files in the geshi/geshi subdirectory
* (added by JeffK -- Jeff, any more contact info?) -- I haven't tested the code is is, will do that shortly. -Rogan
*
*/
function geshi_list_languages ( $path = 'geshi/' )
{
$lang_list = array();
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) { // Loop over the directory.
if(is_dir($file)) continue; // Drop anything that is a directory, cause we want files only
if( ".php" == substr($file, strrpos($file, "."),4)) // process only .php files
{
$lang_list[]= substr($file, 0, strrpos($file, "."));
}
}
closedir($handle);
}
sort($lang_list); //sort the output, i like ordered lists in Wiki Version page :)
return $lang_list;
}
?>
