[Solved]Geshi Syntax Highlighter

Want something adding or changing?, maybe a blade pack.

[Solved]Geshi Syntax Highlighter

Postby Adminer » Sun Oct 17, 2010 6:01 pm

Hi!

It's nice tool for programmers. I have found a small plugin for ckeditor.
http://tinyurl.com/2ac3fo7
It works perfectly good with ckeditor! I have a new button, paste php code and ... save.

Image

Testing 1,2,3! Wow! Should works!

system_GeSHi.php

Code: Select all
<?php
/******************************************************************************
* The Following license and copyright information must not be removed        *
*                                                                            *
******************************************************************************
*    Build Date: 04.09.2011                                                  *
******************************************************************************
* @port author : Remigiusz Waszkiewicz                                       *
* @copyright   : Copyright License GPLv3                                     *
* @version     : 1.5 stable                                                  *
* @platform    : PHP > 5.x.x                                                 *
* @plugin      : System GeSHi Syntax Higlighter                              *
******************************************************************************
* based on http://www.pklab.net/pagefiles/geshi/ExtractCodeForGeshi.php.html *
* Created by PkLab.net and for a Geshi plugin, for CKEditor (3.x)            *
* from http://www.pklab.net/index.php?id=350&lang=EN                         *
******************************************************************************
*/
   
///////////////////////
// Socket Allocation //
///////////////////////

// Add Blades to Sockets $bladeList['blade'] = 'socket'; //
$bladeList['addButtonGeSHi'] = 'admin-add-page-function';
$bladeList['scanPageGeSHi'] = 'scan-content-slug';

///////////////////////
//      Blades       //
///////////////////////



// blade - ouput function button and place function in page //
function addButtonGeSHi(&$extraInfo,&$content) {
    if($_SESSION['adminLogIn']) {
            if( isset( $_POST['geshi'] ) ) {
                $content = stripslashes($_POST['content']);
                $content.= "in-page-blade(geshi-syntax-highlighter)";
            }
            $extraInfo.= '<span class="rcms-button-wrapper">
<span class="l"> </span>
<span class="r"> </span><input class="rcms-button" id="button" type="submit" value="GeSHi" name="geshi"></span>&nbsp;';
        }
}
// end /////////////////////////////



//Output the data in page area
function scanPageGeSHi(&$slugOut) {   
   if (preg_match("/in-page-blade\(geshi-syntax-highlighter/", $slugOut)) {   
  $Content = $slugOut;
  // <pre class="geshi:php;line_num:false;"> source code </pre>
  // ^START                                                   ^STOP
  $codekey = 'geshi';
  $codetag = '<pre class="';
  $fullcodetag = $codetag.$codekey;
  $START = strpos($Content,$fullcodetag) ;
  $langs = array();
  while($START!==false)
  {   
    $pathtoGeSHi = getSystemRoot(RAZOR_HOME_FILENAME).RAZOR_BLADEPACK_DIR.'system_GeSHi/geshi.php';
    include_once "$pathtoGeSHi";
    //take tag option string
   
    $start = $START + strlen($codetag);
    $stop = strpos($Content,'"',$start);
    $tagopt = substr($Content,$start,$stop-$start);
   
    //parse option string into array
    $options  = String2KeyedArray($tagopt,';',':');   
    $lang = $options['geshi'];   
   if(isset($options['line_num']) && $options['line_num']) {   
    $line_num = ($options['line_num'] != 'false');
   }
   else {
   $line_num = true;
   }
   
    //look for source code
    $start = 1 + strpos($Content,'>',$start) ;
    $stop  = strpos($Content,'</pre>',$start) ;   
   
    //if close tag is not found goto untile EndOfFIle
    if($stop!==false)
    {
      $STOP = $stop+strlen('</pre>');
    } 
    else
    {
      $stop = strlen ($Content);
      $STOP = $stop;
    }
   
    //get the source code
    $source = substr ($Content,$start,$stop-$start) ;
    $source = html_entity_decode($source,ENT_QUOTES);
   
   
    if (end($langs) == $lang)
    {
      if ($line_num == true)
        $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
      else
        $geshi->enable_line_numbers(GESHI_NO_LINE_NUMBERS);

      //if lang is same of a last code block then recycle geshi obj and css
      $geshi->set_source($source);
    }
    else 
    {
      //new source language has been found in the content
     
      //create a new geshi obj
      $geshi = new GeSHi($source, $lang);
     
      // And echo the result!//
      $geshi->set_header_type(GESHI_HEADER_PRE);
      $geshi->enable_classes();
      $geshi->set_overall_style('font-size:9pt;', true);
     $geshi->set_line_style("font-size:9pt;background: #f0f0f0;", "font-size:9pt;background: #fcfcfc;");
    
     //// $geshi->set_overall_style('padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:wrap');
      //// $geshi->set_line_style('font-size:8pt;','font-size:8pt;');     
     //// $geshi->set_line_style('background: #fcfcfc;', 'background: #f0f0f0;', true);
     //// $geshi->set_highlight_lines_extra_style('background-color:#ffff66');
       
     
      // MISTAKE: for right formatting, this must be out before outing css
      if($line_num == true)
        $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS,2);
      //$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 1);
      else
        $geshi->enable_line_numbers(GESHI_NO_LINE_NUMBERS);

      // Echo out the stylesheet for this code block
      // chek if css lang has already loaded
      if(!in_array($lang,$langs))
      {
        echo '<style type="text/css"><!--'.
          $geshi->get_stylesheet().
          '--></style>';
      }
      // stores languase already found in current page
      array_push($langs,$lang);
    }
         
    $newcode = $geshi->parse_code();
    $Content =
      substr($Content,0,$START).
      $newcode.
      substr($Content,$STOP);   
    //search for next loop 
    $START = strpos($Content,$fullcodetag) ;
  }
  // END OF GESHI

      $slugOut = $Content;   
      $slugOut = str_replace('<p>
   in-page-blade(geshi-syntax-highlighter)</p>', ' ' , $slugOut);
      $slugOut = str_replace('in-page-blade(geshi_syntax_highlighter)', ' ' , $slugOut);
      
   }   
}
//// end ///////////////////

