MediaWiki GeSHi
Jump to navigation
Jump to search
SyntaxHighlight GeSHi is a MediaWiki extension that adds the <source> tag to present formatted source code.
This page is part of the pages dedicated to Mediawiki.
- Extension:SyntaxHighlight_GeSHi on mediawiki.
Restoring old <pre> formatting
Since at least version r24298 (July 21, 2007) (with GeSHi version 1.0.8), <source> tag does not match usual formatting applied for <pre> tags. This is because the extension applies by default the new GeSHi header style GESHI_HEADER_PRE_VALID. We describe below different solutions to restore the old formatting:
- Define a custom style in MediaWiki:Common.css — This is probably the easiest & safest method, and also it allows to customize the output. For instance the following style adds a left border + background by default, unless if the
<source>
tag is enclosed in a<div class="noborder">
/** GeSHi Syntax Highlight - custom styles */ /** ... by default, we add a left border + left padding + left margin + lightgray background (for clarity) */ div.mw-geshi { margin: 0.5em 0em 0.5em 2em; padding: 0em 0em 0em 1em; border-left: 1px dashed #2f6fab; background-color: #f9f9f9; } /** ... except if the <source> tag is enclosed in a <div class="noborder"> */ div.noborder div.mw-geshi { margin: 0px; padding: 0px; border-left: none; background-color: inherit; }
- Patch GeSHi — The following patch restores the old
pre
format. It also introduces a new option prevalid to attribute enclose to force application of header style GESHI_HEADER_PRE_VALID.SyntaxHighlight_GeSHi_r24298.patch (<file name="SyntaxHighlight_GeSHi_r24298.patch" tag="source">download</file>)--- SyntaxHighlight_GeSHi.class.php.old 2008-09-07 23:24:37.000000000 +0200 +++ SyntaxHighlight_GeSHi.class.php 2008-09-07 23:33:15.000000000 +0200 @@ -39,7 +39,7 @@ // "Enclose" parameter if ( isset( $args['enclose'] ) && $args['enclose'] == 'div' ) { $enclose = GESHI_HEADER_DIV; - } elseif ( defined('GESHI_HEADER_PRE_VALID') ) { + } elseif ( (isset( $args['line'] ) || isset( $args['enclose'] ) && $args['enclose'] == 'prevalid' ) && 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'] ) ) {
SyntaxHighlight_GeSHi_r60735.patch (<file name="SyntaxHighlight_GeSHi_r60735.patch" tag="source">download</file>)--- SyntaxHighlight_GeSHi.class.php.old 2008-09-07 23:24:37.000000000 +0200 +++ SyntaxHighlight_GeSHi.class.php 2008-09-07 23:33:15.000000000 +0200 @@ -39,7 +39,7 @@ // "Enclose" parameter if ( isset( $args['enclose'] ) && $args['enclose'] == 'div' ) { $enclose = GESHI_HEADER_DIV; - } elseif ( defined('GESHI_HEADER_PRE_VALID') ) { + } elseif ( (isset( $args['line'] ) || isset( $args['enclose'] ) && $args['enclose'] == 'prevalid' ) && 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'] ) ) {
- Add a custom .css to php - Another solution is discussed here. The proposed solution is to edit file "SyntaxHighlight_GeSHi.class.php". Go to line 192, which should look like
$css[] = ".source-$lang {line-height: normal;}";
Change this to
$css[] = ".source-$lang {padding: 1em; border: 1px dashed #2f6fab; color: black; background-color: #f9f9f9; line-height: 1.1em;}";
and you have restored the pre css formatting.