Template:Code:Interpreted/doc

Code:Interpreted
This is a rather more complex code template, intended to present code that can be typed in to an interpreter, rather than compiled. It is expected that this sort of code will be copied and pasted directly into an interactive shell-like environment. The same template can also be used for a variety of formats, such as basic input, or input plus output. This is achieved by using a template that accepts a variable number of arguments.

If a language is specified, then syntax highlighting of code is automatically included, using the &lt;source&gt; tag (courtesy of GeSHi). This also allows line numbering, or (with a few user CSS lines, as described below), displays a cursor character which will not be copied and pasted. This allows readers to copy and paste example code directly into the interpreter.

Named arguments
Called with 4 unnamed arguments, the output generated looks something like Template:Code:Output The 1st argument is for the initial explanation. The entire box is contained in a div of class "code".

Called with three unnamed arguments, the Results box vanishes, as does the (now unneeded) "Input" heading This is a script in Python. If you wish to format Python scripts differently from other scripts, add the following to your user CSS file .code * pre.source-python:before, .code .source-python pre:before {content: "\003E \003E \003E \0020";}

However, you might want an Input/Results box with no end explanation. If so, just use a blank 4th argument You might want to provide a Python-specific prompt in the output too. If so, just call &lt;pre&gt; with the appropriate class

Now it gets simpler. With two unnamed arguments: There is no "after" text.

With one unnamed argument there is no before text. The first argument is the code cd /bin ls

Named arguments
There are 2 named arguments: "title", "lang". (Note it would be nice to have a 3rd, whether or not to apply an output prompt)

The effect of the "title" argument should be obvious: A simple example with 2 unnamed arguments and a "title" argument set to "Title example".

The named argument "lang" is a shortcut, so that you don't need to put the class="source-python" or equivalent in every &lt;pre&gt; tag. An example with all 6 possible arguments. The "lang" argument adds another class to the input div, called source-"lang"

Wiki Code
The code for all the above codeboxes is Called with 4 unnamed arguments, the output generated looks something like Template:Code:Output The 1st argument is for the initial explanation. The entire box is contained in a div of class "code".

Called with three unnamed arguments, the Results box vanishes, as does the (now unneeded) "Input" heading This is a script in Python. If you wish to format Python scripts differently from other scripts, add the following to your user CSS file&lt;pre&gt;.code .input pre.source-python:before, .code .source-python pre:before {content: "\003E \003E \003E \0020";}&lt;/pre&gt;

However, you might want an Input/Results box with no end explanation. If so, just use a blank 4th argument You might want to provide a Python-specific prompt in the output too. If so, just call &lt;pre&gt; with the appropriate class

Now it gets simpler. With two unnamed arguments: There is no "after" text.

With one unnamed argument there is no before text. The first argument is the code&lt;pre&gt;cd /bin&lt;/pre&gt;&lt;pre&gt;ls&lt;/pre&gt;

There are 2 named arguments: "title" and "lang". The effect of the "title" argument should be obvious: A simple example with 2 unnamed arguments and a "title" argument set to "Title example".

The named argument "lang" is a shortcut, so that you don't need to put the class="source-python" or equivalent in every &lt;pre&gt; tag. A simple example with 3 unnamed arguments and a "lang" argument. The "lang" argument adds another class to the input div, called source-"lang"