Help:Highlight code

This page was last modified on 28 March 2010, at 22:12. This page has been accessed 743 times.

From RBOSE

Jump to: navigation, search

The <syntaxhighlight> tags allow the display of preformatted code modules but in addition they add coloring according to the code language settings. Like the <pre> tags and the <poem> tags, they preserve white space, that is, they depict the code module exactly as it was typed.


Contents

Usage

On the wiki page, you can now use "syntaxhighlight" elements:

<syntaxhighlight lang="php">
<?php
    $v = "string";    // sample initialization
?>
html text
<?
    echo $v;         // end of php code
?>
</syntaxhighlight>

show:

<?php
    $v = "string";    // sample initialization
?>
html text
<?
    echo $v;         // end of php code
?>


Alternative Tag

<source> is also used in some other languages (for example XML). If your source code contains <source>, it will conflict with this tag since there is no way for the interpreter to identify how each is used.

As of rev:50696, an alternative tag <syntaxhighlight> is provided. <syntaxhighlight> is recommended to avoid the conflicts mentioned above.


Parameters

  • lang="??": Defines what programming language the source code is using. This affects how the extension highlights the source code. See the section "Supported languages" in this page for details of supported languages.
  • line="GESHI_NORMAL_LINE_NUMBERS|GESHI_FANCY_LINE_NUMBERS": Type of line numbering to use (default is no line numbering). Corresponds to enable_line_numbers the flag in GeSHi.
  • line start="??": Use together with the parameter "line". Define the start number of the line. If you type line start="55", it will start counting at 55, then 56,57,58... and so on. Corresponds to start_line_numbers_at method on GeSHi
  • highlight="??": Specifies which line is highlighted. Note that the parameter line start="??" doesn't affect how it counts the lines.
  • enclose="??": Specifies what container is used to enclose the source code. Takes values "pre" (default value), "div", "none". Corresponds to set_header_type method on GeSHi.
  • strict: Type the name of the parameter to enable the strict mode. Corresponds to enable_strict_mode method on GeSHi.

The effect and usage of these parameters can be consulted in GeSHi's documentation.

Since r22246, you can override the colors using MediaWiki:Geshi.css.


More Usage

When line numbering is added with line, long code lines will be wrapped. See the example below. When text is the selected language, and numbering is used, the behaviour resembles the use of pre tags with numbering and long-line wrapping.

The following example shows how to color an HTML code listing:

<syntaxhighlight lang="html4strict" line start="100" highlight="5">
HTML module goes here...
</syntaxhighlight>

A typical result is just:

  1. <table align=center style="background: ivory;color:maroon;font-style:italic;font-family:arial;font-weight:bold;font-size:10pt;"> 
  2. <tr><th> Heading 1 </th><th> Heading 2 </th></tr>
  3. <tr>
  4. <td style="padding:10px;"> This is cell 1 text </td>
  5. <td style="padding:10px;"> This is cell 2 text </td>
  6. </tr>
  7. </table>


Supported languages

These are the languages known by GeSHi that can be used in the lang parameter.

CodeLanguage
abapABAP
actionscriptActionScript
adaAda
apacheApache Configuration
applescriptAppleScript
asmASM
aspActive Server Pages (ASP)
autoitAutoIt
bashBash
basic4glBasic4GL
bfBrainfuck
blitzbasicBlitz BASIC
bnfBackus-Naur Form
cC
c_macC (Mac)
caddclAutoCAD DCL
cadlispAutoLISP
cfdgCFDG
cfmColdFusion Markup Language
cilCommon Intermediate Language (CIL)
cobolCOBOL
cpp-qtC++ (Qt toolkit)
cppC++
csharpC#
cssCascading Style Sheets (CSS)
dD
delphiDelphi
diffDiff
divDIV
dosDOS batch file
dotDOT
eiffelEiffel
fortranFortran
freebasicFreeBASIC
generoGenero
gettextGNU internationalization (i18n) library
glslOpenGL Shading Language (GLSL)
gmlGame Maker Language (GML)
gnuplotgnuplot
groovyGroovy
haskellHaskell
hq9plusHQ9+
html4strictHTML
idlUno IDL
iniINI
innoInno
intercalINTERCAL
ioIo
javaJava
java5Java(TM) 2 Platform Standard Edition 5.0
javascriptJavaScript
kixtartKiXtart
klonecKlone C
klonecppKlone C++
latexLaTeX
lispLisp
lolcodeLOLCODE
lotusscriptLotusScript
luaLua
CodeLanguage
m68kMotorola 68000 Assembler
makemake
matlabMATLAB M
mircmIRC scripting language
mxmlMXML
mpasmMicrochip Assembler
mysqlMySQL
nsisNullsoft Scriptable Install System (NSIS)
objcObjective-C
ocaml-briefOCaml
ocamlOCaml
oobasOpenOffice.org Basic
oracle8Oracle 8 SQL
oracle11Oracle 11 SQL
pascalPascal
perper
perlPerl
php-briefPHP
phpPHP
pixelbenderPixel Bender
plsqlPL/SQL
povrayPersistence of Vision Raytracer
powershellWindows PowerShell
progressOpenEdge Advanced Business Language
prologProlog
providexProvideX
pythonPython
qbasicQBasic/QuickBASIC
railsRails
regWindows Registry
robotsrobots.txt
rubyRuby
sasSAS
scalaScala
schemeScheme
scilabScilab
sdlbasicSdlBasic
smalltalkSmalltalk
smartySmarty
sqlSQL
tclTcl
teratermTera Term
textPlain text
thinbasicthinBasic
tsqlTransact-SQL
typoscriptTypoScript
vbVisual Basic
vbnetVisual Basic .NET
verilogVerilog
vhdlVHDL
vimVimscript
visualfoxproVisual FoxPro
visualprologVisual Prolog
whitespaceWhitespace
winbatchWinbatch
xmlXML
xorg_confXorg.conf
xppX++
z80ZiLOG Z80 Assembler


External links