Jump to content

Help:XML-style tags

From mediawiki.org
PD Note: When you edit this page, you agree to release your contribution under the CC0. See Public Domain Help Pages for more info. PD

XML-style tags are used to format contents. It uses this syntax:

<tagname attribute1="value1" attribute2="value2"> content </tagname>

Parser extension tags

On any wiki, the Special:Version page shows the available parser extension tags in alphabetical order.

For example, on this wiki, the tags are as follows:

  • ‎<categorytree>
  • ‎<ce>
  • ‎<charinsert>
  • ‎<chem>
  • ‎<dynamicpagelist>
  • ‎<gallery>
  • ‎<graph>
  • ‎<hiero>
  • ‎<imagemap>
  • ‎<indicator>
  • ‎<inputbox>
  • ‎<langconvert>
  • ‎<languages>
  • ‎<mapframe>
  • ‎<maplink>
  • ‎<math>
  • ‎<nowiki>
  • ‎<phonos>
  • ‎<poem>
  • ‎<pre>
  • ‎<ref>
  • ‎<references>
  • ‎<rss>
  • ‎<score>
  • ‎<section>
  • ‎<source>
  • ‎<syntaxhighlight>
  • ‎<templatedata>
  • ‎<templatestyles>
  • ‎<timeline>

The Special:Version page also has a list of installed parser hooks , which work similarly but use slightly different syntax and generally produce more dynamic content or content that can be further postprocessed by other templates.

Tag functions

Each of the XML tags there has a different function:

Tag Description
‎<categorytree> Extension:CategoryTree
‎<ce> Deprecated alias for ‎<chem>
‎<charinsert> Extension:CharInsert
‎<chem> Extension:Math/Syntax
‎<dynamicpagelist> Extension:DynamicPageList
‎<gallery> Help:Images
‎<graph> Extension:Graph (currently not functional on most wikis due to security vulnerabilities)
‎<hiero> Extension:WikiHiero/Syntax
‎<imagemap> Extension:ImageMap
‎<indicator> Help:Page status indicators
‎<inputbox> Extension:InputBox
‎<langconvert> Writing systems/Syntax
‎<languages> Help:Extension:Translate
‎<mapframe>, ‎<maplink> Help:Extension:Kartographer
‎<math> Extension:Math/Syntax
‎<nowiki> Help:Advanced editing , Manual:Template expansion process#Intermediate results
‎<phonos> Help:Extension:Phonos
‎<poem> Extension:Poem
‎<pre> Help:Advanced editing , Manual:Template expansion process#Intermediate results
<ref name="...">, ‎<references> Help:Footnotes
‎<rss> Extension:RSS
<section begin="...">, <section end="..."> Extension:Labeled Section Transclusion
<source lang="..."> Deprecated alias for ‎<syntaxhighlight>
<syntaxhighlight lang="..."> Extension:SyntaxHighlight
‎<templatedata> Extension:TemplateData
‎<templatestyles> Extension:TemplateStyles
‎<timeline> Extension:EasyTimeline/syntax

Using the #tag parser function

You can use the parser function #tag which is a way to create custom HTML tags in MediaWiki in the following ways:


{{#tag:tagname|content}}
{{#tag:tagname|content|attribute1=value1}}
{{#tag:tagname|content|attribute1=value1|attribute2=value2}}

Other ways can be used too.

Below is an example before expansion:

{{#tag:tagname}}
{{#tag:tagname||attribute1=value1}}
{{#tag:tagname||attribute1=value1|attribute2=value2}}
{{#tag:tagname|content}}
{{#tag:tagname|content|attribute1=value1}}
{{#tag:tagname|content|attribute1=value1|attribute2=value2}}

After expansion:

<tagname/>
<tagname attribute1="value1"/>
<tagname attribute1="value1" attribute2="value2"/>
<tagname> content </tagname>
<tagname attribute1="value1"> content </tagname>
<tagname attribute1="value1" attribute2="value2"> content </tagname>

content must be provided first. If the first parameter is named (has an equals sign), the equals sign is ignored and the entire string including the parameter name is treated as the content. If the content has a "|", write it as {{!}}, except in contexts like ....

The standard XML-style tag syntax which usually doesn't parse any wikitext inside the tag, which is what makes things like <nowiki> work. Some tags like <ref> do parse the wikitext inside the tag as a special case, though.

The #tag: parser function, on the other hand, expands all other template calls before sending it to the XML-style tag. For example, with {{T2 }} containing "{{{1}}}", parameter 2 is "{{{2}}}":

  • <nowiki>{{t2|[[foo]]|[[bar]]}}</nowiki> leaves the template call unexpanded, resulting in {{t2|[[foo]]|[[bar]]}}.
  • {{#tag:nowiki|{{t2|[[foo]]|[[bar]]}}}} expands the template call but then leaves the wikilinks unexpanded, resulting in Parameter 1 is "[[foo]]", parameter 2 is "[[bar]]".
  • {{t2|[[foo]]|[[bar]]}} expands everything, resulting in Parameter 1 is "foo", parameter 2 is "bar"

For simple tags like <references/>, using {{#tag:references}} offers little benefit.

Non-parser tags

Other XML-style tags do not go through the parser at all. These generally do not work with #tag, and wikitext inside them is processed normally.

  • <noinclude>, <includeonly>, <onlyinclude>: See Help:Template#Controlling template inclusion.
  • Most ‘safe’ HTML tags: 'b', 'del', 'i', 'ins', 'u', 'font', 'big', 'small', 'sub', 'sup', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'cite', 'code', 'em', 's', 'strike', 'strong', 'tt', 'var', 'div', 'center', 'blockquote', 'ol', 'ul', 'dl', 'table', 'caption', 'pre', 'ruby', 'rt' , 'rb' , 'rp', 'p', 'span', 'u', 'br', 'hr', 'li', 'dt', 'dd', 'td', 'th', 'tr', see Help:HTML in wikitext
  • <!-- ... -->: The content within these is ignored entirely (It doesn't even become a comment in the resulting HTML). See Help:Comment tags
  • XML-style tags that don't meet the above criteria are rendered as-is, including HTML tags not allowed in wikitext. For example, <script>alert(1);</script><foo>bar</foo> is parsed unchanged, appearing as <script>alert(1);</script><foo>bar</foo>.

See also