/**
	 * Initialise a GeSHi object to format some code, performing
	 * common setup for all our uses of it
	 *
	 * @note Used only until MW 1.20
	 *
	 * @param string $text
	 * @param string $lang
	 * @return GeSHi
	 */
	public static function prepare( $text, $lang ) {

		global $wgSyntaxHighlightKeywordLinks;

		self::initialise();
		$geshi = new GeSHi( $text, $lang );
		if( $geshi->error() == GESHI_ERROR_NO_SUCH_LANG ) {
			return null;
		}
		$geshi->set_encoding( 'UTF-8' );
		$geshi->enable_classes();
		$geshi->set_overall_class( "source-$lang" );
		$geshi->enable_keyword_links( $wgSyntaxHighlightKeywordLinks );

		// If the source code is over 100 kB, disable higlighting of symbols.
		// If over 200 kB, disable highlighting of strings too.
		$bytes = strlen( $text );
		if ( $bytes > 102400 ) {
			$geshi->set_symbols_highlighting( false );
			if ( $bytes > 204800 ) {
				$geshi->set_strings_highlighting( false );
			}
		}

		return $geshi;
	}
Пример #2
0
	$geshi->set_methods_style(1, "color: black;", false);
	
	//for multi-line comments /**/
	$geshi->set_comments_style('MULTI','color: rgb(63,127,95); font-style: code;', false);

	//for 'import' keyword
//	$geshi->set_comments_style(2,'color: rgb(127,0,85); font-weight: bold;', false);

	//for string constants
	$geshi->set_strings_style('color: rgb(42,0,255);', true);

	//for links (standard classes, etc.)
	$geshi->set_link_styles(GESHI_LINK, 'color: #000060;');
	$geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');

	//for keywords
	$geshi->set_keyword_group_style(1,'color: rgb(127,0,85); font-weight: bold;', false);
	$geshi->set_keyword_group_style(2,'color: rgb(127,0,85); font-weight: bold;', false); 
	$geshi->set_keyword_group_style(4,'color: rgb(127,0,85); font-weight: bold;', false); 
	
	//new keyword group for 'package'
//	$geshi->add_keyword_group(5, 'color: rgb(127,0,85); font-weight: bold;', true, array('package', 'import'));

	$geshi->set_header_content('SVNKit API examlpe: '.$fileName);
	$geshi->set_header_content_style('font-family: Verdana, Arial, sans-serif; color: #808080; font-size: 70%; font-weight: bold; background-color: #f0f0ff; border-bottom: 1px solid #d0d0d0; padding: 2px;');
	$geshi->set_symbols_highlighting(false);
	$geshi->set_footer_content_style('font-family: Verdana, Arial, sans-serif; color: #808080; font-size: 70%; font-weight: bold; background-color: #f0f0ff; border-top: 1px solid #d0d0d0; padding: 2px;');
	$geshi->set_url_for_keyword_group(3,"http://java.sun.com/j2se/1.4.2/docs/api/");
	$code = $geshi->parse_code();
	echo "<html><body><h1 >".$fileName."</h1>".$code."<div style=\"max-width: 800px; width: 800px;\"><center><small style=\"color: #669999; font-size: 100%; margin: 0px; padding: 0px; margin-top: 0.5em; font-weight: normal;\"><span style=\"font-size: 80%;\">(c) 2004-2007 TMate Software. All rights reserved.</span></small></center></div></body></html>";
?>
 /**
  * Initialise a GeSHi object to format some code, performing
  * common setup for all our uses of it
  *
  * @param string $text
  * @param string $lang
  * @return GeSHi
  */
 public static function prepare($text, $lang)
 {
     global $wgSyntaxHighlightKeywordLinks;
     self::initialise();
     $geshi = new GeSHi($text, $lang);
     if ($geshi->error() == GESHI_ERROR_NO_SUCH_LANG) {
         return null;
     }
     $geshi->set_encoding('UTF-8');
     $geshi->enable_classes();
     $geshi->set_overall_class("source-{$lang}");
     $geshi->enable_keyword_links($wgSyntaxHighlightKeywordLinks);
     // If the source code is over 100 kB, disable higlighting of symbols.
     // If over 200 kB, disable highlighting of strings too.
     $bytes = strlen($text);
     if ($bytes > 102400) {
         $geshi->set_symbols_highlighting(false);
         if ($bytes > 204800) {
             $geshi->set_strings_highlighting(false);
         }
     }
     /**
      * GeSHi comes by default with a font-family set to monospace, which
      * causes the font-size to be smaller than one would expect.
      * We append a CSS hack to the default GeSHi styles: specifying 'monospace'
      * twice "resets" the browser font-size specified for monospace.
      *
      * The hack is documented in MediaWiki core under
      * docs/uidesign/monospace.html and in bug 33496.
      */
     // Preserve default since we don't want to override the other style
     // properties set by geshi (padding, font-size, vertical-align etc.)
     $geshi->set_code_style('font-family: monospace, monospace;', true);
     // No need to preserve default (which is just "font-family: monospace;")
     // outputting both is unnecessary
     $geshi->set_overall_style('font-family: monospace, monospace;', false);
     return $geshi;
 }