From 3fdce00db18f2a222ab3a73c33d91bbce94aa95b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20Laxstr=C3=B6m?= Date: Sun, 28 Sep 2008 15:30:45 +0000 Subject: [PATCH] * (bug 15634) Add The Enclosure/Header Type "none" --- SyntaxHighlight_GeSHi.class.php | 51 +++++++++++++++++++++++---------- SyntaxHighlight_GeSHi.php | 4 +-- 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/SyntaxHighlight_GeSHi.class.php b/SyntaxHighlight_GeSHi.class.php index 47ad0f80..181b96fb 100644 --- a/SyntaxHighlight_GeSHi.class.php +++ b/SyntaxHighlight_GeSHi.class.php @@ -36,19 +36,9 @@ class SyntaxHighlight_GeSHi { $geshi = self::prepare( $text, $lang ); if( !$geshi instanceof GeSHi ) return self::formatError( htmlspecialchars( wfMsgForContent( 'syntaxhighlight-err-language' ) ) ); - // "Enclose" parameter - if ( isset( $args['enclose'] ) && $args['enclose'] == 'div' ) { - $enclose = GESHI_HEADER_DIV; - } elseif ( defined('GESHI_HEADER_PRE_VALID') ) { - // Since version 1.0.8 geshi can produce valid pre, but we need to check for it - $enclose = GESHI_HEADER_PRE_VALID; - } elseif( isset( $args['line'] ) ) { - // Force
mode to maintain valid XHTML, see - // http://sourceforge.net/tracker/index.php?func=detail&aid=1201963&group_id=114997&atid=670231 - $enclose = GESHI_HEADER_DIV; - } else { - $enclose = GESHI_HEADER_PRE; - } + + $enclose = self::getEncloseType( $args ); + // Line numbers if( isset( $args['line'] ) ) { $geshi->enable_line_numbers( GESHI_FANCY_LINE_NUMBERS ); @@ -73,11 +63,15 @@ class SyntaxHighlight_GeSHi { return self::formatError( $err ); } else { // Armour for Parser::doBlockLevels() - if( $enclose == GESHI_HEADER_DIV ) + if( $enclose === GESHI_HEADER_DIV ) $out = str_replace( "\n", '', $out ); // Register CSS $parser->mOutput->addHeadItem( self::buildHeadItem( $geshi ), "source-{$lang}" ); - return '
' . $out . '
'; + if ( $enclose === GESHI_HEADER_NONE ) { + return ' '.$out . ''; + } else { + return '
' . $out . '
'; + } } } @@ -130,6 +124,33 @@ class SyntaxHighlight_GeSHi { $end - $start < $arbitrarilyLargeConstant; } + static function getEncloseType( $args ) { + // Since version 1.0.8 geshi can produce valid pre, but we need to check for it + if ( defined('GESHI_HEADER_PRE_VALID') ) { + $pre = GESHI_HEADER_PRE_VALID; + } else { + $pre = GESHI_HEADER_PRE; + } + + // "Enclose" parameter + $enclose = $pre; + if ( isset( $args['enclose'] ) ) { + if ( $args['enclose'] === 'div' ) { + $enclose = GESHI_HEADER_DIV; + } elseif ( $args['enclose'] === 'none' ) { + $enclose = GESHI_HEADER_NONE; + } + } + + if( isset( $args['line'] ) && $pre === GESHI_HEADER_PRE ) { + // Force
mode to maintain valid XHTML, see + // http://sourceforge.net/tracker/index.php?func=detail&aid=1201963&group_id=114997&atid=670231 + $enclose = GESHI_HEADER_DIV; + } + + return $enclose; + } + /** * Hook into Article::view() to provide syntax highlighting for * custom CSS and JavaScript pages diff --git a/SyntaxHighlight_GeSHi.php b/SyntaxHighlight_GeSHi.php index aaa39270..bd91d95f 100644 --- a/SyntaxHighlight_GeSHi.php +++ b/SyntaxHighlight_GeSHi.php @@ -34,8 +34,8 @@ * If you forget, or give an unsupported value, the extension spits out * some help text and a list of all supported languages. * - * The extension has been tested with GeSHi 1.0.7 and MediaWiki 1.5 CVS - * as of 2005-06-22. + * The extension has been tested with GeSHi 1.0.8 and MediaWiki 1.14a + * as of 2008-09-28. */ if( !defined( 'MEDIAWIKI' ) )