Help:Syntax Highlighting

From GTAMods Wiki
Revision as of 23:16, 7 December 2008 by Seemann (talk | contribs) (See also)
Jump to navigation Jump to search

If you want to include source code snippets in your articles, you can make use of the <source /> tag to automatically highlight the text according to the selected language to make it more readable.

Usage

In the wiki markup, you can use <source>...</source> tags.

Example for PHP:

<source lang="php">
<?php
  // Hello World in PHP
  echo 'Hello World!';
?>
</source>

Results in:

<?php
  // Hello World in PHP
  echo 'Hello World!';
?>

Parameters

There is a variety of parameters you can use:

lang
This is a keyword to specify the language you want to have highlighted. Use scm for mission script code (Sanny Builder syntax, provided by Seemann); for the other available languages see this list.
line
With this parameter set line numbers will show up at the start of each line.
start
If you are quoting from the middle of a file, use this to set the offset for line numbers.
highlight
To highlight certain lines of the code snipped, this parameter takes a list of line ranges.

Example

The following example shows scm code, with line numbers starting at 10, and lines 2, 7 and 9 to 11 highlighted:

<source lang="scm" line start="10" highlight="2, 7, 9-11">
:LoadModel
0247: load_model #BFORI
 
:CheckModel
0001: wait 0 ms
00D6: if 0
0248:   model #BFORI available
004D: jump_if_false @CheckModel
009A: 0@ = create_actor_pedtype 5 model #BFORI at 0.0 0.0 0.0
0249: release_model #BFORI
004E: end_thread
</source>

Results in:

:LoadModel
0247: load_model #BFORI
 
:CheckModel
0001: wait 0 ms
00D6: if 0
0248:   model #BFORI available
004D: jump_if_false @CheckModel
009A: 0@ = create_actor_pedtype 5 model #BFORI at 0.0 0.0 0.0
0249: release_model #BFORI
004E: end_thread

See also