コード例 #1
0
	/**
	 * 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
 /**
  * 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;
 }