Template talk:CodeSample
Comparison of various methods of formatting code:
What it looks like | What you type |
---|---|
You can insert in-line code using the <code><nowiki><code></nowiki></code> tag. To prevent invalid parsing of angle brackets, you can use the <code><nowiki></code> tag, or <code>&lt;</code> and <code>&gt;</code>. |
You can insert in-line code using the |
For syntax highlighting, use the <code><syntaxhighlight></code> tag: <syntaxhighlight> string [int] mymap; file_to_map( "somefile.txt" , mymap ); </syntaxhighlight> Be warned: <code><syntaxhighlight></code> does not wrap the code in pretty boxes. |
For syntax highlighting, use the string [int] mymap;
file_to_map( "somefile.txt" , mymap ); Be warned: |
You can use [[Template:CodeSample]] to wrap the code in a pretty box. {{CodeSample |code= item needed = $item[ ketchup hound ]; //Could someone think of a longer example, please? }} Be warned: [[Template:CodeSample]] does not format the text in monospace. |
You can use Template:CodeSample to wrap the code in a pretty box.
|
You can use the <code><pre></code> tag for pre-formatted text. Because the resulting box would result in unwrapped overflowing text, you may need to use <code><pre style="white-space: nowrap;"></code>. <pre style="white-space: nowrap;"> print( "Hello, world!" ); </pre> |
You can use the print( "Hello, world!" ); |
So....like....why do we even NEED this template? --PhilmASTErpLus 03:40, 21 June 2010 (UTC)
There are HUNDREDS of references to this template on this wiki. The main issue is that having a larger overall template for functions doesn't allow one to insert the <syntaxhighlight> tag in a sane way, unless a sub-template (ie this one) is used. In other words, it's a wrapper for the aforementioned tag to deal with wiki markup limitations. --StDoodle (#1059825) 04:31, 21 June 2010 (UTC)