Template:Code/Doc: Difference between revisions

Jump to navigation Jump to search
643 bytes added ,  30 November 2013
no edit summary
(note about Template:File)
No edit summary
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
This template is for code. The first argument is the title of the code block. The actual code still needs to be inside a <nowiki><pre>...</pre></nowiki> block. To markup code that is the contents of specific files, use [[Template:File]] instead.
This template is for code. The first argument is the title of the code block but can be left blank.


Example:
* the actual code still needs to be inside a {{Codeline|<nowiki><pre> ... </pre></nowiki>}} block or a {{Codeline|<nowiki><syntaxhighlight> ... </syntaxhighlight></nowiki>}} block.
<pre>{{Code|input check example|<pre>
* to markup code that is the contents of specific files, use [[Template:File]] instead.
  if (nargin < 1 || nargin > 4)
 
    print_usage;
== Code ==
  elseif (!isnumeric (arg1))
<pre>
    error ("first argument should be numeric");
{{Code
  endif
|Title=
&lt;/pre>}}</pre>
|Code=
}}
</pre>
You can omit the parameters if you respect the correct order.
 
== Examples ==
=== Example 1 ===
<pre>{{Code|input check example|
if (nargin < 1 || nargin > 4)
  print_usage;
endif
}}</pre>


Will produce:
Will produce:
{{Code|input check example|<pre>
{{Code|input check example|
  if (nargin < 1 || nargin > 4)
if (nargin < 1 || nargin > 4)
    print_usage;
  print_usage;
  elseif (!isnumeric (arg1))
endif
    error ("first argument should be numeric");
  endif
</pre>}}
</pre>}}
<noinclude>[[Category:Template Documentation]]</noinclude>
 
=== Example 2 ===
Note the empty code description.
<pre>{{Code|
|x (x > 20) = 34;
}}</pre>
 
Will produce:
{{Code|
|x (x > 20) = 34;
}}
 
=== Example 3 ===
<pre>
{{Code
|Title = input check example
|Code = if (nargin < 1 || nargin > 4)
  print_usage;
endif
}}
</pre>
 
Will produce:
{{Code
|Title = input check example
|Code = if (nargin < 1 || nargin > 4)
  print_usage;
endif
}}
 
=== Example 4 ===
<pre>
{{Code
|Title =
|Code = if (nargin < 1 || nargin > 4)
  print_usage;
endif
}}
</pre>
 
Will produce:
{{Code
|Title =
|Code = if (nargin < 1 || nargin > 4)
  print_usage;
endif
}}
 
[[Category:Template with documentation]]
501

edits

Navigation menu