MediaWiki GeSHi

From miki
Revision as of 19:14, 13 February 2014 by Mip (talk | contribs) (Import from Mediawiki page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This extension adds the <source> tag to present formatted source code. See official page.

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.
  • 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.