Syntax Highlighting for Code Blocks


NOTE
This feature is available since:
WikkaWiki 1.1.6.0
This is the documentation page for the syntax highlighter.

Code highlighting sample
 

GeSHi is now hooked into Wikka.

Usage: %%(formatter[;line-number][;filename]) code %%

Line-numbers
If geshi_line_numbersin the ConfigurationOptions is enabeld, simply add a ;line-number after the language formatter to display line-numbers starting at line-number.

%%(php;15)
<?php
echo "Hello, World!";
?>
%%


  1. <?php
  2. echo "Hello, World!";
  3. ?>


Setting a file name for download
If you specify a filename, this will be used for downloading the code.

%%(php;15;test.php)
<?php
echo "Hello, World!";
?>
%%


test.php (line 15)
  1. <?php
  2. echo "Hello, World!";
  3. ?>


Linking to online documention
If you click on a function name, you get to the entry of this function in the online manual of the language (only for some languages). You can try it out with the php-example below.

Available formatters


GeSHi formatters
List of available code formatters
since 1.1.6.4
LanguageFormatterLanguageFormatterLanguageFormatter
ActionscriptactionscriptABAPabapADAada
Apache LogapacheAppleScriptapplescriptASMasm
ASPaspAutoITautoitBashbash
BlitzBasicblitzbasicBasic4GLbasic4glbnfbnf
CcC for Macsc_macC#csharp
C++cppC++ (+QT)cpp-qtCAD DCLcaddcl
CadLispcadlispCFDGcfdgColdFusioncfm
CSScssCSV csvDd
DelphidelphiDiff-OutputdiffDIVdiv
DOSdosDotdotEiffeleiffel
FortranfortranFreeBasicfreebasicFOURJ\'s Genero 4GLgenero
GMLgmlGroovygroovyHaskellhaskell
HTMLhtml4strictINIiniInno Scriptinno
IoioJava 5java5Javajava
JavascriptjavascriptLaTeXlatexLisplisp
LualuaMatlabmatlabmIRC Scriptingmirc
Microchip AssemblermpasmMicrosoft RegistryregMotorola 68k Assemblerm68k
MySQLmysqlNSISnsisObjective Cobjc
OpenOffice BASICoobasObjective CamlocamlObjective Caml (brief)ocaml-brief
Oracle 8oracle8PascalpascalPer (FOURJ\'s Genero 4GL)per
PerlperlPHPphpPHP (brief)php-brief
PL/SQLplsqlPythonphytonQ(uick)BASICqbasic
robots.txtrobotsRuby on RailsrailsRubyruby
SASsasSchemeschemesdlBasicsdlbasic
SmartysmartySQLsqlTCL/iTCLtcl
T-SQLtsqlTexttextthinBasicthinbasic
UnoidlidlVB.NETvbnetVHDLvhdl
Visual BASICvbVisual Fox ProvisualfoxproWinBatchwinbatch
XMLxmlX++xppZiLOG Z80 Assemblerz80
CSV is not handled by GeSHi, but by a Wikka handler: FormatterCSV
since 1.4.2



built-in:

Note that GeSHi syntax highlighting takes precedence over built-in syntax highlighting.

Examples


highlighted with GeSHi

%%(php;1) PHP code with line-numbers%%:
  1. <?php
  2. $text = "Hello, World!";
  3. print $text;
  4. ?>


%%(css) CSS code%%
body {
    font-family: "Trebuchet MS", Georgia, serif;
    font-size: .9em;
    line-height: 1.4em;
    font-weight: normal;
    color: #000000;
    background-image: url(../images/wikkalight.jpg);
    background-attachment: fixed;
    background-repeat: no-repeat;
    background-color: #000;
    margin: 0px;
}


%%(javascript;129) JavaScript code starting on line 129%%
  1. function fKeyDown()
  2. {
  3.     if (event.keyCode == 9)
  4.     {
  5.         event.returnValue = false;
  6.         document.selection.createRange().text = String.fromCharCode(9);
  7.     }
  8. }


%%(php;1) PHP code with line-numbers and filename%%:
test.php (line 1)
  1. <?php
  2. $text = "Hello, World!";
  3. print $text;
  4. ?>


Wikka built-in highlighter

The built-int highlighter does not supported line numbering and is maintained for backwards-compatibility.

%%(ini) INI file contents%%:
; Menu specification file for Opera 7.0

[Version]
File Version=2

[Info]  #background info
Name=Munin++ Menu
Description=Munin++ Menu
Author=NonTroppo (originally by Rijk van Geijtenbeek)
Version=1.9


%%(email) Email message%%:


%%code%%:
int main(int arc,char **argv)
{
	printf("Hello, %s!
", (argc>1) ? argv[1] : "World");
	return 0;
}




CategoryEN
Comments
Comment by anonymous
2009-02-17 07:36:16
How is it possible to use a double % inside of a codeblock?
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki