Template:CodeBlock/doc: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(Created page with "<noinclude>{{DISPLAYTITLE:Template: Markdown Code Block/doc}}{{doc|0}}</noinclude>__NOTOC__ This template allows text to be formatted as a Markdown-style block of code. == Us...")
 
No edit summary
 
(46 intermediate revisions by 7 users not shown)
Line 1: Line 1:
<noinclude>{{DISPLAYTITLE:Template: Markdown Code Block/doc}}{{doc|0}}</noinclude>__NOTOC__
<noinclude>{{doc|0}}</noinclude>__NOTOC__
This template allows text to be formatted as a Markdown-style block of code.
This template formats the text as a block of code.


== Usage ==
==Parameters and Examples==
Just insert {{MdCode|outline|<nowiki>{{MdCodeBlock|YourText}}</nowiki>}} into the page and replace '''YourText''' with your content to make the code block styling work.
===Main===
 
The main parameters are described below.
<br>'''Manage Wiki Formatting:'''<br>
{| class=standard-table width=100%
You can use {{MdCode|outline|<nowiki><nowiki>YourText</nowiki></nowiki>}} to disable processing of various commands that allow the wiki to style your text. Also, it can disable the template style.
! style=width:10% | Name
 
! style=width:30% | Description
<br>'''Switching Styles:'''<br>
! Example
Insert {{MdCode|outline|<nowiki>style|</nowiki>}} after {{MdCode|outline|<nowiki>{{MdCodeBlock|</nowiki>}} and replace '''stylename''' with the name of an existing style.
! style=width:27% | Preview
 
<br>'''Using Modifiers:'''<br>
Insert {{MdCode|outline-oneclick|<nowiki>modifier=YourText|</nowiki>}} after {{MdCode|outline-oneclick|<nowiki>{{MdCode|</nowiki>}} or {{MdCode|outline-oneclick|<nowiki>style|</nowiki>}} and replace '''"modifier"''' with the name of an existing modifier. After the equal sign, you need to write the properties corresponding to the modifier.
 
<br>'''Adding a Block Header:'''<br>
A description of including a header in a block can be found [[Template:MdCodeBlock/Header|here]].
 
== Styles ==
{| class="standard-table"
! Name !! Description
|-
|-
| <code style="padding: 1px 3px;">default</code> || enabled by default, but disabled if other styles are activated
| align=center | {{Code|{{Param|1}}}}
| Your code.<br>It is recommended to wrap the template content with the {{Code|select=1|&#60;nowiki&#62;}} tag.
| {{CodeBlock|margin=5px|<nowiki>{{CodeBlock|Hello, World!}}</nowiki>}}
| {{Capsule|margin=5px|{{CodeBlock|margin=0|Hello, World!}}}}
|-
|-
| <code style="padding: 1px 3px; user-select: all;">limited</code> || default design with limited height (after reaching the maximum, scrolling will be activated)
| align=center | {{Code|{{Param|margin}}}}
| Controls margins. Goes clockwise.
| {{CodeBlock|margin=5px|<nowiki>{{CodeBlock|margin=5px 30px 0 10px|Hello, World!}}</nowiki>}}
| {{Capsule|margin=5px|{{CodeBlock|margin=5px 30px 0 10px|Hello, World!}}}}
|-
|-
| <code style="padding: 1px 3px; user-select: all;">outline</code> || less saturated version with outline
| align=center | {{Code|{{Param|style}}}}
| The style of the template. The following styles are available:
:* {{Code|1}} - Outlined version;
:* {{Code|style=3|Default}} - Default style that is based on Markdown.
| {{CodeBlock|margin=5px|<nowiki>{{CodeBlock|style=1|Hello, World!}}</nowiki>}}
| {{Capsule|margin=5px|{{CodeBlock|margin=0|style=1|Hello, World!}}}}
|-
|-
| <code style="padding: 1px 3px; user-select: all;">outline-limited</code> || same as outline, but with a limited height (after reaching the maximum, scrolling will be activated)
| align=center | {{Code|{{Param|height}}}}
| Controls the height of the block.
| {{CodeBlock|margin=5px|<nowiki>{{CodeBlock|height=52px|<nowiki>1. Hello World
2. Hello World
3. Hello World
4. Hello World<&#47;nowiki>}}</nowiki>}}
| {{Capsule|margin=5px|{{CodeBlock|height=52px|margin=0|<nowiki>1. Hello World
2. Hello World
3. Hello World
4. Hello World</nowiki>}}}}
|-
| align=center | {{Code|{{Param|width}}}}
| Controls the width of the block.
| {{CodeBlock|margin=5px|<nowiki>{{CodeBlock|width=50%|<nowiki>1. Hello World
2. Hello World
3. Hello World
4. Hello World
5. Hello World <&#47;nowiki>}}</nowiki>}}
| {{Capsule|margin=5px|{{CodeBlock|width=30%|margin=0|<nowiki>1. Hello World
2. Hello World
3. Hello World
4. Hello World
5. Hello World </nowiki>}}}}
|-
|-
|}
| align=center | {{Code|{{Param|lines}}}}
 
| ''Manual:'' Numbered lines.
== Modifiers ==
| {{CodeBlock|margin=5px|<nowiki>{{CodeBlock|lines=4|<nowiki>Hello World
{| class="standard-table"
Hello World
! Name !! Description
Hello World
Hello World<&#47;nowiki>}}</nowiki>}}
| {{Capsule|margin=5px|{{CodeBlock|lines=4|margin=0|<nowiki>Hello World
Hello World
Hello World
Hello World</nowiki>}}}}
|-
|-
| <code style="padding: 1px 3px; user-select: all;">height</code> || controls the height of styles with limited height (default {{MdCode|outline|auto}})
| align=center | {{Code|{{Param|start}}}}
| What number to start numbering from (default value is 1). The value can be negative.
| {{CodeBlock|margin=5px|<nowiki>{{CodeBlock|start=12|lines=5|<nowiki>Hello World
Hello World
Hello World
Hello World
Hello World<&#47;nowiki>}}</nowiki>}}
| {{Capsule|margin=5px|{{CodeBlock|start=12|lines=5|<nowiki>Hello World
Hello World
Hello World
Hello World
Hello World</nowiki>}}}}
|-
|-
| <code style="padding: 1px 3px; user-select: all;">margin</code> || controls margin (default {{MdCode|outline|5px 0 0 0}})
| align=center | {{Code|{{Param|highlight}}}}
| Adds syntax highlighting for the language specified. {{Bug|Condenses code into one line.}}
| {{CodeBlock|margin=5px|<nowiki>{{CodeBlock|highlight=c|int main() {return 0;} }}</nowiki>}}
| {{Capsule|margin=5px|{{CodeBlock|highlight=c|<nowiki>int main() {
return 0;
}</nowiki>}}}}
|-
|-
|}
|}


== Examples ==
===Header===
{{MdCodeBlock|outline|<nowiki>{{MdCodeBlock|margin=0|Hello World}}</nowiki>}}
The parameters for adding a header with the code source and the name of the programming language are described below.
{{Documentation/PreviewBlock|{{MdCodeBlock|margin=0|Hello World}}}}
{{note|The header is enabled automatically when you enter one of the following parameters.}}
{| class=standard-table width=100%
! style=width:10% | Name
! style=width:30% | Description
! Example
! style=width:27% | Preview
|-
| align=center | {{Code|{{Param|src}}}}
| The source of your code.
| {{CodeBlock|margin=5px|<nowiki>{{CodeBlock|src=light.rad|forcetextureshadow props_foliage/urban_tree01.mdl}}</nowiki>}}
| {{Capsule|margin=5px|{{CodeBlock|src=light.rad|margin=0|forcetextureshadow props_foliage/urban_tree01.mdl}}}}
|-
| align=center | {{Code|{{Param|lang}}}}
|The name of the language displayed on the right side of the header.
| {{CodeBlock|margin=5px|<nowiki>{{CodeBlock|lang=csharp
|<nowiki>using System;


namespace HelloWorld
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World");
        }
    }
}<&#47;nowiki>}}</nowiki>}}
| {{Capsule|margin=5px|{{CodeBlock|lang=csharp|margin=0|<nowiki>using System;


{{MdCodeBlock|outline|<nowiki>{{MdCodeBlock|limited|height=50px|margin=0|1. Hello World
namespace HelloWorld
2. Hello World
{
3. Hello World
    internal class Program
4. Hello World}}</nowiki>
    {
}}
        static void Main(string[] args)
{{Documentation/PreviewBlock|{{MdCodeBlock|limited|height=50px|margin=0|<nowiki>1. Hello World
        {
2. Hello World
            Console.WriteLine("Hello World");
3. Hello World
        }
4. Hello World</nowiki>
    }
}}}}
}</nowiki>}}}}
|}


== See also ==
* {{T|Code}}


[[Category:Markdown]]
{{Doc/Sandbox other|
 
[[Category:Templates]]
<includeonly>{{sandbox other||
[[Category:Formatting templates]]
[[Category:Markdown]]
}}
}}</includeonly>

Latest revision as of 09:27, 7 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)
Edit-copy.png
This is a documentation subpage for Template:CodeBlock.
Don't forget to purge the contents of the base page upon creating or editing this subpage.

This template formats the text as a block of code.

Parameters and Examples

Main

The main parameters are described below.

Name Description Example Preview
{{{1}}} Your code.
It is recommended to wrap the template content with the <nowiki> tag.
{{CodeBlock|Hello, World!}}
Hello, World!
{{{margin}}} Controls margins. Goes clockwise.
{{CodeBlock|margin=5px 30px 0 10px|Hello, World!}}
Hello, World!
{{{style}}} The style of the template. The following styles are available:
  • 1 - Outlined version;
  • Default - Default style that is based on Markdown.
{{CodeBlock|style=1|Hello, World!}}
Hello, World!
{{{height}}} Controls the height of the block.
{{CodeBlock|height=52px|<nowiki>1. Hello World 2. Hello World 3. Hello World 4. Hello World</nowiki>}}
1. Hello World 2. Hello World 3. Hello World 4. Hello World
{{{width}}} Controls the width of the block.
{{CodeBlock|width=50%|<nowiki>1. Hello World 2. Hello World 3. Hello World 4. Hello World 5. Hello World </nowiki>}}
1. Hello World 2. Hello World 3. Hello World 4. Hello World 5. Hello World
{{{lines}}} Manual: Numbered lines.
{{CodeBlock|lines=4|<nowiki>Hello World Hello World Hello World Hello World</nowiki>}}
  1.  
  2.  
  3.  
  4.  
Hello World Hello World Hello World Hello World
{{{start}}} What number to start numbering from (default value is 1). The value can be negative.
{{CodeBlock|start=12|lines=5|<nowiki>Hello World Hello World Hello World Hello World Hello World</nowiki>}}
  1.  
  2.  
  3.  
  4.  
  5.  
Hello World Hello World Hello World Hello World Hello World
{{{highlight}}} Adds syntax highlighting for the language specified.
Icon-Bug.pngBug:Condenses code into one line.  [todo tested in ?]
{{CodeBlock|highlight=c|int main() {return 0;} }}
int main() { return 0; }

Header

The parameters for adding a header with the code source and the name of the programming language are described below.

Note.pngNote:The header is enabled automatically when you enter one of the following parameters.
Name Description Example Preview
{{{src}}} The source of your code.
{{CodeBlock|src=light.rad|forcetextureshadow props_foliage/urban_tree01.mdl}}
light.rad
forcetextureshadow props_foliage/urban_tree01.mdl
{{{lang}}} The name of the language displayed on the right side of the header.
{{CodeBlock|lang=csharp |<nowiki>using System; namespace HelloWorld { internal class Program { static void Main(string[] args) { Console.WriteLine("Hello World"); } } }</nowiki>}}
The source was not specified
C#
using System; namespace HelloWorld { internal class Program { static void Main(string[] args) { Console.WriteLine("Hello World"); } } }

See also