Difference between revisions of "Template:Code"
Jump to navigation
Jump to search
(6 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | + | <code>{{{1}}}</code><noinclude> | |
==Usage== | ==Usage== | ||
+ | '''Good for short code segments:''' | ||
+ | :{{Code|<nowiki>{{Code|code line}}</nowiki>}} | ||
− | |||
− | Used to highlight code samples in an enlarged, monospace typeface that is easier to read than the default. | + | '''Not so good for longer segments:''' |
+ | :{{Code|This is a long line of code that may have many words that continue for a long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long length.}} | ||
+ | |||
+ | Used to highlight code samples in an enlarged (through the site's main.css), monospace typeface that is easier to read than the default. | ||
+ | |||
+ | The template form is shorter and easier to enter while editing. | ||
+ | ---- | ||
+ | {{Highlight|bgcolor=yellow|'''Note''': This template is not suitable for blocks of code.}} | ||
+ | |||
+ | * Instead, see the technique below: | ||
+ | |||
+ | ==For code blocks== | ||
+ | <pre> <nowiki><nowiki> | ||
+ | Start with a space in the first column, | ||
+ | (before the <nowiki>). | ||
+ | |||
+ | Then your block format will be | ||
+ | maintained. | ||
+ | |||
+ | This is good for copying in code blocks: | ||
+ | |||
+ | def function(): | ||
+ | """documentation string""" | ||
+ | |||
+ | if True: | ||
+ | print True | ||
+ | else: | ||
+ | print False</nowiki></nowiki> | ||
+ | </pre> | ||
+ | ===Working Example (click edit to see wikicode)=== | ||
+ | <nowiki> | ||
+ | def function(): | ||
+ | """documentation string""" | ||
+ | |||
+ | if True: | ||
+ | print True | ||
+ | else: | ||
+ | print False</nowiki> | ||
</noinclude> | </noinclude> |
Latest revision as of 17:53, 1 August 2012
{{{1}}}
Usage
Good for short code segments:
{{Code|code line}}
Not so good for longer segments:
This is a long line of code that may have many words that continue for a long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long length.
Used to highlight code samples in an enlarged (through the site's main.css), monospace typeface that is easier to read than the default.
The template form is shorter and easier to enter while editing.
- Instead, see the technique below:
For code blocks
<nowiki> Start with a space in the first column, (before the <nowiki>). Then your block format will be maintained. This is good for copying in code blocks: def function(): """documentation string""" if True: print True else: print False</nowiki>
Working Example (click edit to see wikicode)
def function(): """documentation string""" if True: print True else: print False