Help:XML-style tags
Note: When you edit this page, you agree to release your contribution under the CC0. See Public Domain Help Pages for more info. |
XML-style tags use 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.
On MediaWiki, 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> and <timeline>
The special:version page also has a list of installed parser hooks, which allow more dynamic content to be included on any page.
Other standard tags exist but they aren't defined in the special:version page. They include:
- <categorytree mode="..." hideprefix="..." ...> and other attributes. See Extension:CategoryTree
- <charinsert>: See Extension:CharInsert
- <dynamicpagelist>: see Extension:DynamicPageList (Wikimedia) and n:DynamicPageList
- <gallery caption="..." widths="..." heights="..." perrow="...">: See Help:Images and other uploaded files#Gallery
- <hiero>: See Extension:WikiHiero
- <imagemap>: See Extension:ImageMap
- <inputbox>: See Extension:InputBox
- <math>: See m:Help:Displaying a formula; comes with the MediaWiki distribution, but it requires a separate installation, see Manual:Math
- <nowiki> and <pre>: See Help:Advanced editing#Disabling wikitext interpretation and/or reformatting, Manual:Template expansion process#Intermediate results and Markup spec/BNF/Noparse-block
- <poem>: See Extension:Poem
- <ref name="...">, <references>: See Help:Footnotes and Extension:Cite/Cite.php
- <section begin="...">, <section end="...">: See Extension:Labeled Section Transclusion
- <source lang="...">: See Extension:ASHighlight
- <syntaxhighlight lang="...">: See Extension:SyntaxHighlight GeSHi
- <timeline>: See Extension:EasyTimeline/syntax
Tag 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.
First, identify the wikitexts for the content, the attribute names, and the values, and expand each. If two attributes, attribute1, and attribute2, have the same name values, keep the value of the second one and discard the first. This is similar to template calls but different from the #switch function, where "a=b|a=c" is considered equivalent to "a=b".
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>
After the first "|", content is fixed, and "=" within the expanded wikitext has no special significance. The entire text is used regardless. If the content has a "|", write it as {{!}}, except in contexts like [[...|...]]. For example, write external links in a timeline as [...{{!}}...].
The tag function is a useful alternative to XML-style tags because it doesn't expand the wikitext for content and attributes.
It allows parameters, variables, parser functions, and templates. For nowiki and pre-tags, the choice depends on what effect you want, but for most other extensions, the tag function is more versatile.
However, double braces in the content can cause parsing issues, which can be fixed by adding a space between the braces.
For simple tags like <references/>
, using {{#tag:references}}
offers little benefit.
Other
- <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
- <!-- ... -->: See Help:Comment tags and Markup spec/BNF/Noparse-block#HTML-comment