Vorlage:Code/doc: Unterschied zwischen den Versionen
imported>Oetterer Keine Bearbeitungszusammenfassung |
imported>Oetterer Keine Bearbeitungszusammenfassung |
||
| (Eine dazwischenliegende Version desselben Benutzers wird nicht angezeigt) | |||
| Zeile 1: | Zeile 1: | ||
{{Documentation subpage}} | {{Documentation subpage}} | ||
{{lua|Module:Code}} | |||
<!-- Categories go at the bottom of this page. --> | <!-- Categories go at the bottom of this page. --> | ||
== Description == | == Description == | ||
| Zeile 16: | Zeile 17: | ||
;code | ;code | ||
: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. | ||
;line | ;line | ||
:''optional'' | :''optional'' The line attribute enables line numbers. | ||
;start | ;start | ||
:''optional'' | :''optional'' The start attribute (in combination with ''line'') defines the first line number of the code block. | ||
;highlight | ;highlight | ||
:''optional'' | :''optional'' The highlight attribute specifies one or more lines that should be marked (by highlighting those lines with a different background color). | ||
:you can list values seperated by a comma or give a range or both: 1,4,9,11-13 | :you can list values seperated by a comma or give a range or both: 1,4,9,11-13 | ||
;inline | |||
:''optional'' The attribute indicates that the source code should be inline as part of a paragraph (as opposed to being its own block). | |||
;class | |||
:''optional'' The css class to use. When inline is used, class="nowrap" (on those wikis that support it; not on MediaWiki itself) specifies that line breaks should not occur at spaces within the code block. | |||
;style | |||
:''optional'' CSS styles to add | |||
== Usage == | == Usage == | ||
Aktuelle Version vom 11. Oktober 2022, 10:53 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. |
| This template uses Lua: |
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.
| 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. |
| 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
code=or2=, otherwise the display of text will be botched up. - line
- optional The line attribute enables line numbers.
- start
- optional The start attribute (in combination with line) defines the first line number of the code block.
- highlight
- optional The highlight attribute specifies one or more lines that should be marked (by highlighting those lines with a different background color).
- you can list values seperated by a comma or give a range or both: 1,4,9,11-13
- inline
- optional The attribute indicates that the source code should be inline as part of a paragraph (as opposed to being its own block).
- class
- optional The css class to use. When inline is used, class="nowrap" (on those wikis that support it; not on MediaWiki itself) specifies that line breaks should not occur at spaces within the code block.
- style
- optional CSS styles to add
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:
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>