Displaying Code with proper Indentation

From The DarkMod Wiki
Revision as of 10:29, 7 October 2007 by Tels (talk | contribs) (re-org)
Jump to navigationJump to search

In DarkWiki there exists no such thing as a [code][/code] block like in a Forum, that automatically formats the content of the brackets in a fixed font and keeps indentation.

To keep the indentation of a text in DarkWiki (for example a piece of code or an extract of a shader definition), just add a space character in front of every line you want to quote, like this:

<<-- The first character of this line is a space
 ||
 ||
\\// The line below has also a space as first character
 
//\\ The above line has also a space as first character
 ||
 ||

Just take a look at the source code of this very page to get an impression of how it works, it's really simple. Or mark the above sample with your mouse to see the empty spaces in front of each line.

If you have several lines of code, you just have to make sure that every line starts with a space. This also applies to line-spacers, as in the example below. Everything after the first space character counts as indentation.

// The following is an example of some code
void foo()
{
  if(a == b)
     a++;

  if(a > 19)
     return;
}

Note, that the line between the a++; and the if(a > 19) is such a line-spacer.

If you omitted the space character in this line-spacer, it would produce an unintended result like this:

// The following is an example of some code
void foo()
{
  if(a == b)
     a++;
  if(a > 19)
     return;
}

Here, the code parts are separated, as the line-spacer contains no space character.

So, remember to put a space character in front of every line you want to display in a code block.