Template:Code/doc: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
 
(18 intermediate revisions by 3 users not shown)
Line 2: Line 2:
This template will allow you to format text as a one-line code.
This template will allow you to format text as a one-line code.


== Parameters and Examples ==
== Usage ==
{| class=standard-table | style="width:100%"
<div style="margin:-6px 0 6px"><span style="display:inline-block; width:22px; height:16px; background:#FFF; vertical-align:text-bottom; clip-path:path('M0 4v8H1V4ZM9 4v8h1V4ZM3 6v4H7V6Zm9 0v4h4V6Z')"></span>This template prefers inline formatting of parameters</div>
 
{| cellpadding="6" rules="all" style="width:100%; border:1px solid #555; background:#2D2D2D"
|- style="background:#333; color:#DFDFDF"
! Parameters
! {{int:Listfiles description}}
! {{int:Preview}}
|-
|-
! Parameter
| style="font-family:monospace" | {{P| <Text>}} <br> {{P| 1 | <Text>}}
! Description
| The text that will be displayed. Can contain links, templates and raw html, except when the {{Param|lang}} parameter is used.
! Example
| style="background:#262626" | {{Code|Hello, World!}}
! Preview
|-
|-
| align=center | {{Code|{{param|style}}}}
| style="font-family:monospace" | {{P| lang | <Option>}}
| The style of the template. The following styles are available:
| Adds syntax highlighting for the language specified using [[mw:Extension:SyntaxHighlight|syntaxhighlight]] tag with [[mw:Extension:SyntaxHighlight#inline|inline]] attribute. <br> [[mw:Extension:SyntaxHighlight#Supported_languages|List of Supported languages]].
:* {{Code|style=3|Default}} – the default style is based on Markdown;
| style="background:#262626" | {{Code|lang=c|int main() { return 0; } }}
:* {{Code|1}} – Outlined version;
:* {{Code|2}} – Desaturated version;
:* {{Code|3}} – Clear version;
:* {{Code|4}} – A brighter outlined version.
| {{CodeBlock|&#123;&#123;Code&#124;{{tint|color=yellow|style}}<nowiki>=</nowiki>{{tint|color=green|1}}&#124;{{tint|color=comment|Hello, World!}}&#125;&#125;}} {{CodeBlock|&#123;&#123;Code&#124;{{tint|color=yellow|style}}<nowiki>=</nowiki>{{tint|color=green|2}}&#124;{{tint|color=comment|Hello, World!}}&#125;&#125;}} {{CodeBlock|&#123;&#123;Code&#124;{{tint|color=yellow|style}}<nowiki>=</nowiki>{{tint|color=green|3}}&#124;{{tint|color=comment|Hello, World!}}&#125;&#125;}}{{CodeBlock|&#123;&#123;Code&#124;{{tint|color=yellow|style}}<nowiki>=</nowiki>{{tint|color=green|4}}&#124;{{tint|color=comment|Hello, World!}}&#125;&#125;}}
| {{Capsule|margin=5px|{{Code|style=1|Hello, World!}}}} {{Capsule|margin=5px|{{Code|style=2|Hello, World!}}}} {{Capsule|margin=5px|{{Code|style=3|Hello, World!}}}} {{Capsule|margin=5px|{{Code|style=4|Hello, World!}}}}
|-
| align=center | {{Code|{{param|select}}}}
| Text selection mode. The following values are available:
:* {{Code|style=3|Default}} – Initial state;
:* {{Code|0}} – None: template content will not be highlighted;
:* {{Code|1}} – All: one click selection.
| {{CodeBlock|&#123;&#123;Code&#124;{{tint|color=yellow|select}}<nowiki>=</nowiki>{{tint|color=green|1}}&#124;{{tint|color=comment|Hello, World!}}&#125;&#125;}} {{CodeBlock|&#123;&#123;Code&#124;{{tint|color=yellow|select}}<nowiki>=</nowiki>{{tint|color=green|2}}&#124;{{tint|color=comment|Hello, World!}}&#125;&#125;}}
| {{Capsule|margin=5px|{{Code|select=1|Hello, World!}}}} {{Capsule|margin=5px|{{Code|select=2|Hello, World!}}}}
|-
| align=center | {{Code|{{param|color}}}}
| Text color. <br> HSL, HEX, RGB and more are supported.
| {{CodeBlock|&#123;&#123;Code&#124;{{tint|color=yellow|color}}<nowiki>=</nowiki>{{tint|color=green|#EF9B9B}}&#124;{{tint|color=comment|Hello, World!}}&#125;&#125;}}
| {{Capsule|margin=5px|{{Code|color=#EF9B9B|Hello, World!}}}}
|-
| align=center | {{Code|{{param|bg}}}}
| Background color. <br> HSL, HEX, RGB and more are supported.
| {{CodeBlock|&#123;&#123;Code&#124;{{tint|color=yellow|bg}}<nowiki>=</nowiki>{{tint|color=green|rgba(239,155,155,.15)}}&#124;{{tint|color=comment|Hello, World!}}&#125;&#125;}}
| {{Capsule|margin=5px|{{Code|bg=rgba(239,155,155,.15)|Hello, World!}}}}
|-
|-
| style="font-family:monospace" | {{P| style | <CSS>}}
| CSS styles. Note that some styles require {{Code|!important}} to be specified.
| style="background:#262626" | {{Code|style=color:#EF9B9B !important|Colored text}}
|}
|}
== See Also ==
* {{T|CodeBlock}}
* {{T|Mono}}


{{Doc/Sandbox other|
{{Doc/Sandbox other|

Latest revision as of 08:22, 21 October 2025

Edit-copy.png
This is a documentation subpage for Template:Code.
Don't forget to purge the contents of the base page upon creating or editing this subpage.

This template will allow you to format text as a one-line code.

Usage

This template prefers inline formatting of parameters
Parameters Description Preview
| <Text>
| 1 = <Text>
The text that will be displayed. Can contain links, templates and raw html, except when the {{{lang}}} parameter is used. Hello, World!
| lang = <Option> Adds syntax highlighting for the language specified using syntaxhighlight tag with inline attribute.
List of Supported languages.
int main() { return 0; }
| style = <CSS> CSS styles. Note that some styles require !important to be specified. Colored text

See Also