Help:Code Syntax Highlighting
For more information see: Extension:SyntaxHighlight_GeSHi (Extension Help). Note that this is a "new plugin" and its native syntax differs from that used on the wiki - which we have maintained for backwards compatability.
Contents |
Inline code
Use {{Icode|your inline code fragment}} to markup up code fragments within the body of text. For example: "Class CActive is the base class of all Active Objects". This maps to the HTML <tt> tag.
Note: Replace the equals (=) and pipe (|) characters with the = and | codes respectively or this will not work.
Code blocks
The wiki allows you to specify code blocks syntax formatted for a large number of programming languages. You can also specify the initial line number of the block (if any) and a line that should be highlighted.
For example
- <code chsarp> your code</code> - markup code as C#
- <code xml 5> your code</code> - markup code as XML and start line numbering from line 5
- <code cpp 6 highlight="3"> your code</code> - markup code as C++, start line numbering from line 6, and highlight the 3rd line:
-
int main(int argc,char *argv){
int d;
d = argc + 1;
}
-
Syntax
<code [language] [n] [highlight="linenumber"] >source code here</code>
Parameters
- language: Code for any of the supported languages, including C# (csharp), C++ (cpp), XML (xml), Java (java) - see full list here.
- n: Line number to start with. A non numeric value (ie "n") will start the list at 001. NOTE that the numbering cycles back to 001 for line numbers greater than 1000.
- highlight="linenumber" : Marks the specified linenumber in highlight (line of the code sample, irrespective of "n" value)
The "default syntax" without parameters is the same as the pre tag: <code>
public class MyClass extends SomeOtherClass
{
public MyClass()
{
System.exit(); // surprise, you're dead!
}
}
Examples
Specify language (java)
<code java>
public class MyClass extends SomeOtherClass
{
public MyClass()
{
System.exit(); // surprise, you're dead!
}
}
Line numbers
<code cpp 5>
int main(int argc,char *argv){
int d;
d = argc + 1;
}
Highlighting (with line numbers)
<code cpp 6 highlight="linenumber">
int main(int argc,char *argv){
int d;
d = argc + 1;
}

