Contents |
Introduction
Extension:SyntaxHighlighter displays formatted source code with the <source> tag using SyntaxHighlighter javascript library. For installation, please refer MediaWiki's Extension:SyntaxHighlighter page.
Supporting Languages
Some of the supported languages and corresponding lang parameters are shown below. For the full list, please refer SyntaxHighlighter site. the lang parameter in the source should be set to one of the aliases. Else, it will automatically render the plain text mode.
- C++ : cpp, c
- C# : csharp, c-sharp
- CSS : css
- PHP : php
- XML : xml, html, xhtml
- Python : python, py
- Java : java
- Javascript : jscript, js, javascript
Other Parameters
Besides the lang parameter, it supports all parameters used in SyntaxHighlighter library. In fact, our extension only passes the parameters from the source tag and pass it to SyntaxHighlight. If you want to see the supported parameters, please refer the SyntaxHighlight configuration page.
Samples
Plain Text
<source lang="php" first-line="3">
<?php
if( !defined( 'MEDIAWIKI' ) ) {
die(-1);
}
$wgExtensionCredits['other'][] = array(
'path' => __FILE__,
'name' => 'SyntaxHighlighter',
'description' => 'uses alexgorbatchev.com/SyntaxHighlighter',
'version' => '1.0',
'author' => 'Seong Jae Lee'
);
function wfSyntaxHighlighterParserInit(Parser &$parser) {
$parser->setHook('source', 'wfSyntaxHighlighterRender');
return true;
}
?>
</source>
Php
<?php
if( !defined( 'MEDIAWIKI' ) ) {
die(-1);
}
$wgExtensionCredits['other'][] = array(
'path' => __FILE__,
'name' => 'SyntaxHighlighter',
'description' => 'uses alexgorbatchev.com/SyntaxHighlighter',
'version' => '1.0',
'author' => 'Seong Jae Lee'
);
function wfSyntaxHighlighterParserInit(Parser &$parser) {
$parser->setHook('source', 'wfSyntaxHighlighterRender');
return true;
}
?>
Python
# Fibonacci numbers module
def fib(n): # write Fibonacci series up to n
a, b = 0, 1
while b < n:
print b,
a, b = b, a+b
def fib2(n): # return Fibonacci series up to n
result = []
a, b = 0, 1
while b < n:
result.append(b)
a, b = b, a+b
return result
Java
abstract class PizzaBuilder {
protected Pizza pizza;
public Pizza GetPizza() { return pizza; }
public void CreateNewPizza() { pizza = new Pizza(); }
public abstract void BuildDough();
public abstract void BuildSauce();
public abstract void BuildTopping();
}
class HawaiianPizzaBuilder extends PizzaBuilder;
class SpicyPizzaBuilder extends PizzaBuilder;
class Cook {
private PizzaBuilder builder;
public void SetPizzaBuilder(PizzaBuilder builder) { this.builder = builder; }
public Pizza ConstructPizza() {
builder.CreateNewPizzaProduct();
builder.BuildDough();
builder.BuildSauce();
builder.BuildTopping();
}
}
C++
template<class T>
class Singleton
{
public:
// Guaranteed to be destroyed.
// Instantiated on first use.
static T& GetInstance() { static T instance; return instance; }
private:
Singleton();
~Singleton();
Singleton(const Singleton &) {}; // Don't Implement
Singleton& operator=(const Singleton<T>&) {}; // Don't Implement
Singleton* operator&() {};
};
class A : public Singleton<A>
{
friend class Singleton<A>;
private:
A(); // Should be private
~virtual A();
A(const A&);
A& operator=(const A&);
A* operator&();
};