Template:Code listing/doc
This is a documentation subpage for Template:Code listing. It contains usage information, categories and other content that is not part of the original template page. |
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:
|
External links
- Extension:SyntaxHighlight, MediaWiki extension for syntax highlighting