Template:Code listing/doc

From finiki, the Canadian financial wiki

This template allows you to display code listings (programming language) inside a collapsible box.

Usage

Invoke with:

{{Code listing| title = | state = | listing = <syntaxhighlight> ... </syntaxhighlight>}}

Arguments:

  • title: Title for the enclosing box. Optional. Default is "Code listing".
  • state: Initial display state. Optional. Default is "collapsed".
  • listing: Code listing. Required. Be sure to include the <syntaxhighlight>...</syntaxhighlight> tags. Or, use <pre> ... </pre> for any cases where syntax highlighting is not required or not possible.

The <syntaxhighlight> tag supports a number of parameters, such as lang="name" to specify the programming language and the line attribute which enables line numbers.

Example

Using:

{{Code listing|title=Hello world|listing= <syntaxhighlight lang="python" line>
#!/usr/bin/python3
print("Hello, world!")
</syntaxhighlight>}}

Results in:

Hello world
#!/usr/bin/python3
print("Hello, world!")

External links