|
|
Line 481: |
Line 481: |
| |} | | |} |
|
| |
|
| == Pre-formatted text == | | == Preformatted text == |
| | {{main article|Help:Preformatted text}} |
| | |
| There is many different ways to do monospaced pre-formatted text. | | There is many different ways to do monospaced pre-formatted text. |
|
| |
|
Line 523: |
Line 525: |
| <nowiki>Here is some text. | | <nowiki>Here is some text. |
| And some more.</nowiki> | | And some more.</nowiki> |
| |-
| |
| | Using <nowiki><pre></nowiki> tags.
| |
| |
| |
| <nowiki><pre>Some text.
| |
| Some more text.</pre></nowiki>
| |
| | <pre>Some text.
| |
| Some more text.</pre>
| |
| |}
| |
|
| |
| === 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 <nowiki><pre></nowiki> tag together with a style attribute to wrap the text.
| |
|
| |
| {| class="wikitable" width="100%"
| |
| ! Description
| |
| ! width="30%" | What you type
| |
| ! width="30%" | What you get
| |
| |-
| |
| | Using <nowiki><pre style="white-space: pre-wrap;"></nowiki> to wrap the text.
| |
| |
| |
| <nowiki><pre style="white-space: pre-wrap;">This is a very long...</pre></nowiki>
| |
| |<pre style="white-space: pre-wrap;">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.</pre>
| |
| |}
| |
|
| |
| {| class="wikitable"
| |
| ! width="40%" | Description
| |
| ! width="30%" | What you type
| |
| ! What you get
| |
| |-
| |
| | Using only <nowiki><pre></nowiki>.
| |
| |
| |
| <nowiki><pre>This is a very long...</pre></nowiki>
| |
| |<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.</pre>
| |
| |} | | |} |
|
| |
|
| === Syntax highlighting === | | === 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 <nowiki><syntaxhighlight></nowiki> tags. The tag can be given some attributes to control how the source code appears.
| | <'''syntaxhighlight''' lang="" ''line start=""'' ''highlight=""'' ''inline''></syntaxhighlight> |
| | |
| 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 ('''"'''). | | All attributes but '''lang''' are 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'''. | | ; lang: The language to be highlighted, for example '''bash''', '''cpp''' or '''xml'''. |
|
| |
|
| ; line: Use line numbering. | | ; line: Use line numbering. |
Line 572: |
Line 538: |
| ; 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. | | ; 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. | | ; 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,5-7''' highlight line 3 and 5-7 in a snippet. |
|
| |
|
| ; enclose | | ; inline |
| : Encloses the source code in a certain html tag. Takes either '''pre''', '''div''' or '''none''', with '''pre''' being the default one. | | : Used when syntax highlighting is needed in running text. |
| : Using '''div''' will wrap lines that are too long to fit the screen width so they continue on the following line.
| |
|
| |
|
| {| class="wikitable" width="100%" | | {| class="wikitable" width="100%" |
Line 583: |
Line 548: |
| ! width="30%" | What you get | | ! width="30%" | What you get |
| |- | | |- |
| | Nasal highlighting.
| | | XML highlighting, arbitrarily starting from line 46, and highlighting the 1st, 3rd and 4th line in the snippet. |
| |
| |
| <pre style="white-space: pre-wrap;"><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>
| |
| </pre>
| |
| | <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>
| |
| | |
| |-
| |
| | XML highlighting, here with line numbering, but without specifying the line number of the first line. | |
| | | | | |
| <pre style="white-space: pre-wrap;"><syntaxhighlight lang="xml" line enclose="div"> | | <nowiki><syntaxhighlight lang="xml" line start="46" highlight="1,3-4"> |
| <animation> | | <animation> |
| <object-name>Object</object-name> | | <object-name>Object</object-name> |
Line 606: |
Line 556: |
| </animation> | | </animation> |
| </syntaxhighlight> | | </syntaxhighlight> |
| </pre> | | </nowiki> |
| | <syntaxhighlight lang="xml" line enclose="div"> | | | <syntaxhighlight lang="xml" line start="46" highlight="1,3-4"> |
| <animation> | | <animation> |
| <object-name>Object</object-name> | | <object-name>Object</object-name> |
Line 614: |
Line 564: |
| </syntaxhighlight> | | </syntaxhighlight> |
| |- | | |- |
| | C++ highlighting, arbitrarily starting from line 46, and highlighting the 4th line in the snippet. | | | Syntax highlighting in running text |
| | | | | |
| <pre style="white-space: pre-wrap;"><syntaxhighlight lang="cpp" line start="46" highlight="4" enclose="div"> | | <nowiki>A typical C++ comment <syntaxhighlight lang="cpp" inline>// looks like this</syntaxhighlight>.</nowiki> |
| globals->get_commands()->execute("profiler-start");
| | | A typical C++ comment <syntaxhighlight lang="cpp" inline>// looks like this</syntaxhighlight>. |
| // or with filename | |
| SGPropertyNode args;
| |
| args.setStringValue("filename", "output.profile");
| |
| globals->get_commands()->execute("profiler-start", &args);
| |
| </syntaxhighlight></pre> | |
| |<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> | |
| |} | |
| | |
| ==== 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 <code>style="background: #ffdddd;"</code> which will give the background color a pink tint instead of the default gray <code>#dddddd</code>.
| |
| | |
| When illustrating comparisons between a good and a bad way of doing something the good example can be given a green tint with <code>#ddffdd</code>. ''Only use the green tint when comparing against a snippet of bad code.''
| |
| | |
| {| class="wikitable" width="100%"
| |
| ! Description
| |
| ! width="30%" | What you type
| |
| ! width="30%" | What you get
| |
| |-
| |
| | Highlighting bad coding practices or common errors
| |
| |
| |
| <pre style="white-space: pre-wrap;">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>
| |
| </pre>
| |
| |
| |
| A common pitfall is forgetting a slash in a closing tag:
| |
| <syntaxhighlight lang="xml" style="background: #ffdddd;">
| |
| <?xml version="1.0" encoding="UTF-8"?>
| |
| <PropertyList>
| |
| <!-- Contents -->
| |
| <PropertyList> <!-- Note missing slash -->
| |
| </syntaxhighlight>
| |
| |-
| |
| | Good and bad examples next to each other
| |
| |
| |
| <pre style="white-space: pre-wrap;">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>
| |
| </pre> | |
| |
| |
| Bad [[PropertyList XML File|property-list XML file]] (without 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>
| |
| |} | | |} |
|
| |
|