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.

Re: Code hilighting

A filler to make it 100 posts

3 (edited by zaher 2005-06-19 23:39)

Re: Code hilighting

ehh, why you dublicate a MOD http://www.punres.org/viewtopic.php?id=188

1- this MOD hilght useing GeShe or phpMSH (mine), just read gehsi_readme.txt file to enable it
2- there is no problem with <> charchaters because i take text and code in array and parse it eche alone
3- useing CODE tage like as [ code= php ] or [ code ] for plan text

if you have any probelm it just post in same topic

If your people come crazy, you will not need to your mind any more.

Re: Code hilighting

I searched for GeSHi, I cldnt find it, sorry for the trouble - I requested moderators to remove/close this thread

5

Re: Code hilighting

No dont remove it, still work on it, i just notice you for that MOD, (maybe my bad english show me as angry tongue)
may be you can imrove my MOD also and test it.

If your people come crazy, you will not need to your mind any more.

Re: Code hilighting

Thanks. unless this simple integration is useful to someone, I am not planning to work on it anymore.

Re: Code hilighting

druvans i don't think this thread should be removed, it might be useful to someone smile

8

Re: Code hilighting

I agree, this is indeed helpful. Thanks for all your hard work.

GET ON THE TELEPHONE!!

9 (edited by Dexus 2005-07-22 09:10)

Re: Code hilighting

Anyways, if there are much highlighted areas in 20 posts (on single page page), GeSHi can dramatically slow down the server.
Some sort of "parsed-cached" message version will be useful.

I don't know if there any SQL DB blowing up or slowing down if there will be one extra field with 16Mb text field (related to original 65K).
Also some sort of "uncache" flag field, if "parser.php" have been rewritten.
And so on...
Well, i'd thinking of it long ago and still haven't started to implement even a part of it smile
Good luck!

10

Re: Code hilighting

Check mod link it is use phpMSH instead of geshi (you can use GeShi also), but i found phpMSH faster than GeSHI 3..10 times, with out Line numbers.
geshi use RegEx mean useing memory too match and playing with cuting and move strings.
msh use scan lines and can make more recognize code rules, the bad thing is i have not time to support all language my my self, it must done by another user.

If your people come crazy, you will not need to your mind any more.

Re: Code hilighting

Dexus wrote:

Anyways, if there are much highlighted areas in 20 posts (on single page page), GeSHi can dramatically slow down the server.
Some sort of "parsed-cached" message version will be useful.

I don't know if there any SQL DB blowing up or slowing down if there will be one extra field with 16Mb text field (related to original 65K).
Also some sort of "uncache" flag field, if "parser.php" have been rewritten.
And so on...
Well, i'd thinking of it long ago and still haven't started to implement even a part of it smile
Good luck!

May you cld pre-parse the text before saving to DB and set your parsed flag=true

12

Re: Code hilighting

Druvans, i doubt, because:
1. parsed text 100% will be larger then not parsed, so 65535 message length limit will be exceeded.
2. if you wish to "edit" text, you will face "tags".
so there is no alternative to cached field (16Mb).

Re: Code hilighting

Dexus wrote:

Druvans, i doubt, because:
1. parsed text 100% will be larger then not parsed, so 65535 message length limit will be exceeded.
2. if you wish to "edit" text, you will face "tags".
so there is no alternative to cached field (16Mb).

The whole bbcode business is extremly dependent on regExs, so it will be a total rewrite of parser.php, I guess