Topic: Code hilighting
Motivated by : http://punbb.org/forums/viewtopic.php?id=5666
I moved this into its own thread (I hope moderators dont mind)
I added GeSHi code hilighting support into punBB, it is easy !
Demo:http://jobs.gotoguide.org/viewtopic.php?pid=1044
Here's what I did
Download GeSHi from http://qbnz.com/highlighter/
copy geshi.php and geshi directory to punbb include directory
Now open parser.php file add these two functions at end of file (paste it before ?>)
function hilight($text,$lang){
$result='';
//recontruct the string
$text='[h='.$lang.']'.$text.'[/h]';
$array= preg_split('#\[/h\]#',$text,-1,PREG_SPLIT_NO_EMPTY);
for ( $counter = 0; $counter <count($array); $counter ++) {
$result=$result . preg_replace('#\[h=(.*?)\]((.|\s)*)\[/h\]#e','geshify(\'$2\', \'$1\')',$array[$counter].'[/h]');
}
return $result;
}
function geshify($text,$lang){
include_once('geshi.php');
$geshi = new GeSHi($text,$lang);
$geshi->set_header_type(GESHI_HEADER_DIV);
return $geshi->parse_code();
}
now find this line (line 321 )
$text = preg_replace($pattern, $replace, $text);
then add this line next to the above line
$text=preg_replace('#\[h=(.*?)\]((.|\s)*)\[/h\]#e','hilight(\'$2\', \'$1\')',$text);
that is it. it works.