Help:Preformatted text
Monospaced preformatted text can be added in many different ways on the FlightGear wiki.
Pre-formatted running text
Description | What you type | What you get |
---|---|---|
Using <code> HTML tags. |
Here is a <code>'''Class()'''</code>. |
Here is a Class() .
|
Using <tt> HTML tags. |
Here is a <tt>''variable''</tt>. |
Here is a variable. |
Pre-formatted blocks
Apart from using <tt> and <code> on entire blocks of text one one can use the below methods.
Description | What you type | What you get |
---|---|---|
The simplest way is with a leading blank space on each line. |
You '''''can''''' use '''wiki markup''' using this method. |
You can use wiki markup using this method. |
Using <nowiki> tags with a leading blank space. | <nowiki>Here is some text. And some more.</nowiki> |
Here is some text. And some more. |
Using <pre> tags. |
<pre>Some text. Some more text.</pre> |
Some text. Some more text. |
Wrapping in pre-formatted blocks
None of the above mentioned methods for pre-formatted text block wraps. A line that is too long to fit the screen width would continue past the screen edge instead of wrapping around to continue on the following line. A work around to this is to use the <pre> tag together with a style attribute to wrap the text.
Description | What you type | What you get |
---|---|---|
Using <pre style="white-space: pre-wrap;"> to wrap the text. |
<pre style="white-space: pre-wrap;">This is a very long...</pre> |
This is is a very long line of text that could continue past the screen edge. I could have filled it with pure nonsense but I think I will instead just be lazy and copy what I got so far. Sorry. This is is a very long line of text that could continue past the screen edge. I could have filled it with pure nonsense but I think I will instead just be lazy and copy what I got so far. Sorry. |
Description | What you type | What you get |
---|---|---|
Using only <pre>. |
<pre>This is a very long...</pre> |
This is is a very long line of text that could continue past the screen edge. I could have filled it with pure nonsense but I think I will instead just be lazy and copy what I got so far. Sorry. This is is a very long line of text that could continue past the screen edge. I could have filled it with pure nonsense but I think I will instead just be lazy and copy what I got so far. Sorry. |
Syntax highlighting
Syntax highlighting will make source code more readable. This wiki has support for syntax highlighting of many programming languages, including nasal, XML and C++ (see mediawikiwiki:Extension:SyntaxHighlight_GeSHi for a more complete list). The source code snippet to be highlighted is put between <syntaxhighlight> tags. The tag can be given some attributes to control how the source code appears.
Note that you can use syntax highlighting for command lines as well.
<syntaxhighlight lang="" line start="" highlight="" enclose=""></syntaxhighlight>
All attributes but lang is optional. start have to be used together with line. Values must be put inside quotation marks (").
- lang
- The language to be highlighted, for example bash, cpp, dos, nasal or xml.
- line
- Use line numbering.
- start
- Used together with line if you want the line numbering to start somewhere else than one. For example will 42 start the line numbering from 42 instead of 1.
- highlight
- Used for highlighting a line. Do note that lines are counted from the first line in a snippet disregarding start. For example will 3 highlight the third line in a snippet.
- enclose
- Encloses the source code in a certain html tag. Takes either pre, div or none, with pre being the default one.
- Using div will wrap lines that are too long to fit the screen width so they continue on the following line.
Description | What you type | What you get |
---|---|---|
Nasal highlighting. |
<syntaxhighlight lang="nasal" enclose="div"> fgcommand("profiler-start"); # default file name is fgfs.profile // or with a custom filename fgcommand("profiler-start", props.Node.new({"filename": "output.profile"})); </syntaxhighlight> |
fgcommand("profiler-start"); # default file name is fgfs.profile
// or with a custom filename
fgcommand("profiler-start", props.Node.new({"filename": "output.profile"})); |
XML highlighting, here with line numbering, but without specifying the line number of the first line. |
<syntaxhighlight lang="xml" line enclose="div"> <animation> <object-name>Object</object-name> <enable-hot type="bool">false</enable-hot> </animation> </syntaxhighlight> |
<animation>
<object-name>Object</object-name>
<enable-hot type="bool">false</enable-hot>
</animation>
|
C++ highlighting, arbitrarily starting from line 46, and highlighting the 4th line in the snippet. |
<syntaxhighlight lang="cpp" line start="46" highlight="4" enclose="div"> globals->get_commands()->execute("profiler-start"); // or with filename SGPropertyNode args; args.setStringValue("filename", "output.profile"); globals->get_commands()->execute("profiler-start", &args); </syntaxhighlight> |
globals->get_commands()->execute("profiler-start");
// or with filename
SGPropertyNode args;
args.setStringValue("filename", "output.profile");
globals->get_commands()->execute("profiler-start", &args);
|
Differentiating a bad and a good code snippet
One can make examples of bad code, for example with common coding errors or bad coding practices, stand out by adding the cascading style sheets (CSS) attribute style="background: #ffdddd;"
which will give the background color a pink tint instead of the default gray #dddddd
.
When illustrating comparisons between a good and a bad way of doing something the good example can be given a green tint with #ddffdd
. Only use the green tint when comparing against a snippet of bad code.
Description | What you type | What you get |
---|---|---|
Highlighting bad coding practices or common errors |
A common pitfall is forgetting a slash in a closing tag: <?xml version="1.0" encoding="UTF-8"?> <syntaxhighlight lang="xml" style="background: #ffdddd;"> <PropertyList> <!-- Contents --> <PropertyList> <!-- Note missing slash --> </syntaxhighlight> |
A common pitfall is forgetting a slash in a closing tag: <?xml version="1.0" encoding="UTF-8"?>
<PropertyList>
<!-- Contents -->
<PropertyList> <!-- Note missing slash -->
|
Good and bad examples next to each other |
Bad [[PropertyList XML File|property-list XML file]] (missing an XML header). <syntaxhighlight lang="xml" style="background: #ffdddd;"> <PropertyList> <!-- Contents --> </PropertyList> </syntaxhighlight> Do it like this instead: <syntaxhighlight lang="xml" style="background: #ddffdd;"> <?xml version="1.0" encoding="UTF-8"?> <PropertyList> <!-- Contents --> </PropertyList> </syntaxhighlight> |
Bad property-list XML file (without an XML header) <PropertyList>
<!-- Contents -->
</PropertyList>
Do it like this instead: <?xml version="1.0" encoding="UTF-8"?>
<PropertyList>
<!-- Contents -->
</PropertyList>
|