Cookies helfen uns bei der Bereitstellung des IMT HilfeWikis. Bei der Nutzung vom IMT HilfeWiki werden die in der Datenschutzerklärung beschriebenen Cookies gespeichert.Weitere Informationen

Vorlage:Code

IMT HilfeWiki - das Wiki
Wechseln zu:Navigation, Suche
sample text
Documentation icon Template documentation[view] [edit] [history] [purge]

Description

This is a combination of the parser function <syntaxhighlight>...</syntaxhighlight> and the template {{pre2}}. It allows for code coloring depending on programming language conventions (like <syntaxhighlight>...</syntaxhighlight>) and inherits {{pre2}}'s ability for creating a horizontal slider if necessary (and requested). Also: It adds buttons to copy code into the clipboard.


Parameters

1
lang
The language used for color coding. Consult extension syntaxhighlight's documentation for a list of supported programming languages
2
code
The actual code displayed in the box. Warning: If your code contains an equal sign (=), you have to specify the parameter name as either code= or 2=, otherwise the display of text will be botched up.
3
scroll
optional If you don't want a horizontal slider for long text, set this to no
id
optional If you want rhe div containing your code having an id-attribute, pass it along with this parameter
line
optional If you want line numbering, set this to anything other than off
start
optional If you want your line numbering to start at anything else than 1, put this value here (works only in conjunction with line)
highlight
optional If you want line highlighted, list them here.
you can list values seperated by a comma or give a range or both: 1,4,9,11-13

Usage

{{code|bash|code=#!/bin/bash
mysql --defaults-file=/etc/mysql/debian.cnf}}

renders as

#!/bin/bash
mysql --defaults-file=/etc/mysql/debian.cnf

If you omit the paramater name (code=), thus writing

{{code|bash|#!/bin/bash
mysql --defaults-file=/etc/mysql/debian.cnf}}

your output will look like this:

sample text

a more complex example with parameters lang=lua|line=1|start=1|highlight=7,9:

 1 local templateClass = require('Module:Template/class')
 2 local classDebug = require('Module:Debug/class')
 3 
 4 -- ****************************************************************
 5 -- *                         inheritance                          *
 6 -- ****************************************************************
 7 local className = templateClass:subclass('Name')
 8 -- setting class's configuration data
 9 className.myConfiguration[tostring(className)] = mw.loadData('Module:Name/config')
10 
11 -- ****************************************************************
12 -- *                          properties                          *
13 -- ****************************************************************
14 
15 local _private = setmetatable({}, {__mode = 'k'})   -- weak table storing all private attributes

See also

  • {{code snippet}} for short code text in sentences
  • {{pre}} for a pre box with line wraps
  • {{pre2}} for a pre box with horizontal slider
  • <pre>...</pre>