SyntaxHighlighter 3.0.83

Fork Me On GitHub
whats new?
SyntaxHighlighter is an open source Java Script client side code syntax highlighter.
donate download installation autoloader configuration @syntaxhighlight

PHP Example

      <?php
      if (!defined('MEDIAWIKI'))
      	exit(1);
      
      $wgExtensionFunctions[] = "wfSyntaxHighlighterExtension";
      
      $wgExtensionCredits['other'][] = array(
      	'name' => 'SyntaxHighlighter',
      	'author' => array('Alex Gorbatchev'),
      	'version' => '1.0',
      	'url' => 'http://alexgorbatchev.com/projects/syntaxhighlighter',
      	'description' => 'Provides tight integration with SyntaxHighlighter.'
      );
      
      // Path to the SyntaxHighlighter scripts
      $wgSyntaxHighlighterScriptPath = "{$wgScriptPath}/extensions/SyntaxHighlighter/scripts";
      
      // Path to the SyntaxHighlighter styles
      $wgSyntaxHighlighterStylesPath = "{$wgScriptPath}/extensions/SyntaxHighlighter/styles";
      
      // Theme CSS file
      $wgSyntaxHighlighterTheme = "shThemeDefault.css";
      
      // Brushes to include on the page
      $wgSyntaxHighlighterBrushes = array(
      	'shBrushBash.js',
      	'shBrushCpp.js',
      	'shBrushCSharp.js',
      	'shBrushCss.js',
      	'shBrushDelphi.js',
      	'shBrushDiff.js',
      	'shBrushGroovy.js',
      	'shBrushJava.js',
      	'shBrushJScript.js',
      	'shBrushPhp.js',
      	'shBrushPlain.js',
      	'shBrushPython.js',
      	'shBrushRuby.js',
      	'shBrushScala.js',
      	'shBrushSql.js',
      	'shBrushVb.js',
      	'shBrushXml.js'
      );
      
      $dir = dirname(__FILE__) . '/';
      
      function wfSyntaxHighlighterExtension()
      {
      	global $wgOut, $wgScriptPath, $wgParser, 
      		$wgSyntaxHighlighterBrushes, $wgSyntaxHighlighterScriptPath, 
      		$wgSyntaxHighlighterStylesPath, $wgSyntaxHighlighterTheme;
      	
      	// Make shCore.js the very first script to be included (before all the brushes)
      	array_unshift($wgSyntaxHighlighterBrushes, 'shCore.js');
      	
      	$home = $wgSyntaxHighlighterScriptPath;
      	
      	// Add all scripts to the header
      	foreach ($wgSyntaxHighlighterBrushes as $script)
      		$wgOut->addScript("<script type=\"text/javascript\" src=\"{$wgSyntaxHighlighterScriptPath}/$script\"></script>\n");
      
      	// Add CSS links
      	foreach (array('shCore.css', $wgSyntaxHighlighterTheme) as $css)
      		$wgOut->addHeadItem($css, "<link type=\"text/css\" rel=\"stylesheet\" href=\"{$wgSyntaxHighlighterStylesPath}/$css\"/>\n");
      
      	// Add initialization code
      	$wgOut->addScript(
      		"<script type=\"text/javascript\">".
      			"var syntaxHighlighterConfig = { clipboardSwf: '{$wgSyntaxHighlighterScriptPath}/clipboard.swf' };".
      			"SyntaxHighlighter.highlight();".
      		"</script>\n"
      		);
      	
      	// Finally, set up a MediaWiki hook to the <sh /> tag
      	$wgParser->setHook("sh", "wfSyntaxHighlighterExtensionRender"); 
      	
      	return true;
      }
      
      function wfSyntaxHighlighterExtensionRender($input, $argv, $parser)
      {
      	$args = "";
      	
      	while (list($key, $val) = each($argv))
      		$args .= "$key: $val;";
      	
      	$input = htmlspecialchars($input);
      	return "<pre class=\"$args\">\n$input\n</pre>";
      }
      
Brush nameBrush aliasesFile name
ActionScript3as3, actionscript3shBrushAS3.js
Bash/shellbash, shellshBrushBash.js
ColdFusioncf, coldfusionshBrushColdFusion.js
C#c-sharp, csharpshBrushCSharp.js
C++cpp, cshBrushCpp.js
CSScssshBrushCss.js
Delphidelphi, pas, pascalshBrushDelphi.js
Diffdiff, patchshBrushDiff.js
Erlangerl, erlangshBrushErlang.js
GroovygroovyshBrushGroovy.js
JavaScriptjs, jscript, javascriptshBrushJScript.js
JavajavashBrushJava.js
JavaFXjfx, javafxshBrushJavaFX.js
Perlperl, plshBrushPerl.js
PHPphpshBrushPhp.js
Plain Textplain, textshBrushPlain.js
PowerShellps, powershellshBrushPowerShell.js
Pythonpy, pythonshBrushPython.js
Rubyrails, ror, rubyshBrushRuby.js
ScalascalashBrushScala.js
SQLsqlshBrushSql.js
Visual Basicvb, vbnetshBrushVb.js
XMLxml, xhtml, xslt, html, xhtmlshBrushXml.js