Topic: PHP Tag

I'd like to propose integration of a PHP tag. This would allow devs like me to display code in a highlighted and more readable format. For an example of what I mean, visit this page. All the PHP in that article lies between php tags (using a heavily modified parsing engine). As I am not yet familiar with the PunBB engine, I cannot create this functional code right away

Also, for XHTML compliance, the following function can be used on highlight_string() output:

function xhtml_highlight($str) {
   $str = highlight_string($str, true);
   $str = str_replace(array('<font ', '</font>'), array('<span ', '</span>'), $str);
   return preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str);
}

Re: PHP Tag

There is a syntax hightlight [ code] tag mod - http://punbb.org/forums/viewtopic.php?id=4243 - it might be done for 1.2

Re: PHP Tag

Bwongar.com wrote:

I'd like to propose integration of a PHP tag.

This is not a feature I'd like to see in the official PunBB. Why PHP and why not Perl, Ruby, C, ... ?

<code> is enough, use/create a mod if you want more.

4 (edited by Bwongar.com 2005-01-08 23:44)

Re: PHP Tag

analogue wrote:

This is not a feature I'd like to see in the official PunBB. Why PHP and why not Perl, Ruby, C, ... ?

<code> is enough, use/create a mod if you want more.

PHP offers syntax highlighting by default, so why not leverage it for easy use? It's a simple matter and I will no doubt integrate it into my board. However, other syntax highlighting would require external modus, therefore adding size to PunBB by leaps and bounds. Generic syntax highlighting is possible, albeit useless for my work. It makes sense to me that an application written in a specific language does service to promote usage of that language.

Whatever. I guess it doesn't matter what I think.

5

Re: PHP Tag

One of the nicest syntax highlighters is called Geshi: http://qbnz.com/highlighter/

This is the highlighter used in DokuWiki and a plugin for Blog:CMS/Nucleus was written from it.

Plugin for PunBB?

Re: PHP Tag

I'm with analogue on this. Sure, PHP supplies us with a built-in function for highlighting PHP code, but it doesn't make sense to only highlight PHP code. The fact that PunBB is scripted in PHP means nothing to the average user. Adding a BBCode tag for highlighting PHP code would just confuse people.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: PHP Tag

It matters what you think, but as you'll come to learn, around here, people like mod ideas more than feature requests smile

8 (edited by druvans 2005-06-18 19:43)

Re: PHP Tag

I was bored at work today - here is the proof
I tried to add GeSHi, it works for single lines(I dunno where to change it to make it work for multiple lines) with minimal changes to parser.php

Demo http://jobs.gotoguide.org/viewtopic.php?pid=1044

I copied the geshi files to include folder, then added following lines in parser.php.

added an include include_once('geshi.php');


added a function at end

function hilight($text,$lang){
    $geshi = new GeSHi($text,$lang);
    return $geshi->parse_code();
}

inside

added a function call to invoke hilight  inside the function do_bbcode($text)

just after this line :$text = preg_replace($pattern, $replace, $text);
added this line: $text=preg_replace('#\[h=(.*?)\]((.|\s)*)\[/h\]#e','hilight(\'$2\', \'$1\')',$text);

that is it.

only 1 highlight per post,  and "<"," >" is also not working

Re: PHP Tag

There's a mod to highlight PHP, ... code at PunRes.

10 (edited by druvans 2005-06-18 20:06)

Re: PHP Tag

GeSHi supports a tons of langs, and you can add langs own your own.

I changed my mind, I debugged the multiline issue,  darn regex's !

Re: PHP Tag

I fixed multiple highligting also - I modifed the function as follows- As I not a PHP programmer, if anyone see any potential issues, let me know.

I need to fix, '<' and '>' and remove additional <br/> in GeSHi output

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){
    $geshi = new GeSHi($text,$lang);
    $geshi->set_header_type(GESHI_HEADER_DIV);
    return $geshi->parse_code();
}

Re: PHP Tag

I'm trying use these functions. It seems ok. But I have problem with < and >: there are not displayed in the code.
Any fix ?

Thanks,

[no signature]

13 (edited by druvans 2005-07-27 02:26)

Re: PHP Tag

I dint try to fix it as I wasnt sure anyone is going to use.  I ll try to see what I can do, or you cld use zaher's mod for this :  http://www.punres.org/viewtopic.php?id=188

14 (edited by druvans 2005-08-02 19:13)

Re: PHP Tag

vnpenguin wrote:

I'm trying use these functions. It seems ok. But I have problem with < and >: there are not displayed in the code.
Any fix ?

Thanks,

Here you go. May not be a great fix, but it works.  The > & < where getting processed two times, so the end results becomes  &lt; and &gt;  I added str_replace for those, you cld add more values into that array

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]');
  }
  $r_this = array("&lt;", "&gt;","&quot;","&amp");
  $r_with = array("<",">",'"',"&amp");
  $result        = str_replace($r_this,$r_with, $result);
  return $result;
}

here's the code changed

$r_this = array("&lt;", "&gt;","&quot;","&amp");
  $r_with = array("<",">",'"',"&amp");
  $result        = str_replace($r_this,$r_with, $result);