Template talk:CodeSample: Difference between revisions
imported>PhilmASTErpLus No edit summary |
imported>PhilmASTErpLus Why not set some rigid standard on how to display code in general? |
||
(One intermediate revision by one other user not shown) | |||
Line 67: | Line 67: | ||
So....like....why do we even NEED this template? --[[User:PhilmASTErpLus|PhilmASTErpLus]] 03:40, 21 June 2010 (UTC) | So....like....why do we even NEED this template? --[[User:PhilmASTErpLus|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 <nowiki><syntaxhighlight></nowiki> 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. --[[User:StDoodle|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 <code><pre></code> tags for un-highlighted code. I think using [http://en.wikipedia.org/wiki/Help:Wiki_markup#Limiting_formatting.2Fescaping_wiki_markup leading spaces] is a bad idea. --[[User:PhilmASTErpLus|PhilmASTErpLus]] 03:47, 22 June 2010 (UTC) |
Latest revision as of 03:47, 22 June 2010
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)
- 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)