Changes

From SME Server
Jump to navigationJump to search
12,272 bytes added ,  11:05, 23 January 2013
Created page with "The '''Extension:SyntaxHighlight GeSHi''' tag displays formatted source code with the <code><syntaxhighlight></code> tag. This extension also adds c..."
The '''Extension:SyntaxHighlight GeSHi''' tag displays formatted [[w:source code|source code]] with the <code>&lt;syntaxhighlight&gt;</code> tag.

This extension also adds coloring according to the code language settings. Like the <code>&lt;pre&gt;</code> tags and the <code>&lt;poem&gt;</code> tags, the tags shows the coding exactly as it was typed, preserving white space.

This extension also can create line numbers.

==source tag replaced==
Before [[rev:50696]], the <code>&lt;source&gt;</code> tag was used. It is still supported, but <code>&lt;syntaxhighlight&gt;</code> is recommended to avoid possible conflicts. The original syntax is used in some other languages, e.g. XML.

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

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

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

=== Alternative Tag ===
<code>&lt;source&gt;</code> is also used in some other languages (for example XML). If your source code contains <nowiki><source></nowiki>, 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 <code>&lt;syntaxhighlight&gt;</code> is provided. <code>&lt;syntaxhighlight&gt;</code> is recommended to avoid the conflicts mentioned above.

