Displaying Code with proper Indentation: Difference between revisions

From The DarkMod Wiki
Jump to navigationJump to search
No edit summary
 
Tels (talk | contribs)
mention code and pre tags
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
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.
In DarkWiki there are three ways to format a text in a monospaced font and thus keep 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:
== Code ==
 
You can use <nowiki><code></code></nowiki> for texts that are displayed inline. Example: <code>Taffer</code>
 
== Pre ==
 
You can use <nowiki><pre></pre></nowiki> for texts that span multiple paragraphs: Example:
 
<pre>
Taffer
 
taffing
 
  tough.
</pre>
 
== Spacing ==
   
In addition, you can 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 first character of this line is a space
   ||
   ||
Line 42: Line 60:
'''So, remember to put a space character in front of every line you want to display in a code block.'''
'''So, remember to put a space character in front of every line you want to display in a code block.'''


[[Category:Tutorial]]
{{tutorial-wiki|sort=Code}}
[[Category:Wiki]]

Latest revision as of 10:33, 7 October 2007

In DarkWiki there are three ways to format a text in a monospaced font and thus keep indentation:

Code

You can use <code></code> for texts that are displayed inline. Example: Taffer

Pre

You can use <pre></pre> for texts that span multiple paragraphs: Example:

Taffer

 taffing

   tough.

Spacing

In addition, you can 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.