Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Template:Code: Difference between revisions

Template page
No edit summary
m Undo source format. Had unwanted effects.
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<noinclude>
<includeonly><table style="margin:5px; border:1px dashed #555555; padding:5px; background-color: SlateGray;"><tr><td style="white-space: pre-wrap; font-family: monospace,Courier; color: white;">{{{1|No content.}}}</td></tr></table></includeonly><noinclude>
<div style="float:right; margin-left:1em; margin-bottom:1em;">__TOC__</div>
{{documentation}}
</noinclude><table style='padding:5px; margin:5px; border:1px dashed #555555;'><tr><td style='white-space:pre;'>{{co|white|<code>{{{1|}}}</code>}}</td></tr></table><noinclude>
</noinclude>
 
Just a little something to be able to use pre-formatted text within the confined of a code-like presentation without the box taking up the entire width of the page.
== Usage ==
It's a simple template, you just add the code or function name you wish to present as the second argument:
* <nowiki>{{ code | text }}</nowiki>
== Example ==
This code:
 
{{co|yellow|<nowiki>{{ code | <nowiki> {{ foo | bar }} </nowiki></nowiki><nowiki> }}</nowiki>}}
 
Would result in this:
{{code|<nowiki>{{ foo | bar }}</nowiki>}}
And this code:
 
{{co|yellow|<nowiki>{{code|Foo</nowiki>}}<br>
{{co|yellow|bar}}<br>
{{co|yellow|&nbsp;&nbsp;Hah!<nowiki>}}</nowiki>}}
 
Would result in this:
{{code|Foo
bar
  Hah!}}
Similarly this code:
 
{{co|yellow|<nowiki>{{code|10 PRINT "Hello World!"</nowiki>}}<br>
{{co|yellow|<nowiki>20 END}}</nowiki>}}<br>
 
Would result in this:
{{code|10 PRINT "Hello World!"
20 END}}
 
Using it inline, like this:
 
{{co|yellow|foo <nowiki>{{code|Foo what? Huh? Huh!}}</nowiki> bar}}
 
Would result in this:
{{co|grey|Foo}}{{code|Foo what? Huh? Huh!}}{{co|grey| bar}}
 
This as opposed to how <nowiki><pre></pre></nowiki> tags usually work:
<pre>Go ahead, use all the width :(</pre>
 
[[Category:Template]][[Category:Tools]]</noinclude>