Project:Code samples

This page describes best practices for including code samples on pages on MediaWiki.org

Using SyntaxHighlight
You can use tags to format code samples with language-specific syntax highlighting. For a list of supported languages and required parameters, see Extension:SyntaxHighlight.

Copy to clipboard
To add a copy button to a code sample, add.

For example:

results in:

This functionality is provided through MediaWiki:Gadget-site-tpl-copy.js and MediaWiki:Gadget-site-tpl-copy.css.

Using the Codesample template
The Codesample template provides helpful features for formatting code samples, such as line numbers, filenames, and highlighting.

For example:

results in: