Vorlage:Code/doc: Unterschied zwischen den Versionen
imported>Oetterer Keine Bearbeitungszusammenfassung |
|||
Zeile 2: | Zeile 2: | ||
<!-- Categories go at the bottom of this page. --> | <!-- Categories go at the bottom of this page. --> | ||
== Description == | == Description == | ||
This is a combination of the | This is a combination of the parser function {{tag|syntaxhighlight}} and the template {{tl|pre2}}. It allows for code coloring depending on programming language conventions (like {{tag|syntaxhighlight}}) and inherits {{tl|pre2}}'s ability for creating a horizontal slider if necessary (and requested). Also: It adds buttons to copy ''code'' into the clipboard. | ||
{{ambox|type=info|text=If you want to code wikitext, use lang ''html'', ''html4strict'', ''moin'' or ''xml'', since the parser function does not have a mediawiki or wikitext lang.}} | |||
{{ambox|type=delete|text=If your wiki code contains calls to ''templates'', ''parser tags'' or ''parser functions'', you have to encode them in {{tli|text|''unstrip''|<nowiki>'''your call here'''</nowiki>}}!}} | |||
== Parameters == | == Parameters == | ||
Zeile 12: | Zeile 17: | ||
:The actual code displayed in the box. '''{{colors|darkred||Warning: }}''' If your code contains an equal sign (=), you have to specify the parameter name as either {{code snippet|code{{=}}}} or {{code snippet|2{{=}}}}, otherwise the display of text will be botched up. | :The actual code displayed in the box. '''{{colors|darkred||Warning: }}''' If your code contains an equal sign (=), you have to specify the parameter name as either {{code snippet|code{{=}}}} or {{code snippet|2{{=}}}}, otherwise the display of text will be botched up. | ||
;3 | ;3 | ||
;scroll | |||
:''optional'' If you don't want a horizontal slider for long text, set this to {{code snippet|no}} | :''optional'' If you don't want a horizontal slider for long text, set this to {{code snippet|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 == | == Usage == | ||
Zeile 32: | Zeile 47: | ||
{{code|bash|#!/bin/bash | {{code|bash|#!/bin/bash | ||
mysql --defaults-file=/etc/mysql/debian.cnf}} | mysql --defaults-file=/etc/mysql/debian.cnf}} | ||
a more complex example with parameters <code>lang=lua|line=1|start=1|highlight=7,9</code>: | |||
{{code|lang=lua|line=1|start=1|highlight=7,9|code= | |||
local templateClass = require('Module:Template/class') | |||
local classDebug = require('Module:Debug/class') | |||
-- **************************************************************** | |||
-- * inheritance * | |||
-- **************************************************************** | |||
local className = templateClass:subclass('Name') | |||
-- setting class's configuration data | |||
className.myConfiguration[tostring(className)] = mw.loadData('Module:Name/config') | |||
-- **************************************************************** | |||
-- * properties * | |||
-- **************************************************************** | |||
local _private = setmetatable({}, {__mode = 'k'}) -- weak table storing all private attributes | |||
}} | |||
== See also == | == See also == |
Aktuelle Version vom 7. Oktober 2016, 08:07 Uhr
This is a documentation subpage for Vorlage:Code. It contains usage information, categories and other content that is not part of the original vorlage page. |
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.
{{#vardefine:ambox_color|info}}
{{#vardefine:ambox_image|Information icon4.svg}}{{#vardefine:ambox_imageSize|40x40px}}{{#vardefine:ambox_image|[[File:{{#var:ambox_image|Mbox notice.png}}|{{#var:ambox_imageSize|40x40px}}|alt=|link=]]}}{{#vardefine:ambox_content|{| class="metadata plainlinks"
|-
| class="mbox-image" |
| class="mbox-text" |If you want to code wikitext, use lang html, html4strict, moin or xml, since the parser function does not have a mediawiki or wikitext lang. |}
}}
{{#vardefine:ambox_color|danger}}
{{#vardefine:ambox_image|Ambox warning pn.svg}}{{#vardefine:ambox_imageSize|40x40px}}{{#vardefine:ambox_image|[[File:{{#var:ambox_image|Mbox notice.png}}|{{#var:ambox_imageSize|40x40px}}|alt=|link=]]}}{{#vardefine:ambox_content|{| class="metadata plainlinks"
|-
| class="mbox-image" |
| class="mbox-text" |If your wiki code contains calls to templates, parser tags or parser functions, you have to encode them in {{#invoke:text|unstrip|<nowiki>your call here</nowiki>}}! |}
}}
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
orcode=
, otherwise the display of text will be botched up.2=
- 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 (
), thus writing
code=
{{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
:
local templateClass = require('Module:Template/class')
local classDebug = require('Module:Debug/class')
-- ****************************************************************
-- * inheritance *
-- ****************************************************************
local className = templateClass:subclass('Name')
-- setting class's configuration data
className.myConfiguration[tostring(className)] = mw.loadData('Module:Name/config')
-- ****************************************************************
-- * properties *
-- ****************************************************************
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>