mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/SyntaxHighlight_GeSHi
synced 2024-11-15 02:24:07 +00:00
* (bug 15634) Add The Enclosure/Header Type "none"
This commit is contained in:
parent
44a26c7eb5
commit
3fdce00db1
|
@ -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 <div> 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,13 +63,17 @@ 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}" );
|
||||
if ( $enclose === GESHI_HEADER_NONE ) {
|
||||
return '<span class="'.$lang.' source-'.$lang.'"> '.$out . '</span>';
|
||||
} else {
|
||||
return '<div dir="ltr" style="text-align: left;">' . $out . '</div>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Take an input specifying a list of lines to highlight, returning
|
||||
|
@ -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 <div> 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
|
||||
|
|
|
@ -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' ) )
|
||||
|
|
Loading…
Reference in a new issue