Personal tools
Make a donation
$ 




Geshi.php

From OrganicDesign Wiki

Jump to: navigation, search
Legacy.svg Legacy: This article describes a concept that has been superseded in the course of ongoing development on the Organic Design wiki. Please do not develop this any further or base work on this concept, this is only useful for a historic record of work done. You may find a link to the currently used concept or function in this article, if not you can contact the author to find out what has taken the place of this legacy item.
<?
# If not a 'raw' request, do syntax highlighting using geshi extension
# - see http://qbnz.com/highlighter
global $xwTransformID, $geshi_declare;
 
# Declare once, and replace onto end of data-stack
if ( !isset( $geshi_declare ) ) {
	# Converts tabs to spaces better than geshi
	$geshi_declare = true;
	function xwReplaceTabs($m) { return $m[1].str_repeat(' ',strlen($m[2])*4-strlen($m[1])%4); }
	}
 
if ( !isset( $GLOBALS["$tTitle-$xwTransformID"] ) ) {
	# Move *this* geshi to end of *this* data-stack
	xwSetProperty( $properties, 'xpath:/properties:data', $tTitle );
	$GLOBALS["$tTitle-$xwTransformID"] = 1;
	}
else {
 
if ( !$xwRaw ) {
 
	# Get lang and reduce article down to a string if DOM
	if ( is_object( $article ) ) {
		xwUndomificateArticle( $article, $title );
		$lang = 'xml';
		}
	elseif ( !xwGetProperty( $properties, 'language', $lang ) )
		$lang = xwArticleType( $title, $article );
 
	if ( $lang != 'raw' and $lang != '' ) {
 
		# patch for geshi array-count-as-comment bug
		if ( $lang == 'perl' ) $article = str_replace( '$#', ':-:arrlen:-:', $article );
 
		# Set up a geshi-parser
		$langparam = $lang == 'xslt' ? 'xml' : $lang;
		if ( $langparam == 'html' ) $langparam = 'html4strict';
		# Replace tabs with spaces (better than geshi)
		if ( $langparam != 'xml' ) $article = preg_replace_callback( "/^(.*?)(\\t+)/Sm", 'xwReplaceTabs', $article );
		$geshi = new GeSHi( $article, $langparam, 'extensions/geshi/geshi' );
		$geshi->set_header_type( GESHI_HEADER_DIV );
 
		# defaults
		@$geshi->set_brackets_style('font-weight:bold; color:#ff0000;',false);
 
		# dna
		if ( $lang != 'dna' ) {
			@$geshi->set_keyword_group_style(1, 'font-weight:bold;color:#0022aa;', false);
			@$geshi->set_keyword_group_style(2, 'color:#3311cc;', false);
			@$geshi->set_keyword_group_style(3, 'color:#3311cc;', false);
			@$geshi->set_url_for_keyword_group(1, '');
			@$geshi->set_url_for_keyword_group(2, '');
			@$geshi->set_url_for_keyword_group(3, '');
			$comment = 'font-style:italic;color:#d00000;';
			@$geshi->set_comments_style(1,$comment,false);
			@$geshi->set_comments_style(2,eregi('^(actionscript)|(c)$',$lang)?'font-style:italic;color:#ff44aa':$comment,false);
			@$geshi->set_comments_style(3,$comment,false);
			@$geshi->set_comments_style('MULTI',$comment,false);
			@$geshi->set_escape_characters_style('color:#ff0000;',false);
			@$geshi->set_brackets_style('font-weight:bold; color:#ff0000;',false);
			@$geshi->set_strings_style('color:#0080aa;',false);
			@$geshi->set_numbers_style('color:#000000;',false);
			@$geshi->set_methods_style('color:#000000;',false);
			@$geshi->set_symbols_style('color:#008000;',false);
			@$geshi->set_regexps_style('color:#00ffaa;',false);
			}
 
		# Do the parse
		$article = preg_replace("/^<div.*?>/", '<div class="xwcode">', $geshi->parse_code());
 
		# patch for geshi array-count as comment bug
		if ($lang == 'perl') $article = str_replace(':-:arrlen:-:', '$#', $article);
 
		# replace four-bracket links with urls
		$article = preg_replace('/\\[{4}(http:.+?)\\|(.+?)\\]{4}/', '<a href="$1">$2</a>', $article);
		$article = preg_replace('/\\[{4}(http:.+?)\\]{4}/', '<a href="$1">$1</a>', $article);
		$article = preg_replace('/\\[{4}([^\\[]+?)\\|([^\\[]+?)\\]{4}/', '<a href="/$1">$2</a>', $article);
		$article = preg_replace('/\\[{4}([^\\[]+?)\\]{4}/', '<a href="/$1">$1</a>', $article);
 
		$article = "$article";
		}
	}
}
 
?>

The GNU Project Debian Linux Ubuntu Linux Wikipedia Affiliate Button MediaWiki

Content under the www.organicdesign.co.nz domain is available under the Creative Commons Attribution-ShareAlike License