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
 
(41 intermediate revisions by 8 users not shown)
Line 1: Line 1:
<onlyinclude><includeonly><!-- CHOMP
See Also: [[Template:CodeBlock]]
-->{{ #tag: syntaxhighlight
{{doc}}
  | {{{ code | {{{ 1 | }}} }}} <!-- CHOMP
 
-->| style = user-select: {{ #switch: {{{ select | <!-- NOP --> }}} <!-- this should probably be word-only since adding integrals means an ugly switch-case -->
<includeonly><onlyinclude><span style="font-family:monospace; {{#switch:{{{p|{{{preset|}}}}}}
                          | 1        = all
|#default = padding:2px 4px; border-radius:3px; background:rgb(0 0 0 / 26%);
                          | 2        = none
|0 =
                          | #default = {{{ select | inherit }}}
|1 = padding:2px 4px; border-radius:3px; background:rgb(0 0 0 / 16%);
                          }};<!-- CHOMP
|2 = padding:1px 3px; border-radius:3px; background:rgb(0 0 0 / 16%); border:1px solid rgb(255 255 255 / 10%);
          -->{{ #switch:
|3 = padding:1px 3px; border-radius:3px; background:rgb(255 255 255 / 5%); border:1px solid rgb(255 255 255 / 10%);
              {{ #iferror:
}} {{#if:{{{select|}}}|user-select:{{{select}}};}} {{{style|}}}">{{#if:{{{highlight|}}}|{{#tag:syntaxhighlight|{{{1}}}|lang={{{highlight}}}|inline=1}}|{{{1}}}}}</span></onlyinclude></includeonly>
                  {{ #expr: trunc({{{ style | {{{ preset }}} }}}) = {{{ style | {{{ preset }}} }}} and
 
                            1 <= {{{ style | {{{ preset | NO }}} }}} and
[[Category:Formatting templates]]
                            {{{ 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 16:09, 17 August 2025

See Also: Template:CodeBlock

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
View
Page history

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

Parameters and Examples

Parameters Description Examples Preview
{{{preset}}} Preset Template Styles. The following presets are available:
  • Default – The default style is based on Markdown;
  • 0 – Clear version;
  • 1 – Desaturated version;
  • 2 – Outlined version;
  • 3 – A brighter outlined version.
{{Code|Hello, World!}}
{{Code|preset=0|Hello, World!}}
{{Code|preset=1|Hello, World!}}
{{Code|preset=2|Hello, World!}}
{{Code|preset=3|Hello, World!}}
Hello, World!
Hello, World!
Hello, World!
Hello, World!
Hello, World!
{{{select}}} Text selection mode. Uses the user-select CSS property. Default value is unset.
{{Code|select=none|Hello, World!}}
{{Code|select=all|Hello, World!}}
Hello, World!
Hello, World!
{{{style}}} CSS styles.
{{Code|style=color:#EF9B9B|Hello, World!}}
Hello, World!
{{{highlight}}} Adds syntax highlighting for the language specified.
Icon-Bug.pngBug:Condenses code into one line.  [todo tested in ?]
{{Code|highlight=c|int main() {return 0;} }}
int main() {return 0;}