Removing 'Using ??? Syntax Highlighting' from GeSHi

  • Bogey
  • Bogey
  • Genius
  • Bogey
  • Posts: 8363
  • Loc: USA

Post 3+ Months Ago

If you look through this post of mine on my site, you would see 'Using php Syntax Highlighting' on two of the syntax highlighting there... I've looked through geshi.php and the hooks that came with the package and I couldn't find anywhere where I could turn that off.

While I'm on GeSHi here, how do I remove the 'Parsed in 0.090 seconds, using GeSHi 1.0.8.4' ?

Thanks for the replies in advance :)
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9072
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

I believe you are using the same base mod as ozzu is. The mod is driven by GeSHi, but there are still many other parts besides the GeSHi files. In your includes/hooks folder you should see a hook_syntax_highlighter.php file. You should be able to find everything in there that you need to edit. Hope that helps!
  • Bogey
  • Bogey
  • Genius
  • Bogey
  • Posts: 8363
  • Loc: USA

Post 3+ Months Ago

That did help. Thank you :D I actually found more things in there that helped me out... like having the functions as a link to the php.net site that explains that function :)

I looked there once and didn't see it... I guess I just had to be told so I would be sure that it is there. Thanks.

One other thing though, how do I create a default line style and things like that?

So if I type in [php]//some code[/php] it would come out as [syntax lang="php" lines="geshi-f"]//some code[/syntax] ?

I'd also like to change the word "Syntax:" to whatever language they are using.

Thanks.
  • Bogey
  • Bogey
  • Genius
  • Bogey
  • Posts: 8363
  • Loc: USA

Post 3+ Months Ago

Bogey wrote:
One other thing though, how do I create a default line style and things like that?

So if I type in [php]//some code[/php] it would come out as [syntax lang="php" lines="geshi-f"]//some code[/syntax] ?

I'd also like to change the word "Syntax:" to whatever language they are using.

Thanks.

Any help on this?
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9072
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

If you look through hook_syntax_highlighter.php and understand how it works most of everything should be in that file. Towards the top of the file it says:

PHP Code: [ Select ]
        /*
                Change the following flag to true to enable the use of the programming language
                as a BBCode tag. i.e. it will allow the use of [php ] .. [/php ] or [ delphi] .. [/delphi]
                NOTE: It will add a little load to the class creation as the GeSHi dir where the language
                          files are will be scanned and added to the BBCode array every time the class is
                          initialised, this means every page
        */
        var $auto_add_tags = true;
  1.         /*
  2.                 Change the following flag to true to enable the use of the programming language
  3.                 as a BBCode tag. i.e. it will allow the use of [php ] .. [/php ] or [ delphi] .. [/delphi]
  4.                 NOTE: It will add a little load to the class creation as the GeSHi dir where the language
  5.                           files are will be scanned and added to the BBCode array every time the class is
  6.                           initialised, this means every page
  7.         */
  8.         var $auto_add_tags = true;


So putting $auto_add_tags to true should allow you to use the php bbcode tags or whatever language code tags you want to use. Not sure if that was your questions or not.

If you were just referring to changing the line style its all in that same file. Just modify the code so that the default is different. Look in that file for a line that says something like:

PHP Code: [ Select ]
$geshi =& new GeSHi($text, $syntax);


Everything for setting the GeSHi formatting should be right after there. You may have to learn how the GeSHi system works some so that you can customize it the way you want. For instance you can change the line number styles with this:

PHP Code: [ Select ]
$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 2);


For more on GeSHi see this:

http://qbnz.com/highlighter/geshi-doc.html

Hope that helps!
  • Bogey
  • Bogey
  • Genius
  • Bogey
  • Posts: 8363
  • Loc: USA

Post 3+ Months Ago

If you'll look throughout the code blocks on my tutorial hosted on my site, you will see that it says 'Syntax:' rather than 'PHP:' like I want it to.

I already have $auto_add_tags set to true...

I also changed the params array to be: (Found on line 81)
PHP Code: [ Select ]
   var $params = array('lines' => 'geshi-f');

That doesn't change the default though...
  • Bogey
  • Bogey
  • Genius
  • Bogey
  • Posts: 8363
  • Loc: USA

Post 3+ Months Ago

Never mind, I changed the default to fancy lines... I now want to find out how to change the style to the thing and how to change 'Syntax:' to the name of the language that they are using.
  • Bogey
  • Bogey
  • Genius
  • Bogey
  • Posts: 8363
  • Loc: USA

Post 3+ Months Ago

Alright than... I got it all figured out. Thanks for the heads up on this.
  • Bogey
  • Bogey
  • Genius
  • Bogey
  • Posts: 8363
  • Loc: USA

Post 3+ Months Ago

w00t! I'm not able to highlight lines and have the line numbering start from a given number... whooot!

Thanks BigWebMaster for giving me a good kick-start on this.
  • Bogey
  • Bogey
  • Genius
  • Bogey
  • Posts: 8363
  • Loc: USA

Post 3+ Months Ago

I have a question about something on this.

