This page has been semi-protected so that only established users can edit it.

Template:Code: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(Revamp: use {{{preset}}} for style presets instead of {{{style}}}; {{{style}}} now specifies CSS like other templates; use <syntaxhighlight> instead of <code> for parity with wp:Template:Code; add alias {{{background}}} for {{{bg}}})
mNo edit summary
 
(48 intermediate revisions by 9 users not shown)
Line 1: Line 1:
<onlyinclude><includeonly><!-- CHOMP
{{Semi-protection}}
-->{{ #tag: syntaxhighlight
{{Documentation}}
  | {{{ code | {{{ 1 | }}} }}} <!-- CHOMP
<includeonly><onlyinclude>{{#tag: {{#if: {{{lang|}}} | syntaxhighlight | code }}
-->| style = user-select: {{ #switch: {{{ select | <!-- NOP --> }}} <!-- this should probably be word-only since adding integrals means an ugly switch-case -->
|{{{1|}}}| inline = 1
                          | 1        = all
| style = padding:2px 4px; background:#0003 !important; box-decoration-break:clone; {{{style|}}}
                          | 2        = none
| {{#if: {{{lang|}}} | lang }} = {{{lang|}}}
                          | #default = {{{ select | inherit }}}
}}</onlyinclude></includeonly>
                          }};<!-- CHOMP
          -->{{ #switch:
              {{ #iferror:
                  {{ #expr: trunc({{{ style | {{{ preset }}} }}}) = {{{ style | {{{ preset }}} }}} and
                            1 <= {{{ style | {{{ preset | NO }}} }}} and
                            {{{ style | {{{ preset | STOP }}} }}} <= 4 }} <!-- CHOMP
                  // `style` is CSS styles -->
                  | {{ #if: {{{ preset | <!-- NOP --> }}}
                    | USE_PRESET <!-- CHOMP // `preset` specified; override `style`
                -->| STYLE_WITH_CSS <!-- CHOMP // use `style` like every other template does it
                -->}} <!-- CHOMP
                  // `style` or `preset` is numbered preset; known real number in interval [1, 4] -->
                  | DEPRECATED_STYLE_AS_PRESET<!-- CHOMP
            -->}}<!-- END #IFERROR
          -->| USE_PRESET <!--
          -->| DEPRECATED_STYLE_AS_PRESET = {{ #ifexpr: {{{ style | {{{ preset }}} }}} = 3
                                            | color: {{ #if: {{{ color | <!-- NOP --> }}} | {{{ color }}} | currentcolor }};<!-- CHOMP
                                          -->background-color: inherit;
                                            | background-color: {{ #ifexpr: {{{ style | {{{ preset }}} }}} <= 2
                                                                | rgb(0 0 0 / 16%)
                                                                | rgb(255 255 255 / 5%)
                                                                }};<!-- CHOMP
                                          -->border: {{ #ifexpr: {{{ style | {{{ preset }}} }}} != 2
                                                      | 1px solid rgb(255 255 255 / 10%)
                                                      | none
                                                      }};
                                            }}
            | STYLE_WITH_CSS              = background-color: {{ #if: {{{ background | <!-- NOP --> }}}{{{ bg | <!-- NOP --> }}} | {{{ background | {{{ bg }}} }}} | rgb(0 0 0 / 35%) }};<!-- CHOMP
                                        -->border: 1px solid rgb(255 255 255 / 15%);<!-- CHOMP
                                        -->color: {{ #if: {{{ color | <!-- NOP --> }}} | {{{ color }}} | inherit }};<!-- CHOMP
                                        -->{{{ style | <!-- NOP --> }}}
            | #default                  = all: inherit; <!-- Unreachable codepath unless you bork something up there
          -->}}<!-- CHOMP, END #IF
-->| lang = {{{ lang | text }}}
  | class = {{{ class | }}}
  | id = {{{ id | }}}
  | inline = 1
}}</includeonly></onlyinclude>
<noinclude>{{Doc}}</noinclude>

Latest revision as of 11:31, 22 October 2025

English (en)Deutsch (de)Esperanto (eo)Español (es)Français (fr)Suomi (fi)Hrvatski (hr)Magyar (hu)Italiano (it)日本語 (ja)한국어 (ko)Nederlands (nl)Polski (pl)Português (pt)Português do Brasil (pt-br)Русский (ru)Slovenčina (sk)Svenska (sv)Türkçe (tr)Українська (uk)Tiếng Việt (vi)中文 (zh)中文(臺灣) (zh-tw)
Curly brackets white.pngTemplate Documentation [view] [edit]
Icon-translate.png Available doc translations
Page history

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