function string2KeyedArray($string, $delimiter = ',', $kv = '=>') {
  if ($a = explode($delimiter, $string)) { // create parts
    foreach ($a as $s) { // each part
      if ($s) {
        if ($pos = strpos($s, $kv)) { // key/value delimiter
          $ka[trim(substr($s, 0, $pos))] = trim(substr($s, $pos + strlen($kv)));
        } else { // key delimiter not found
          $ka[] = trim($s);
        }
      }
    }
    return $ka;
  }
} // end ///////////////////
?>


system_GeSHi.xml
Code: Select all
<?xml version="1.0" ?>
<bladepack>
    <details>
        <name>GeSHi Syntax Higlighter</name>
        <version>v1.0</version>
        <class>system</class>
        <author>Remigiusz Waszkiewicz</author>
        <description>GeSHi Syntax Higlighter</description>
    </details>
    <archive>
        <archive_file>system_GeSHi.zip</archive_file>
        <xml_file>system_GeSHi.xml</xml_file>
        <bladepack_file>system_GeSHi.php</bladepack_file>
        <bladepack_dir>system_GeSHi</bladepack_dir>
    </archive>
    <note>
        <p>Add GeSHi Syntax Higlighter into your page with a code</p>
    </note>
</bladepack>


Put inside 'system_GeSHi' folder ---> Geshi from zip file: http://sourceforge.net/projects/geshi/files/
Only last stable version - tested on GeSHi-1.0.8.10.zip

A lot of the others scripts with GeSHi Syntax Higlighter plugin:
http://www.jnieto.org/article/highlight ... _and_geshi
http://www.jnieto.org/article/full_high ... nd_tinymce
http://www.redchar.net/?x=entry:entry091004-155551
https://code.google.com/p/geshiforci/
http://lloc.de/scgeshi
http://wakka.xiffy.nl/geshi2
http://modxcms.com/extras/package/167?versionFilter=all
http://www.infernodevelopment.com/bbcod ... ghlighting
http://numberbox.net/blogs/files/geshiplugin.zip
http://moodle.org/mod/forum/discuss.php?d=43266
...and the others.

Regards
Adminer
 
Posts: 555
Joined: Wed Apr 08, 2009 9:52 pm
Location: Poland

Re: Geshi Syntax Highlighter

Postby Adminer » Sat Feb 19, 2011 10:08 pm

Another software for Syntax Highlighter:
http://alexgorbatchev.com/SyntaxHighlig ... tsnew.html
Adminer
 
Posts: 555
Joined: Wed Apr 08, 2009 9:52 pm
Location: Poland

Re: Geshi Syntax Highlighter

Postby Adminer » Fri Mar 04, 2011 11:44 pm

Adminer
 
Posts: 555
Joined: Wed Apr 08, 2009 9:52 pm
Location: Poland

Re: Geshi Syntax Highlighter

Postby Adminer » Sun Mar 06, 2011 2:51 pm

Another nice looking syntax highlighter: Snippet on jQuery.
http://www.steamdev.com/snippet/#
It's easy to adapt it for RazorCMS.
Adminer
 
Posts: 555
Joined: Wed Apr 08, 2009 9:52 pm
Location: Poland


Return to Suggestions

Who is online

Users browsing this forum: No registered users and 1 guest

cron