=== Parameters ===
; <code>lang="??"</code>
: Defines what programming language the source code is using. This affects how the extension highlights the source code. See the section "[[#Supported_languages|Supported languages]]" in this page for details of supported languages.
; <code>line="GESHI_NORMAL_LINE_NUMBERS|GESHI_FANCY_LINE_NUMBERS"</code>
: Type of line numbering to use. If you do not provide this parameter, then lines will not be numbered. Corresponds to [http://qbnz.com/highlighter/geshi-doc.html#enabling-line-numbers enable_line_numbers] the flag in GeSHi.
; <code>line</code>
: Equivalent to <code>'''line="GESHI_FANCY_LINE_NUMBERS"</code>
; <code>line start="??"</code>
: 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 [http://qbnz.com/highlighter/geshi-doc.html#starting-line-numbers start_line_numbers_at] method on GeSHi
<!--
; <code>case</code>
: Corresponds to [http://qbnz.com/highlighter/geshi-doc.html#auto-caps-nocaps set_case_keywords] method on GeSHi
; <code>tab</code>
: Corresponds to [http://qbnz.com/highlighter/geshi-doc.html#setting-tab-width set_tab_width] method on GeSHi
-->
; <code>highlight="??"</code>
: Specifies which line is highlighted. Note that the parameter '''line start="??"''' doesn't affect how it counts the lines.
; <code>enclose="??"</code>
: Specifies what container is used to enclose the source code. Takes values "pre" (default value), "div", "none". Corresponds to [http://qbnz.com/highlighter/geshi-doc.html#the-code-container set_header_type] method on GeSHi. Choosing "div" will cause text to wrap, which is helpful if text is extending off the edge of the screen, causing horizontal scrolling.
; <code>strict</code>
: Type the name of the parameter to enable the strict mode. Corresponds to [http://qbnz.com/highlighter/geshi-doc.html#using-strict-mode enable_strict_mode] method on GeSHi.

The effect and usage of these parameters can be consulted in [http://qbnz.com/highlighter/geshi-doc.html 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:
<pre><syntaxhighlight lang="html4strict" line start="100" highlight="5" enclose="div">
HTML module goes here...
</syntaxhighlight>
</pre>
A typical result is just:
<syntaxhighlight lang="html4strict" line start="100" highlight="5" enclose="div">
<!--This is a comment. Comments are not displayed in the browser-->
<table align=center style="background: ivory;color:maroon;font-style:italic;font-family:arial;font-weight:bold;font-size:10pt;">
<tr><th> Heading 1 </th><th> Heading 2 </th></tr>
<tr>
<td style="padding:10px;"> This is cell 1 text </td>
<td style="padding:10px;"> This is cell 2 text </td>
</tr>
</table>
</syntaxhighlight>

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

<small>Note that installed GeSHi version (can be revealed by previewing e.g. <code>&lt;syntaxhighlight lang="-"&gt;&lt;/syntaxhighlight&gt;</code>) might not be the most recent version; see [[bugzilla:10967]] for Wikimedia sites.</small>

{| class="wikitable" style="float:left"
!Code||Language
|-
|<code>abap</code>||[[:en:ABAP|ABAP]]
|-
|<code>actionscript</code>||[[:en:ActionScript|ActionScript]]
|-
|<code>ada</code>||[[:en:Ada (programming language)|Ada]]
|-
|<code>apache</code>||[[:en:Apache HTTP Server|Apache Configuration]]
|-
|<code>applescript</code>||[[:en:AppleScript|AppleScript]]
|-
|<code>asm</code>||[[:en:Assembly language|Assembly]]
|-
|<code>asp</code>||[[:en:Active Server Pages|Active Server Pages (ASP)]]
|-
|<code>autoit</code>||[[:en:AutoIt|AutoIt]]
|-
|<code>bash</code>||[[:en:Bash (Unix shell)|Bash]]
|-
|<code>basic4gl</code>||[[:en:Basic4GL|Basic4GL]]
|-
|<code>bf</code>||[[:en:Brainfuck|Brainfuck]]
|-
|<code>blitzbasic</code>||[[:en:Blitz BASIC|Blitz BASIC]]
|-
|<code>bnf</code>||[[:en:Backus-Naur Form|Backus-Naur Form]]
|-
|<code>c</code>||[[:en:C (programming language)|C]]
|-
|<code>c_mac</code>||C (Mac)
|-
|<code>caddcl</code>||[[:en:Dialog Control Language|AutoCAD DCL]]
|-
|<code>cadlisp</code>||[[:en:AutoLISP|AutoLISP]]
|-
|<code>cfdg</code>||CFDG
|-
|<code>cfm</code>||[[:en:ColdFusion_Markup_Language|ColdFusion Markup Language]]
|-
|<code>cil</code>||[[:en:Common_Intermediate_Language|Common Intermediate Language (CIL)]]
|-
|<code>cobol</code>||[[:en:COBOL|COBOL]]
|-
|<code>cpp-qt</code>||[[:en:Qt (toolkit)|C++ (Qt toolkit)]]
|-
|<code>cpp</code>||[[:en:C++|C++]]
|-
|<code>csharp</code>||[[:en:C Sharp (programming language)|C#]]
|-
|<code>css</code>||[[:en:Cascading Style Sheets|Cascading Style Sheets (CSS)]]
|-
|<code>d</code>||[[:en:D (programming language)|D]]
|-
|<code>delphi</code>||[[:en:Delphi programming language|Delphi]]
|-
|<code>diff</code>||[[:en:diff|Diff]]
|-
|<code>div</code>||DIV
|-
|<code>dos</code>||[[:en:DOS batch file|DOS batch file]]
|-
|<code>dot</code>||[[:en:DOT language|DOT]]
|-
|<code>eiffel</code>||[[:en:Eiffel (programming language)|Eiffel]]
|-
|<code>fortran</code>||[[:en:Fortran|Fortran]]
|-
|<code>freebasic</code>||[[:en:FreeBASIC|FreeBASIC]]
|-
|<code>gambas</code>||[[:en:Gambas_programming_language|Gambas]]
|-
|<code>genero</code>||Genero
|-
|<code>gettext</code>||[[:en:GNU_gettext|GNU internationalization (i18n) library]]
|-
|<code>glsl</code>||[[:en:GLSL|OpenGL Shading Language (GLSL)]]
|-
|<code>gml</code>||[[:en:Game Maker Language|Game Maker Language (GML)]]
|-
|<code>gnuplot</code>||[[:en:Gnuplot|gnuplot]]
|-
|<code>groovy</code>||[[:en:Groovy (programming language)|Groovy]]
|-
|<code>haskell</code>||[[:en:Haskell (programming language)|Haskell]]
|-
|<code>hq9plus</code>||HQ9+
|-
|<code>html4strict</code>||[[:en:HTML|HTML]]
|-
|<code>html5</code>||[[:en:HTML5|HTML5]]
|-
|<code>idl</code>||[[:en:Universal Network Objects|Uno IDL]]
|-
|<code>ini</code>||[[:en:INI file|INI]]
|-
|<code>inno</code>||[[:en:Inno Setup|Inno]]
|-
|<code>intercal</code>||[[:en:INTERCAL|INTERCAL]]
|-
|<code>io</code>||[[:en:Io (programming language)|Io]]
|-
|<code>java</code>||[[:en:Java (programming language)|Java]]
|-
|<code>java5</code>||[[:en:Java (programming language)|Java(TM) 2 Platform Standard Edition 5.0 ]]
|-
|<code>javascript</code>||[[:en:JavaScript|JavaScript]]
|-
|<code>kixtart</code>||[[:en:KiXtart|KiXtart]]
|-
|<code>klonec</code>||Klone C
|-
|<code>klonecpp</code>||Klone C++
|-
|<code>latex</code>||[[:en:LaTeX|LaTeX]]
|-
|<code>lisp</code>||[[:en:Lisp (programming language)|Lisp]]
|-
|<code>lolcode</code>||[[:en:LOLCODE|LOLCODE]]
|-
|<code>lotusscript</code>||[[:en:LotusScript|LotusScript]]
|-
|<code>lua</code>||[[:en:Lua (programming language)|Lua]]
|}
{| class="wikitable" style="float:left"
!Code||Language
|-
|<code>m68k</code>||[[:en:Motorola 68000|Motorola 68000 Assembler]]
|-
|<code>make</code>||[[:en:Make_(software)|make]]
|-
|<code>matlab</code>||[[:en:MATLAB|MATLAB M]]
|-
|<code>mirc</code>||[[:en:mIRC scripting language|mIRC scripting language]]
|-
|<code>mxml</code>||[[:en:MXML|MXML]]
|-
|<code>mpasm</code>||[[:en:PIC microcontroller|Microchip Assembler]]
|-
|<code>mysql</code>||[[:en:MySQL|MySQL]]
|-
|<code>nsis</code>||[[:en:Nullsoft Scriptable Install System|Nullsoft Scriptable Install System (NSIS)]]
|-
|<code>objc</code>||[[:en:Objective-C|Objective-C]]
|-
|<code>ocaml-brief</code>||[[:en:Objective Caml|OCaml]]
|-
|<code>ocaml</code>||[[:en:Objective Caml|OCaml]]
|-
|<code>oobas</code>||[[:en:StarOffice Basic|OpenOffice.org Basic]]
|-
|<code>oracle8</code>||[[:en:PL/SQL|Oracle 8 SQL]]
|-
|<code>oracle11</code>||[[:en:PL/SQL|Oracle 11 SQL]]
|-
|<code>pascal</code>||[[:en:Pascal (programming language)|Pascal]]
|-
|<code>per</code>||per
|-
|<code>perl</code>||[[:en:Perl|Perl]]
|-
|<code>php-brief</code>||[[:en:PHP|PHP]]
|-
|<code>php</code>||[[:en:PHP|PHP]]
|-
|<code>pixelbender</code>||[[:en:Adobe_Pixel_Bender|Pixel Bender]]
|-
|<code>plsql</code>||[[:en:PL/SQL|PL/SQL]]
|-
|<code>povray</code>||[[:en:POV-Ray|Persistence of Vision Raytracer]]
|-
|<code>powershell</code>||[[:en:Windows_PowerShell|Windows PowerShell]]
|-
|<code>progress</code>||[[:en:OpenEdge_Advanced_Business_Language|OpenEdge Advanced Business Language]]
|-
|<code>prolog</code>||[[:en:Prolog|Prolog]]
|-
|<code>providex</code>||[[:en:ProvideX|ProvideX]]
|-
|<code>python</code>||[[:en:Python (programming language)|Python]]
|-
|<code>qbasic</code>||[[:en:QBasic|QBasic/QuickBASIC]]
|-
|<code>rails</code>||[[:en:Ruby on Rails|Rails]]
|-
|<code>reg</code>||[[:en:Windows Registry|Windows Registry]]
|-
|<code>robots</code>||[[:en:Robots Exclusion Standard|robots.txt]]
|-
|<code>ruby</code>||[[:en:Ruby (programming language)|Ruby]]
|-
|<code>sas</code>||[[:en:SAS System|SAS]]
|-
|<code>scala</code>||[[:en:Scala_(programming_language)|Scala]]
|-
|<code>scheme</code>||[[:en:Scheme (programming language)|Scheme]]
|-
|<code>scilab</code>||[[:en:Scilab|Scilab]]
|-
|<code>sdlbasic</code>||[[:en:SdlBasic|SdlBasic]]
|-
|<code>smalltalk</code>||[[:en:Smalltalk|Smalltalk]]
|-
|<code>smarty</code>||[[:en:Smarty|Smarty]]
|-
|<code>sql</code>||[[:en:SQL|SQL]]
|-
|<code>tcl</code>||[[:en:Tcl|Tcl]]
|-
|<code>teraterm</code>||[[:en:TeraTerm|Tera Term]]
|-
|<code>text</code>||[[:en:Plain text|Plain text]]
|-
|<code>thinbasic</code>||[[:en:thinBasic|thinBasic]]
|-
|<code>tsql</code>||[[:en:Transact-SQL|Transact-SQL]]
|-
|<code>typoscript</code>||[[:en:TYPO3|TypoScript]]
|-
|<code>vala</code>||[[:en:Vala_(programming_language)|Vala]]
|-
|<code>vb</code>||[[:en:Visual Basic|Visual Basic]]
|-
|<code>vbnet</code>||[[:en:Visual Basic .NET|Visual Basic .NET]]
|-
|<code>verilog</code>||[[:en:Verilog|Verilog]]
|-
|<code>vhdl</code>||[[:en:VHSIC Hardware Description Language|VHDL]]
|-
|<code>vim</code>||[[:en:Vimscript|Vimscript]]
|-
|<code>visualfoxpro</code>||[[:en:Visual FoxPro|Visual FoxPro]]
|-
|<code>visualprolog</code>||[[:en:Visual_Prolog|Visual Prolog]]
|-
|<code>whitespace</code>||[[:en:Whitespace_(programming_language)|Whitespace]]
|-
|<code>winbatch</code>||[[:en:Winbatch|Winbatch]]
|-
|<code>xml</code>||[[:en:XML|XML]]
|-
|<code>xorg_conf</code>||[[:en:Xorg.conf|Xorg.conf]]
|-
|<code>xpp</code>||[[:en:Microsoft_Dynamics_AX|X++]]
|-
|<code>z80</code>||[[:en:Zilog Z80|ZiLOG Z80 Assembler]]
|}
<div style="clear:both"></div>

[[Category:Help|Formatting]]

Navigation menu