Template:Code/doc

From The Unofficial Isekai:Slow Life Wiki
Revision as of 19:22, 31 July 2025 by FaeriMagic (talk | contribs) (Created page with "{{Documentation subpage|Template documnetation subpages}} ==Usage== Wraps a short span of text in <code><syntaxhighlight>...</syntaxhighlight></code> tags, see mw:Extension:SyntaxHighlight. This template should only be used for short samples; longer content should use <code><pre></code> or <code><syntaxhighlight></code>. See Help:Wiki markup for an explanation of what the various tags do. If the content includes an equals sign (=), yo...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This is the /doc subpage of Template:Code. Any changes made here will reflect on the main template page.

Usage

Wraps a short span of text in <syntaxhighlight>...</syntaxhighlight> tags, see mw:Extension:SyntaxHighlight. This template should only be used for short samples; longer content should use

 or <syntaxhighlight>. See Help:Wiki markup for an explanation of what the various tags do.

If the content includes an equals sign (=), you must specify the parameter explicitly: Template:Tji.

The template uses the Template:Tag tag with the attribute inline=1. This works like the combination of the Template:Tag and Template:Tag tags,  applied to the expanded wikitext. For example, Template:Tji will not render the word "wiki" in bold, and will render the tripled-single-quotes:

:<syntaxhighlight lang="text" class="" style="" inline="1">some wiki text</syntaxhighlight>

If the above example is declared as wikitext (via Template:Tji, the output is rendered as follows:

:<syntaxhighlight lang="wikitext" class="" style="" inline="1">some wiki text</syntaxhighlight>

However, Template:Tji will still invoke the template:

:<syntaxhighlight lang="wikitext" class="" style="" inline="1">a Template:Template call</syntaxhighlight>

Use Template:Tag around the template name to avoid this problem:

:<syntaxhighlight lang="wikitext" class="" style="" inline="1">a {{template}} call</syntaxhighlight>

When used inline with regular text, Template:Tnull generally looks best and is easiest to read when it is explicitly spaced apart from the regular text:
:<syntaxhighlight lang="wikitext" class="" style="" inline="1">foo  {{code|bar baz}}  quux.</syntaxhighlight>
is well spaced:
:foo  <syntaxhighlight lang="text" class="" style="" inline="1">bar baz</syntaxhighlight>  quux.
versus:
:<syntaxhighlight lang="wikitext" class="" style="" inline="1">foo {{code|bar baz}} quux.</syntaxhighlight>
which is less visually clear:
:foo <syntaxhighlight lang="text" class="" style="" inline="1">bar baz</syntaxhighlight> quux.
because "foo" and "<syntaxhighlight lang="text" class="" style="" inline="1">bar</syntaxhighlight>" will seem more closely associated than "<syntaxhighlight lang="text" class="" style="" inline="1">bar</syntaxhighlight>" and "<syntaxhighlight lang="text" class="" style="" inline="1">baz</syntaxhighlight>"; the width of the space character in a monospaced font is almost always larger than in a proportional font.

Use parameter {{{2}}} (unnamed, as Template:Para, or more explicitly as Template:Para) to specify a language for mw:Extension:SyntaxHighlight. This option defaults to Template:Para, i.e. no highlighting. Valid values include Template:Para for wikitext, Template:Para for HTML, along with many other languages including <syntaxhighlight lang="text" class="" style="" inline="1">php</syntaxhighlight>, <syntaxhighlight lang="text" class="" style="" inline="1">perl</syntaxhighlight>, <syntaxhighlight lang="text" class="" style="" inline="1">css</syntaxhighlight>, <syntaxhighlight lang="text" class="" style="" inline="1">javascript</syntaxhighlight>, <syntaxhighlight lang="text" class="" style="" inline="1">mysql</syntaxhighlight>. Attempting to use an invalid value for lang will cause the page to be added to Category:Pages with syntax highlighting errors, and no syntax highlighting will be present in the output. <syntaxhighlight lang="text" class="" style="" inline="1">html4strict</syntaxhighlight> and <syntaxhighlight lang="text" class="" style="" inline="1">html5</syntaxhighlight> used to be valid values - however, Template:Para should be used instead.

This template does not need to be substituted.

Examples

Template:Markup

Included templates

Embedded templates do not function as expected inside {{code}}; for longer, free-form blocks of code, which can contain templates such as {{var}} and {{samp}}, use Template:Tag as a wrapper instead of this template. Templates used inside {{code}} expose the rendered HTML— this can be useful. For example: The above example shows the HTML rendered by the citation template, including the hidden metadata.

Expensive Parser Function warning

This template internally uses mw:Extension:SyntaxHighlight, which is considered an 'expensive parser function' (see WP:EXPENSIVE). If used on a page which uses more than 500 expensive parser functions, the output of subsequent uses of this template will be presented using Template:Tag formatting (without any syntax highlighting) instead.

TemplateData

Template:Format TemplateData

See also

* {{mono}}, monospaced font only * Help:Wiki markup * Language-specific wrapper templates: ** {{jscode}}, defaults to 'javascript' ** {{luacode}}, defaults to 'lua' (for modules) ** {{tlcode}}, defaults to 'wikitext' (for templates) Template:Semantic markup templates