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}}})
m (The last change hurt the wiki)
Line 1: Line 1:
<onlyinclude><includeonly><!-- CHOMP
{{Doc}}
-->{{ #tag: syntaxhighlight
<includeonly><onlyinclude><code style="border-radius:3px; color:{{{color|currentcolor}}}; user-select:{{#switch:{{{select|}}}|#default=text|0=none|1=all}}; background-color:{{#switch:{{{style}}}
  | {{{ code | {{{ 1 | }}} }}} <!-- CHOMP
|#default = {{{bg|rgb(0,0,0,.35)}}}; padding:2px 3px">{{{1|}}}
-->| style = user-select: {{ #switch: {{{ select | <!-- NOP --> }}} <!-- this should probably be word-only since adding integrals means an ugly switch-case -->
|1 = {{{bg|rgba(0,0,0,.16)}}}; border:1px solid rgba(255,255,255,.1); padding:1px 3px">{{{1|}}}
                          | 1        = all
|2 = {{{bg|rgba(0,0,0,.16)}}}; padding:2px 3px">{{{1|}}}
                          | 2        = none
|3 = {{{bg|initial}}}">{{{1|}}}
                          | #default = {{{ select | inherit }}}
|4 = {{{bg|rgba(255,255,255,.05)}}}; border:1px solid rgba(255,255,255,.1); padding:1px 3px">{{{1|}}}
                          }};<!-- CHOMP
}}<span style="user-select:none"></span></code></onlyinclude></includeonly>
          -->{{ #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>

Revision as of 08:25, 29 April 2023

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;}