Template talk:CodeSample

From Kolmafia
Jump to navigation Jump to search

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>&lt;nowiki&gt;</code> tag, or <code>&amp;lt;</code> and <code>&amp;gt;</code>.

You can insert in-line code using the <code> tag. To prevent invalid parsing of angle brackets, you can use the <nowiki> tag, or &lt; and &gt;.

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 <syntaxhighlight> tag:

string [int] mymap;
file_to_map( "somefile.txt" , mymap );

Be warned: <syntaxhighlight> does not wrap the code in pretty grey boxes.

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.


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 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 <pre> tag for pre-formatted text. Because the resulting box would result in unwrapped overflowing text, you may need to use <pre style="white-space: nowrap;">.

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)

If so, could someone set a standard on how to post highlighted code samples on non-function pages (Data Structures, Control Structures, etc.), as well as un-highlighted sample input/output? I suggest using Template:CodeSample for all highlighting purposes and <pre> tags for un-highlighted code. I think using leading spaces is a bad idea. --PhilmASTErpLus 03:47, 22 June 2010 (UTC)