Template:Code: Difference between revisions

From OLPC
Jump to navigation Jump to search
(use inline style in lieu of CSS change)
No edit summary
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<span style="background-color: #FFFFFF;
<span style="background-color: #FFFFFF;
border: 1px dotted #e6e6e6;
border: 1px dotted #d0d0d0;
font-family: monospace, 'Courier New';
font-family: monospace, 'Courier New';
font-size: 105%;">{{{1}}}</span><noinclude>
font-size: 105%;">{{{1}}}</span><noinclude>
Line 7: Line 7:
'''Good for short code segments:'''
'''Good for short code segments:'''
:{{Code|<nowiki>{{Code|code line}}</nowiki>}}
:{{Code|<nowiki>{{Code|code line}}</nowiki>}}



'''Not so good for longer segments:'''
'''Not so good for longer segments:'''
Line 16: Line 15:
The template form is shorter and easier to enter while editing.
The template form is shorter and easier to enter while editing.
----
----
Where the argument may contain an equals sign, escape that with nowiki.
{{Highlight|bgcolor=yellow|'''Note''': This template is not suitable for blocks of code.}}


For example:
:{{Code|yum install --enablerepo=something}} (did not work properly)
:{{Code|<nowiki>yum install --enablerepo=something</nowiki>}} (worked)
----
{{Highlight|bgcolor=yellow|'''Note''': This template is not suitable for blocks of code.}}
* Instead, see the technique below:
* Instead, see the technique below:



Latest revision as of 22:32, 21 August 2013

{{{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.


Where the argument may contain an equals sign, escape that with nowiki.

For example:

{{{1}}} (did not work properly)
yum install --enablerepo=something (worked)

Note: This template is not suitable for blocks of code.

  • 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