To have highlighting on I had to add the following lines of PHP code to process_tag function.
PHP Code: [ Select ]
if( isset($item['params']['highlight']) )
{
    $h_lines = $item['params']['highlight'];
   
    if( strpos($h_lines, ',') !== false )
    {
        $hct_lines = explode(',', $h_lines);
       
        $hc_lines = array();
        foreach($hct_lines as $number)
        {
            if(is_numeric($number))
            {
                $hc_lines[] = $number;
            }
        }
    }
   
    if( strpos($h_lines, '-') )
    {
        $hp_lines = explode('-', $h_lines);
       
        $hl_lines = array();
       
        for($i = $hp_lines[0]; $i <= $hp_lines[1]; $i++)
        {
            $hl_lines[] = $i;
        }
    }
   
    if(isset($hl_lines) && isset($hc_lines))
    {
        $h_lines = array_merge( $hl_lines, $hc_lines );
    }
   
    $geshi->highlight_lines_extra($h_lines);
    $geshi->set_highlight_lines_extra_style('background-color: #ffff99;','background-color: #ffff00;');
}
  1. if( isset($item['params']['highlight']) )
  2. {
  3.     $h_lines = $item['params']['highlight'];
  4.    
  5.     if( strpos($h_lines, ',') !== false )
  6.     {
  7.         $hct_lines = explode(',', $h_lines);
  8.        
  9.         $hc_lines = array();
  10.         foreach($hct_lines as $number)
  11.         {
  12.             if(is_numeric($number))
  13.             {
  14.                 $hc_lines[] = $number;
  15.             }
  16.         }
  17.     }
  18.    
  19.     if( strpos($h_lines, '-') )
  20.     {
  21.         $hp_lines = explode('-', $h_lines);
  22.        
  23.         $hl_lines = array();
  24.        
  25.         for($i = $hp_lines[0]; $i <= $hp_lines[1]; $i++)
  26.         {
  27.             $hl_lines[] = $i;
  28.         }
  29.     }
  30.    
  31.     if(isset($hl_lines) && isset($hc_lines))
  32.     {
  33.         $h_lines = array_merge( $hl_lines, $hc_lines );
  34.     }
  35.    
  36.     $geshi->highlight_lines_extra($h_lines);
  37.     $geshi->set_highlight_lines_extra_style('background-color: #ffff99;','background-color: #ffff00;');
  38. }

Reason being, is that the default thing, doesn't highlights anything when I put in the param highlight="#,#,#-#"

It worked perfectly... until now for some reason. All of a sudden, it's giving me the following error.

Quote:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 6 bytes) in /home/bogey/webapps/htdocs/includes/hooks/hook_syntax_highlighter.php on line 472

Lines 472 is:
PHP Code: [ Select ]
for($i = $hp_lines[0]; $i <= $hp_lines[1]; $i++)

Any ideas on how I should go about fixing this?

Or at least fixing the default thing so it actually does highlight the lines?

Thanks in advance.
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9072
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Sorry for the delayed response, if that many bytes are being exhausted it sounds like you have an indefinite loop. I believe I also had to modify the highlighting code to get it to work correctly. You have probably already fixed this by now, but if this might help here is the code I had written to implement the highlighting:

PHP Code: [ Select ]
         // Check if Highlight parameter specified
         // format: highlight="1,2,3-10"
         $highlight_lines = array();
         if(isset($item['params']['highlight']))
         {
            // get highlight string
            $str = $item['params']['highlight'];
            $list = explode(',', $str);
            for($i=0, $end = count($list); $i < $end; $i++)
            {
               $str = trim($list[$i]);
               if(strpos($str, '-'))
               {
                  $row = explode('-', $str);
                  if(count($row) == 2)
                  {
                     $num1 = intval($row[0]);
                     if($num1 == 0)
                     {
                        $num1 = 1;
                     }
                     $num2 = intval($row[1]);
                     if($num1 > 0 && $num2 > $num1 && ($num2 - $num1) < 256)
                     {
                        $highlight_lines = array_merge($highlight_lines, range($num1, $num2));
                     }
                  }
               }
               else
               {
                  $num = intval($str);
                  if($num)
                  {
                     $highlight_lines = array_merge($highlight_lines, array($num));
                  }
               }
            }
         }
  1.          // Check if Highlight parameter specified
  2.          // format: highlight="1,2,3-10"
  3.          $highlight_lines = array();
  4.          if(isset($item['params']['highlight']))
  5.          {
  6.             // get highlight string
  7.             $str = $item['params']['highlight'];
  8.             $list = explode(',', $str);
  9.             for($i=0, $end = count($list); $i < $end; $i++)
  10.             {
  11.                $str = trim($list[$i]);
  12.                if(strpos($str, '-'))
  13.                {
  14.                   $row = explode('-', $str);
  15.                   if(count($row) == 2)
  16.                   {
  17.                      $num1 = intval($row[0]);
  18.                      if($num1 == 0)
  19.                      {
  20.                         $num1 = 1;
  21.                      }
  22.                      $num2 = intval($row[1]);
  23.                      if($num1 > 0 && $num2 > $num1 && ($num2 - $num1) < 256)
  24.                      {
  25.                         $highlight_lines = array_merge($highlight_lines, range($num1, $num2));
  26.                      }
  27.                   }
  28.                }
  29.                else
  30.                {
  31.                   $num = intval($str);
  32.                   if($num)
  33.                   {
  34.                      $highlight_lines = array_merge($highlight_lines, array($num));
  35.                   }
  36.                }
  37.             }
  38.          }
  • Bogey
  • Bogey
  • Genius
  • Bogey
  • Posts: 8363
  • Loc: USA

Post 3+ Months Ago

Awesome. It wasn't fixed. I think I dumped it because I couldn't figure it out. I will return to it and fix it up. Thanks :D

Post Information

  • Total Posts in this topic: 12 posts
  • Users browsing this forum: No registered users and 67 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.