Template:Code/doc

Revision as of 15:26, 6 August 2024 by JarlPenguin (talk | contribs) (Created page with "{{documentation header}} <!-- Documentation here --> {{lua|Delimited tag}} {{shortcut|cd}} {{see also|Template:Samp}} This template is an alternative way to use {{cd|<nowiki><code>...</code></nowiki>}} (i.e. the HTML <code><code></code> element). You should avoid using this template in history sections, but it's fine if you do. == Parameters == {| class="wikitable" |+ Code template parameters |- ! Parameter !! Behavior !! Accepted values !! Default |- | Anonymous...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
This is the documentation page. It should be transcluded into Template:Code. See Template:Documentation for more information.
This template uses Module:Delimited tag, a script written in Lua.
Shortcut
See also: Template:Samp

This template is an alternative way to use <code>...</code> (i.e. the HTML <code> element). You should avoid using this template in history sections, but it's fine if you do.

Parameters

Code template parameters
Parameter Behavior Accepted values Default
Anonymous parameters, i.e. parameters that don't have names. These are the text that code will display as inline <code> elements. One <code> element will be used to wrap each of the anonymous parameters. Any text. None
d, delim or delimiter The delimiter to use between the <code> elements. or, and, br, list, or-list, and-list, &, ,, none or any other text. or, and& have a special behavior where the delimiter is different at the end, and , adds a space after the comma, but all other deimiters are simply placed between the <code> elements.  (a single space)
wordbreak or wb If specified, long words in the <code> element will break into multiple lines. This might be required if you are dealing with URLs (see below). 1 true , or any other non-empty string. (boolean) False

Escape characters

Keep in mind pipes and equals signs are used to specifiy parameters in templates. If you want the text "number of cats = number of mice * 3 * multiplier" to be formatted propoerly, you must escape the =. {{cd|=}} gives an error because the equal sign if interpreted as assigning an empty string to the paramer whose name is an empty string.

Magic words

There are many ways to "escape" text on this wiki. First, we have magic words for the equals sign and pipe. And we can use the non-breaking space HTML entity for spaces.

Magic words
Wikitext Result Result in Code
{{!}}
{{=}} = =
&nbsp; =  

You might also need to escape double curly braces, {{like these}}, and many other forms of formatting on this wiki. This can be done using <nowiki>...</nowiki>, or by putting <nowiki/> between the braces. Non-breaking space (&nbsp;) works more often than <nowiki> element does, so I suggest you use &nbsp;.

Use the |delimiter= parameter (aliases |delim= or |d=) to change the separator between each string. Set this value to the name in words of the delimiter, such as "and", "br", "or-list", "none", etc. When using a list delimiter, use |list-level= to change the indentation (defaults to **).

HTML entities

If you want to include spaces at the start of end of a <code> element, you need to either escape it with <nowiki>...</nowiki> or use &nbsp;.

If you want to use <angle brackets>, <like this>, you might need to use more HTML entities. Usually, you won't need to do this, inless you are describing how to use HTML elements or HTML entities on the page where you're using this template.

Finally, in some rare instances, you will need to use the legendary &amp;, or even the mythical &amp;amp;.

Caption text
Name HTML Result Result in Code
Non-breaking space &nbsp;    
Less than &lt; < <
Greater than &gt; > >
Ampersand &amp; & &

Examples

  1. {{code|text}}text
  2. {{code|1|2|3|4|5}}1 2 3 4 5
  3. Formatted ocde
    1. {{code|''fancy text''}}fancy text
    2. {{code|'''emphasized text'''}}emphasized text
    3. {{code|link to [[Zombie]]}}link to Zombie
    4. {{code|[https://imgur.com/ image hosting site that we don't use on this wiki]}}image hosting site that we don't use on this wiki
  4. Comma delimiter
    1. {{code|1|2|3|4|5|d=,}}1, 2, 3, 4, 5
    2. {{code|1|2|3|4|5|delim=,}}1, 2, 3, 4, 5
    3. {{code|1|2|3|4|5|delimiter=,}}1, 2, 3, 4, 5
  5. And delimiter
    1. {{code|1|2|3|4|5|d=and}}1, 2, 3, 4, and 5
    2. {{code|1|2|3|4|5|delim=and}}1, 2, 3, 4, and 5
    3. {{code|1|2|3|4|5|delimiter=and}}1, 2, 3, 4, and 5
  6. Or delimiter
    1. {{code|1|2|3|4|5|d=and}}1, 2, 3, 4, and 5
    2. {{code|1|2|3|4|5|delim=and}}1, 2, 3, 4, and 5
    3. {{code|1|2|3|4|5|delimiter=and}}1, 2, 3, 4, and 5
  7. Escape character usage
    1. {{code|<nowiki>something=one|two|three</nowiki>}}something=one|two|three
    2. {{code|something{{=}}one{{!}}two{{!}}three}}something=one|two|three
    3. {{code|<nowiki> </nowiki>}} – 
    4. {{code|&nbsp;}} 

Word Breaking

Breaking example 1
Header text A Header text B Header text C Header text D Header text E
Some text Normally if you have a really long piece of text, like this, it doesn't cause any issues, because the text will break between the words into multiple lines. More text More text More text, extended to make my point.
Normally if you have a really long piece of text, like this, it doesn't cause any issues, because the text will break between the words into multiple lines. Some text More text More text More text, extended to make my point.
Yet more text. Yet more text. Yet more text. Yet more text. Yet more text.

However, if we have an extremely long URL (this example is not actually in the game), like minecraft/generation/overworld/structures/rare/experimental/trial_chambers/version_3/chambers/chamber_4/section_3/layer_3/step_1/loot_table/main_draw.json, it will not break when used in a table and will end up making its column far too wide.

I have collapsed this table for your convenience. Good luck finding the collapse button after expanding it!

Breaking example 2
Header text A Header text B Header text C Header text D Header text E
Some text minecraft/generation/overworld/structures/rare/experimental/trial_chambers/version_3/chambers/chamber_4/section_3/layer_3/step_1/loot_table/main_draw.json More text More text More text, extended to make my point.
minecraft/generation/overworld/structures/rare/experimental/trial_chambers/version_3/chambers/chamber_4/section_3/layer_3/step_1/loot_table/main_draw.json Some text More text More text More text, extended to make my point.
Yet more text. Yet more text. Yet more text. Yet more text. Yet more text.

As you can see, having our words break would be nice here. The easiest way to do this to use the wb/wordbreak parameter. It allows the line to break anywhere it needs to, even in the middle of a word. The table below shows what this does

Breaking example 3
Wiki text Code result Header text C Header text D Header text E
{{cd|minecraft/generation/overworld/structures/rare/experimental/trial_chambers/version_3/chambers/chamber_4/section_3/layer_3/step_1/loot_table/main_draw.json|wb=1}} minecraft/generation/overworld/structures/rare/experimental/trial_chambers/version_3/chambers/chamber_4/section_3/layer_3/step_1/loot_table/main_draw.json More text More text More text, extended to make my point.
{{cd|minecraft/generation/overworld/structures/rare/experimental/trial_chambers/version_3/chambers/chamber_4/section_3/layer_3/step_1/loot_table/main_draw.json|wb=1}} minecraft/generation/overworld/structures/rare/experimental/trial_chambers/version_3/chambers/chamber_4/section_3/layer_3/step_1/loot_table/main_draw.json More text More text More text, extended to make my point.
Yet more text. Yet more text. Yet more text. Yet more text. Yet more text.