GeSHi - Generic Syntax Highlighter for Drupal
Since howforge.com has lots of contents related to programming techniques and source codes, I have been looking for a good syntax highlighter that supports all codes published in this site such as Python, HTML, XML, bash, C, Java, C#, CSS, JavaScript, SQL, Ruby, and PHP. Today, while editing XML code in DokuWiki, I found it has very powerful syntax highlighter provided by GeSHi. GeSHi is a generic syntax highlighter written in pure PHP. The advantage of GeSHi is its purity, in my opinion. You don’t have to deploy any additional software stacks like perl. Anyway, GeSHi is such a library for developer to call at run-time. To use it as a filter in Drupal, there must be a filter module that wraps GeSHi. Fortunately, vfilby has done geshifilter module for Drupal already. Actually, geshifilter covers all functions existing in codefilter module so you don’t need codefilter anymore.
If you are looking for syntax highlighter for Drupal, GeSHi is the best solution for you. In some case, you may set border of all pre tags, geshifilter has its own border. So you might need to remove this additional CSS by using below style.
.content div.codeblock {
padding: 0px;
border: 0px;
background-color: inherit;
}
In addition, geshifilter has a bit problem on site with Alias path. I fixed this problem and made a patch as follow.
--- geshifilter.module.orig 2006-03-25 19:08:40.000000000 +0700
+++ geshifilter.module 2006-03-25 19:11:51.000000000 +0700
@@ -31,8 +31,7 @@
drupal_set_html_head(’@import url(’. $GLOBALS[base_url] .’/modules/geshifilter/geshifilter.css);’);
if( variable_get( ’geshi_enabled’, FALSE ) == TRUE ) {
/* Parse out the current subdirectory if one exists */
- $subdir = preg_replace( "@((.*)://)[^/]*@", "", $GLOBALS[base_url] );
- include_once( $_SERVER[DOCUMENT_ROOT].$subdir.’/modules/geshifilter/geshi/geshi.php’ );
+ include_once( drupal_get_path(’module’, ’geshifilter’).’/geshi/geshi.php’ );
}
} else {
$items[] = array( ’path’ => ’admin/settings/geshifilter’,
@@ -59,7 +58,7 @@
variable_set( ’geshi_enabled’, $data[’geshi_enabled’] );
}
- if( $data[’geshi_dir’] != variable_get( ’geshi_dir’, $_SERVER[DOCUMENT_ROOT].’/modules/geshifilter/geshi’ ) ) {
+ if( $data[’geshi_dir’] != variable_get( ’geshi_dir’, ’modules/geshifilter/geshi’ ) ) {
drupal_set_message( "Changed GeSHi directory" );
variable_set( ’geshi_dir’, $data[’geshi_dir’] );
}
@@ -92,14 +91,14 @@
$form[’geshi’][’geshi_dir’] = array(
’#type’ => ’textfield’,
’#title’ => t(’GeSHi Directory’),
- ’#default_value’ => variable_get( ’geshi_dir’, $_SERVER[DOCUMENT_ROOT].’/modules/geshifilter/geshi’ ),
+ ’#default_value’ => variable_get( ’geshi_dir’, ’modules/geshifilter/geshi’ ),
’#size’ => 70,
’#maxlength’ => 100,
’#description’ => t(’Location of directory where GeSHi resides’),
);
- $lang_dir = variable_get( ’geshi_dir’, $_SERVER[DOCUMENT_ROOT].’/modules/geshifilter/geshi’ ).’/geshi’;
+ $lang_dir = variable_get( ’geshi_dir’, ’modules/geshifilter/geshi’ ).’/geshi’;
if( is_dir( $lang_dir ) ) {
if( $dir = opendir( $lang_dir ) ) {
while( ($file = readdir( $dir ) ) !== false ) {
@@ -195,7 +194,7 @@
$text = preg_replace( "@
@", "", $text );
$text = preg_replace( "@
|
@", "", $text );
- $geshi = new GeSHi( $text, $lang, variable_get( ’geshi_dir’, $_SERVER[DOCUMENT_ROOT].’/modules/geshifilter/geshi’ ).’/geshi’ );
+ $geshi = new GeSHi( $text, $lang, variable_get( ’geshi_dir’, ’modules/geshifilter/geshi’ ).’/geshi’ );
$text = "
" . $geshi->parse_code() . "";
if ($multiline)
Technorati Tags: English, IT, Programming, Review, Software, Drupal, Tips and Tricks, GeSHi, Filter
- sugree's blog
- 1334 reads
Post new comment