Aus SatriaWiki
Wechseln zu: Navigation, Suche
(Die Seite wurde neu angelegt: „==Permitted HTML== The following HTML elements are currently permitted: {| border="0" cellpadding="5" | valign="top"| * [[w:HTML_eleme…“)
 
 
Zeile 1: Zeile 1:
 +
For many HTML elements, more convenient wikitext code is available, see [[Help:Wiki markup]], however there are some situations in which the HTML alternative is useful, for example creating a link to a particular element of a table.
 +
 
==Permitted HTML==
 
==Permitted HTML==
The following [[w:HTML element|HTML element]]s are currently permitted:
+
The following [[HTML element]]s are currently permitted:
       
+
 
{| border="0" cellpadding="5"
+
* [[HTML element#General|<abbr>]]
| valign="top"|
+
**Marks an abbreviation, and can make the full form available: <abbr title="abbreviation">abbr.</abbr>
* [[w:HTML_element#Phrase elements|&lt;abbr&gt;]]
+
* [[HTML element#Presentation|&lt;b&gt;]]
* [[w:HTML_element#Official presentational markup|&lt;b&gt;]]
+
**<b>Sets font to boldface where possible</b>
* [[w:HTML_element#Official presentational markup|&lt;big&gt;]]
+
* [[HTML element#Presentation|&lt;big&gt;]]
* [[w:HTML_element#General block elements|&lt;blockquote&gt;]]
+
**<big>Increases</big> font size
* [[w:HTML_element#Images and objects|&lt;br&gt;]]
+
* [[HTML element#Other block elements|&lt;blockquote&gt;]]
* [[w:HTML_element#Tables|&lt;caption&gt;]]
+
**A block-level quotation, <blockquote>for when the quotation includes block level elements,</blockquote> e.g. paragraphs
* [[w:HTML_element#Official presentational markup|&lt;center&gt;]]
+
* [[HTML element#Other inline elements|&lt;br&gt;]]
* [[w:HTML_element#General phrase elements|&lt;cite&gt;]]
+
**A forced<br/> line-break
* [[w:HTML_element#Computer code phrase elements|&lt;code&gt;]]
+
* [[HTML element#Tables|&lt;caption&gt;]]
* [[w:HTML_element#Lists|&lt;dd&gt;]]
+
**<table><caption>Specifies a caption for a table</caption></table>
* [[w:HTML_element#Special inline elements|&lt;del&gt;]]
+
* [[HTML element#Other block elements|&lt;center&gt;]]
* [[w:HTML_element#Other containers|&lt;div&gt;]]
+
**<center>Creates a block-level center-aligned division</center> Use <code>&lt;div&gt;</code> instead
* [[w:HTML_element#Lists|&lt;dl&gt;]]
+
* [[HTML element#Other inline elements|&lt;cite&gt;]]
* [[w:HTML_element#Lists|&lt;dt&gt;]]
+
**<cite>A citation</cite>
* [[w:HTML_element#General phrase elements|&lt;em&gt;]]
+
* [[HTML element#Computer phrase elements|&lt;code&gt;]]
* [[w:HTML_element#Official presentational markup|&lt;font&gt;]]
+
**<code>A code snippet</code>
| valign="top"|
+
* [[HTML element#Lists|&lt;dd&gt;]]
* [[w:HTML_element#Headings|&lt;h1&gt;]]
+
**<dl><dd>The definition of a term,</dd><dd>in a definition list</dd></dl>
* [[w:HTML_element#Headings|&lt;h2&gt;]]
+
* [[HTML element#Other block elements|&lt;del&gt;]]
* [[w:HTML_element#Headings|&lt;h3&gt;]]
+
**<del>Deleted text</del>
* [[w:HTML_element#Headings|&lt;h4&gt;]]
+
* [[HTML element#Other block elements|&lt;div&gt;]]
* [[w:HTML_element#Headings|&lt;h5&gt;]]
+
**<div>A block-level logical division</div>
* [[w:HTML_element#Headings|&lt;h6&gt;]]
+
* [[HTML element#Lists|&lt;dl&gt;]]
* [[w:HTML_element#General block elements|&lt;hr&gt;]]
+
**<dl>A definition list (consisting of definition terms paired with definitions)</dl>
* [[w:HTML_element#Official presentational markup|&lt;i&gt;]]
+
* [[HTML element#Lists|&lt;dt&gt;]]
* [[w:HTML_element#Special inline elements|&lt;ins&gt;]]
+
**<dl><dt>A definition term</dt><dt>in a definition list</dt></dl>
* [[w:HTML_element#Lists|&lt;li&gt;]]
+
* [[HTML element#General|&lt;em&gt;]]
* [[w:Ordered list|&lt;ol&gt;]]
+
**<em>Emphasis</em>
* [[w:HTML_element#General block elements|&lt;p&gt;]]
+
* [[HTML element#Presentation|&lt;font&gt;]]
* [[w:HTML_element#Other containers|&lt;pre&gt;]]
+
**<font color="green" size="-1" face="Courier">Can specify the font color with the color attribute, typeface with the face attribute, and absolute or relative size with the size attribute.</font> use <nowiki><span></nowiki> instead
* [http://www.w3.org/TR/1999/WD-ruby-19990322/ &lt;rb&gt;]
+
* [[HTML element#Basic text|&lt;h1&gt;]] - [[HTML element#Basic text|&lt;h6&gt;]]
* [http://www.w3.org/TR/1999/WD-ruby-19990322/ &lt;rp&gt;]
+
**<nowiki><h1>Section headings at different levels.</h1></nowiki>
* [http://www.w3.org/TR/1999/WD-ruby-19990322/ &lt;rt&gt;]
+
* [[HTML element#Other block elements|&lt;hr&gt;]]
* [http://www.w3.org/TR/1999/WD-ruby-19990322/ &lt;ruby&gt;]
+
**<hr>A horizontal rule</hr>
| valign="top"|
+
* [[HTML element#Presentation|&lt;i&gt;]]
* [[w:HTML_element#Official presentational markup|&lt;s&gt;]]
+
**<i>Sets font to italic where possible</i>
* [[w:HTML_element#Official presentational markup|&lt;small&gt;]]
+
* [[HTML element#Other block elements|&lt;ins&gt;]]
* [[w:HTML_element#Span element|&lt;span&gt;]]
+
**<ins>Inserted text</ins>
* [[w:HTML_element#Official presentational markup|&lt;strike&gt;]]
+
* [[HTML element#Lists|&lt;li&gt;]]
* [[w:HTML_element#General phrase elements|&lt;strong&gt;]]
+
**<li>A list item in ordered (ol)</li><li>or unordered (ul) lists</li>
* [[w:HTML_element#Special inline elements|&lt;sub&gt;]]
+
* [[HTML element#Lists|&lt;ol&gt;]]
* [[w:HTML_element#Special inline elements|&lt;sup&gt;]]
+
**<ol><li>An ordered...</li><li>(enumerated) list</li></ol>
* [[w:HTML_element#Tables|&lt;table&gt;]]
+
* [[HTML element#Basic text|&lt;p&gt;]]
* [[w:HTML_element#Tables|&lt;td&gt;]]
+
**Creates a <p>paragraph,</p> perhaps the most common block level element
* [[w:HTML_element#Tables|&lt;th&gt;]]
+
* [[HTML element#Other block elements|&lt;pre&gt;]]
* [[w:HTML_element#Tables|&lt;tr&gt;]]
+
**a <pre>Pre-formatted text</pre> b
* [[w:HTML_element#Presentational markup|&lt;tt&gt;]]
+
* [[Ruby character#Ruby markup|&lt;rb&gt;]]
* [[w:HTML_element#Presentational markup|&lt;u&gt;]]
+
**東 vs <ruby style="font-size:1.2em;"><rb>東</rb></ruby>
* [[w:Ordered list|&lt;ul&gt;]]
+
* [[Ruby character#Ruby markup|&lt;rp&gt;]]
* [[w:HTML_element#Computer code phrase elements|&lt;var&gt;]]
+
**( vs <ruby style="font-size:1.2em;"><rp>(</rp></ruby>
* [[w:HTML_element#HTML comment|&lt;!-- ... --&gt;]]
+
* [[Ruby character#Ruby markup|&lt;rt&gt;]]
|}
+
**とう vs <ruby style="font-size:1.2em;"><rt>とう</rt></ruby>
 
+
* [[Ruby character#Ruby markup|&lt;ruby&gt;]]
 
+
**東(とう)京(きょう) vs <ruby style="font-size:1.2em;"><rb>東</rb><rp>(</rp><rt>とう</rt><rp>)</rp></ruby>
For many HTML elements, more convenient wikitext code is available, see [[Help:Editing]]. On the other hand, HTML tags allow an <tt>id</tt> that can be referenced in one's [[Help:User style|user style]] css, and allows the tag to be used as link target.
+
<ruby style="font-size:1.2em;"><rb>京</rb><rp>(</rp><rt>きょう</rt><rp>)</rp></ruby>
 +
* [[HTML element#Presentation|&lt;s&gt;]]
 +
**<s>Strike-through text</s>
 +
* [[HTML element#Presentation|&lt;small&gt;]]
 +
**<small>Decreases</small> font size
 +
* [[HTML element#Span|&lt;span&gt;]]
 +
**<span>An inline logical division</span>
 +
* [[HTML element#Presentation|&lt;strike&gt;]]
 +
**<s>Strike-through text</s>
 +
* [[HTML element#General|&lt;strong&gt;]]
 +
**
 +
* [[HTML element#Other inline elements|&lt;sub&gt;]]
 +
**Mark<sub>subscript</sub>
 +
* [[HTML element#Other inline elements|&lt;sup&gt;]]
 +
**Mark<sup>superscript</sup>
 +
* [[HTML element#Tables|&lt;table&gt;]]
 +
**<table>Identifies a table</table>
 +
* [[HTML element#Tables|&lt;td&gt;]]
 +
**<table><td>A table data cell</td></table>
 +
* [[HTML element#Tables|&lt;th&gt;]]
 +
**<table><th>A table header cell; contents are conventionally displayed bold and centered</th></table>
 +
* [[HTML element#Tables|&lt;tr&gt;]]
 +
**<table><tr>Contains a row of cells in a table</tr></table>
 +
* [[HTML element#Presentation|&lt;tt&gt;]]
 +
**<tt>Fixed-width font</tt>
 +
* [[HTML element#Presentation|&lt;u&gt;]]
 +
**<u>Underlines text</u>
 +
* [[HTML element#Lists|&lt;ul&gt;]]
 +
**<ul><li>An unordered...</li><li>(bulleted) list</li></ul>
 +
* [[HTML element#Computer phrase elements|&lt;var&gt;]]
 +
**<var>Variable</var>
 +
* [[HTML element#Comments|&lt;!-- ... --&gt;]]
 +
**<nowiki><!--Comment--></nowiki>
  
 +
==Anchors==
 +
HTML tags allow an <code>id</code> attribute that can be referenced in one's [[Help:User style|user style]] CSS, and allows the element to be used as link target.
  
For example, the anchor element <tt>&lt;a></tt> is not allowed, so the wikitext
+
However, the anchor element <code>a</code> is not allowed, so the wikitext
 
+
<code><nowiki><a href="http://meta.wikimedia.org/">Main Page</a></nowiki></code>
: <code><nowiki><a href="http://meta.wikimedia.org/">Main Page</a></nowiki></code>
 
 
 
 
is treated like the wikitext
 
is treated like the wikitext
 
+
<code><nowiki>&amp;lt;a href="http://meta.wikimedia.org/"&amp;gt;Main Page&amp;lt;/a&amp;gt;</nowiki></code>
: <code><nowiki>&amp;lt;a href="http://meta.wikimedia.org/"&amp;gt;Main Page&amp;lt;/a&amp;gt;</nowiki></code>
 
 
 
 
and is therefore displayed as
 
and is therefore displayed as
 
+
{{Quote|1=<a href="http://meta.wikimedia.org/">Main Page</a>}}
: <a href="http://meta.wikimedia.org/">Main Page</a>
+
which is unlikely to be what the editor intended. Instead of using the anchor element (&lt;a&gt;) the wiki markup for external reference is required (enclosed in square brackets with the URL separated from the contents by a single space):
 
+
<code><nowiki>[http://meta.wikimedia.org/ Main Page]</nowiki></code>
which is unlikely to be what the editor intended. Instead of using the anchor element (&lt;a&gt;) the wiki markup for external reference is recommended (enclosed in square brackets with the URL separated from the contents by a single space):
+
displays as
 
+
{{Quote|[http://meta.wikimedia.org/ Main Page]}}
: <code><nowiki>[http://meta.wikimedia.org/ Main Page]</nowiki></code>
 
 
 
displays as:
 
 
 
: [http://meta.wikimedia.org/ Main Page]
 
 
 
 
 
<br clear=all><!-- stop floating navbox before pre -->
 
  
 
The following excerpt from [http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/includes/Sanitizer.php?view=markup Sanitizer.php] additionally shows which attributes are allowed.
 
The following excerpt from [http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/includes/Sanitizer.php?view=markup Sanitizer.php] additionally shows which attributes are allowed.
  
<source lang=php>
+
<source lang="php">
            $htmlpairsStatic = array( # Tags that must be closed
+
$htmlpairsStatic = array( # Tags that must be closed
                'b', 'del', 'i', 'ins', 'u', 'font', 'big', 'small', 'sub', 'sup', 'h1',
+
    'b', 'del', 'i', 'ins', 'u', 'font', 'big', 'small', 'sub', 'sup', 'h1',
                'h2', 'h3', 'h4', 'h5', 'h6', 'cite', 'code', 'em', 's',
+
    'h2', 'h3', 'h4', 'h5', 'h6', 'cite', 'code', 'em', 's',
                'strike', 'strong', 'tt', 'var', 'div', 'center',
+
    'strike', 'strong', 'tt', 'var', 'div', 'center',
                'blockquote', 'ol', 'ul', 'dl', 'table', 'caption', 'pre',
+
    'blockquote', 'ol', 'ul', 'dl', 'table', 'caption', 'pre',
                'ruby', 'rt' , 'rb' , 'rp', 'p', 'span', 'u', 'abbr'  
+
    'ruby', 'rt' , 'rb' , 'rp', 'p', 'span', 'u', 'abbr'
            );
+
);
            $htmlsingle = array(
+
$htmlsingle = array(
                'br', 'hr', 'li', 'dt', 'dd'
+
    'br', 'hr', 'li', 'dt', 'dd'
            );
+
);
            $htmlsingleonly = array( # Elements that cannot have close tags
+
$htmlsingleonly = array( # Elements that cannot have close tags
                'br', 'hr'
+
    'br', 'hr'
            );
+
);
            $htmlnest = array( # Tags that can be nested--??
+
$htmlnest = array( # Tags that can be nested--??
                'table', 'tr', 'td', 'th', 'div', 'blockquote', 'ol', 'ul',
+
    'table', 'tr', 'td', 'th', 'div', 'blockquote', 'ol', 'ul',
                'dl', 'font', 'big', 'small', 'sub', 'sup', 'span'
+
    'dl', 'font', 'big', 'small', 'sub', 'sup', 'span'
            );
+
);
            $tabletags = array( # Can only appear inside table, we will close them
+
$tabletags = array( # Can only appear inside table, we will close them
                'td', 'th', 'tr',
+
    'td', 'th', 'tr',
            );
+
);
            $htmllist = array( # Tags used by list
+
$htmllist = array( # Tags used by list
                'ul','ol',
+
    'ul','ol',
            );
+
);
            $listtags = array( # Tags that can appear in a list
+
$listtags = array( # Tags that can appear in a list
                'li',
+
    'li',
            );
+
);
 
</source>
 
</source>
  
 
== Tags ==
 
== Tags ==
  
{{mlw|HTML_element|Span|<code>'''&lt;span>'''</code>}} is a generic inline text container.  
+
{{mlw|HTML element|Span|<code>'''&lt;span>'''</code>}} is a generic inline text container.  
  
<code>'''&lt;font>'''</code> is a similar tag which is [[w:Deprecation|deprecate]]d (should not be used) in favor of <nowiki><span></nowiki>.''
+
<code>'''&lt;font>'''</code> is a similar tag which is [[deprecation|deprecate]]d (should not be used) in favor of <nowiki><span></nowiki>.''
  
 
For example
 
For example
Zeile 130: Zeile 154:
 
</source>
 
</source>
  
See also {{tim|font size demo}} and {{mlm|Help:Text color}}.
+
See also {{tim|font size demo}} and [[m:Help:Text color]].
  
 
It's pointless to combine the legacy tag <tt>&lt;font&gt;</tt>
 
It's pointless to combine the legacy tag <tt>&lt;font&gt;</tt>
Zeile 144: Zeile 168:
 
The standard way of providing a named anchor as an invisible target (i.e. <code><a name="Foo"></code>) doesn't work (since all <code><a></code> tags are converted), and [http://www.w3.org/TR/html401/struct/links.html an alternative suggested by the W3C], <code><nowiki><hN id="Foo"></hN></nowiki></code>, produces an "[Edit]" link.
 
The standard way of providing a named anchor as an invisible target (i.e. <code><a name="Foo"></code>) doesn't work (since all <code><a></code> tags are converted), and [http://www.w3.org/TR/html401/struct/links.html an alternative suggested by the W3C], <code><nowiki><hN id="Foo"></hN></nowiki></code>, produces an "[Edit]" link.
  
However, <code><nowiki><span id="Foo"></nowiki></code> does produce a target that can be the destination of a link. Note that it doesn't work everywhere; for instance, in a table, it has to be inside a cell before some browsers will jump to it properly.
+
However, <code><nowiki><span id="Foo"/></nowiki></code> does produce a target that can be the destination of a link. (This is silently changed to <code><nowiki><span id="Foo"></span></nowiki></code>).  Note that it doesn't work everywhere; for instance, in a table, it has to be inside a cell before some browsers will jump to it properly.
 +
 
 +
This technique can be used to produce immutable links from one article to a section of another, which continue to work even if the section name is changed by someone who does not realize that another article links there.  For example, <code><nowiki><span id="immutable link from Article"/></nowiki></code>.
  
 
===<nowiki><div></nowiki>===
 
===<nowiki><div></nowiki>===
Zeile 151: Zeile 177:
 
* <nowiki></div></nowiki> should be preceded by a newline
 
* <nowiki></div></nowiki> should be preceded by a newline
 
*<nowiki></div></nowiki> followed by text on the same line, two newlines and text before <nowiki><div></nowiki> on the same line should be avoided (because the two newlines only produce a space)
 
*<nowiki></div></nowiki> followed by text on the same line, two newlines and text before <nowiki><div></nowiki> on the same line should be avoided (because the two newlines only produce a space)
 
Example:
 
 
{{xpdplain|
 
--|--|
 
|o
 
 
p<|div>q<|/div>r
 
 
s<|div>|t|
 
|u|
 
|v|
 
|x<|/div>y
 
 
s<|div>|t|
 
|u|
 
|v|
 
|x<|/div>y
 
 
z|
 
|--|--|
 
}}
 
  
 
===HTML comment===
 
===HTML comment===
 
Using {{tim|t}}:
 
Using {{tim|t}}:
 
*{{xpd|t}}
 
*{{xpd|t}}
*"<code><nowiki>{{subst:xpd|t}}</nowiki>"</code> gives the wikitext "<code>&lt;!--t-->start-pqr-end"<code>, producing HTML code without the comment.
+
*"<code><nowiki>{{subst:xpd|t}}</nowiki>"</code> gives "&lt;!--t-->start-pqr-end", producing HTML code without the comment.
The "Remove comments" option of [[mw:Extension:ExpandTemplates|ExpandTemplates]] selects whether comments are removed, not just in the final result but throughout the expansion process. This affects the result of parser functions: a comment in the expression of #expr or in the condition of #ifexpr gives an error message unless "Remove comments" is on, and comments affect #if and ifeq.
+
The "Remove comments" option of [[mw:Extension:ExpandTemplates|ExpandTemplates]] selects whether comments are removed, not just in the final result but throughout the expansion process. This affects the result of parser functions: a comment in the expression of #expr or in the condition of #ifexpr gives an error message unless "Remove comments" is on, and comments affect #if and #ifeq.
  
 
Example:
 
Example:
Zeile 202: Zeile 206:
 
Result of full substitution, and of ExpandTemplates with "Remove comments" off:
 
Result of full substitution, and of ExpandTemplates with "Remove comments" off:
 
----
 
----
<strong class="error">Expression error: Unrecognised punctuation character ""</strong>
+
0
  
 
0
 
0
Zeile 230: Zeile 234:
 
</div>
 
</div>
 
</blockquote>
 
</blockquote>
 
  
 
Most tags can have classes and IDs. They can be used in conjunction with stylesheets to give a piece of text a descriptive class (or unique identifier) and to refer to that in a stylesheet.
 
Most tags can have classes and IDs. They can be used in conjunction with stylesheets to give a piece of text a descriptive class (or unique identifier) and to refer to that in a stylesheet.
Zeile 245: Zeile 248:
 
Classes and IDs can also be used by Javascript code, for example see [[:en:Template_talk:Link_FA#How_does_it_work.3F|how {Link FA} works]] in enwiki.
 
Classes and IDs can also be used by Javascript code, for example see [[:en:Template_talk:Link_FA#How_does_it_work.3F|how {Link FA} works]] in enwiki.
  
 +
Classes are also widely used to create [[microformat]]s. See [[WP:UF|the microformats project]] for more information. Some [[Wikipedia:WikiProject Microformats/classes|class names are reserved]] for use in microformats.
  
 
Another attribute example is <tt>title</tt>, for example used in {{tl|H:title}} template: note the hover box over "20000 ft"
 
Another attribute example is <tt>title</tt>, for example used in {{tl|H:title}} template: note the hover box over "20000 ft"
Zeile 269: Zeile 273:
  
 
=== Comments ===
 
=== Comments ===
HTML comments in the wikitext (<nowiki><!-- ... --></nowiki>) will not appear in the HTML code at all.
+
<b>HTML comments in the wikitext (<nowiki><!-- ... --></nowiki>) will not appear in the HTML code at all.</b>
  
 
=== Headers ===
 
=== Headers ===
Zeile 282: Zeile 286:
  
 
User CSS and JS pages (see [[Help:User style]]) are interpreted as if inside a <nowiki><pre></nowiki> block. From MW 1.11 this also goes for sitewide CSS/JS; in earlier versions, you have to manually add <tt><nowiki>/*<pre>*/</nowiki></tt> to the beginning and <tt><nowiki>/*</pre>*/</nowiki></tt> to the end of those pages to avoid strange rendering.
 
User CSS and JS pages (see [[Help:User style]]) are interpreted as if inside a <nowiki><pre></nowiki> block. From MW 1.11 this also goes for sitewide CSS/JS; in earlier versions, you have to manually add <tt><nowiki>/*<pre>*/</nowiki></tt> to the beginning and <tt><nowiki>/*</pre>*/</nowiki></tt> to the end of those pages to avoid strange rendering.
 +
 +
==Validation==
 +
{{main|Help:Markup validation}}
 +
The MediaWiki software attempts to catch HTML errors, but it does not catch all of them. If you use HTML in wikitext, it is helpful to verify it with the [[W3C Markup Validation Service]].
  
 
== External links ==
 
== External links ==
 
* HTML 4.01 specification: [http://www.w3.org/TR/html401/index/elements.html elements] | [http://www.w3.org/TR/html401/index/attributes.html attributes]
 
* HTML 4.01 specification: [http://www.w3.org/TR/html401/index/elements.html elements] | [http://www.w3.org/TR/html401/index/attributes.html attributes]
 
* For customizing the handling of HTML in MediaWiki, see the HTML and Tidy sections in [[mw:Manual:Configuration settings]]
 
* For customizing the handling of HTML in MediaWiki, see the HTML and Tidy sections in [[mw:Manual:Configuration settings]]
* Some extensions allow adding arbitrary HTML to a page, for example [[mw:Extension:AddHTML]],[[mw:Extension:SecureHTML]] and [[mw:Extension:Secure HTML]]; see [http://www.mediawiki.org/wiki/Manual:%24wgRawHtml $wgRawHtml] for a more complete list
+
* Some extensions allow adding arbitrary HTML to a page, for example [[mw:Extension:AddHTML]], [[mw:Extension:SecureHTML]] and [[mw:Extension:Secure HTML]]; see [[mw:Manual:$wgRawHtml|$wgRawHtml]] for a more complete list
 
* Within the MediaWiki codebase, these HTML checks happen in [http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/includes/Sanitizer.php includes/Sanitizer.php]
 
* Within the MediaWiki codebase, these HTML checks happen in [http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/includes/Sanitizer.php includes/Sanitizer.php]

Aktuelle Version vom 11. August 2010, 12:55 Uhr

For many HTML elements, more convenient wikitext code is available, see Help:Wiki markup, however there are some situations in which the HTML alternative is useful, for example creating a link to a particular element of a table.

Permitted HTML

The following HTML elements are currently permitted:

  • <abbr>
    • Marks an abbreviation, and can make the full form available: abbr.
  • <b>
    • Sets font to boldface where possible
  • <big>
    • Increases font size
  • <blockquote>
    • A block-level quotation,
      for when the quotation includes block level elements,
      e.g. paragraphs
  • <br>
    • A forced
      line-break
  • <caption>
    • Specifies a caption for a table
  • <center>
    • Creates a block-level center-aligned division
      Use <div> instead
  • <cite>
    • A citation
  • <code>
    • A code snippet
  • <dd>
    • The definition of a term,
      in a definition list
  • <del>
    • Deleted text
  • <div>
    • A block-level logical division
  • <dl>
    • A definition list (consisting of definition terms paired with definitions)
  • <dt>
    • A definition term
      in a definition list
  • <em>
    • Emphasis
  • <font>
    • Can specify the font color with the color attribute, typeface with the face attribute, and absolute or relative size with the size attribute. use <span> instead
  • <h1> - <h6>
    • <h1>Section headings at different levels.</h1>
  • <hr>

    • A horizontal rule</hr>
  • <i>
    • Sets font to italic where possible
  • <ins>
    • Inserted text
  • <li>
    • A list item in ordered (ol)
    • or unordered (ul) lists
  • <ol>
      1. An ordered...
      2. (enumerated) list
  • <p>
    • Creates a

      paragraph,

      perhaps the most common block level element
  • <pre>
    • a
      Pre-formatted text
      b
  • <rb>
    • 東 vs
  • <rp>
    • ( vs (
  • <rt>
    • とう vs とう
  • <ruby>
    • 東(とう)京(きょう) vs (とう)

(きょう)

  • <s>
    • Strike-through text
  • <small>
    • Decreases font size
  • <span>
    • An inline logical division
  • <strike>
    • Strike-through text
  • <strong>
  • <sub>
    • Marksubscript
  • <sup>
    • Marksuperscript
  • <table>
    • Identifies a table
  • <td>
    • A table data cell
  • <th>
    • A table header cell; contents are conventionally displayed bold and centered
  • <tr>
    • Contains a row of cells in a table
  • <tt>
    • Fixed-width font
  • <u>
    • Underlines text
  • <ul>
      • An unordered...
      • (bulleted) list
  • <var>
    • Variable
  • <!-- ... -->
    • <!--Comment-->

Anchors

HTML tags allow an id attribute that can be referenced in one's user style CSS, and allows the element to be used as link target.

However, the anchor element a is not allowed, so the wikitext

<a href="http://meta.wikimedia.org/">Main Page</a>

is treated like the wikitext

&lt;a href="http://meta.wikimedia.org/"&gt;Main Page&lt;/a&gt;

and is therefore displayed as Vorlage:Quote which is unlikely to be what the editor intended. Instead of using the anchor element (<a>) the wiki markup for external reference is required (enclosed in square brackets with the URL separated from the contents by a single space):

[http://meta.wikimedia.org/ Main Page]

displays as Vorlage:Quote

The following excerpt from Sanitizer.php additionally shows which attributes are allowed.

<source lang="php"> $htmlpairsStatic = array( # Tags that must be closed

   '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', 'abbr'

); $htmlsingle = array(

   'br', 'hr', 'li', 'dt', 'dd'

); $htmlsingleonly = array( # Elements that cannot have close tags

   'br', 'hr'

); $htmlnest = array( # Tags that can be nested--??

   'table', 'tr', 'td', 'th', 'div', 'blockquote', 'ol', 'ul',
   'dl', 'font', 'big', 'small', 'sub', 'sup', 'span'

); $tabletags = array( # Can only appear inside table, we will close them

   'td', 'th', 'tr',

); $htmllist = array( # Tags used by list

   'ul','ol',

); $listtags = array( # Tags that can appear in a list

   'li',

); </source>

Tags

Vorlage:Mlw is a generic inline text container.

<font> is a similar tag which is deprecated (should not be used) in favor of <span>.

For example <source lang=html4strict> a red word. </source> produces the same result as <source lang=html4strict> a red word. </source>

See also Vorlage:Tim and m:Help:Text color.

It's pointless to combine the legacy tag <font> with inline CSS; legacy browsers would ignore the CSS, while modern browsers support <span> (see above).

Note that in most cases, one can use a more descriptive tag, for instance, <strong> to indicate an important piece of text, or <em> (subject to the same things as strong) to indicate an emphasized piece of text.

This not only draws the user's attention to the text, but can also alert those who are using nonvisual browsers or have sight impairments, etc. to the fact that that is emphasized text.

Using <span> as a link target

The standard way of providing a named anchor as an invisible target (i.e. <a name="Foo">) doesn't work (since all <a> tags are converted), and an alternative suggested by the W3C, <hN id="Foo"></hN>, produces an "[Edit]" link.

However, <span id="Foo"/> does produce a target that can be the destination of a link. (This is silently changed to <span id="Foo"></span>). Note that it doesn't work everywhere; for instance, in a table, it has to be inside a cell before some browsers will jump to it properly.

This technique can be used to produce immutable links from one article to a section of another, which continue to work even if the section name is changed by someone who does not realize that another article links there. For example, <span id="immutable link from Article"/>.

<div>

<div> is a generic block container. Rules:

  • <div> should be followed by a newline
  • </div> should be preceded by a newline
  • </div> followed by text on the same line, two newlines and text before <div> on the same line should be avoided (because the two newlines only produce a space)

HTML comment

Using Vorlage:Tim:

  • Vorlage:Xpd
  • "{{subst:xpd|t}}" gives "<!--t-->start-pqr-end", producing HTML code without the comment.

The "Remove comments" option of ExpandTemplates selects whether comments are removed, not just in the final result but throughout the expansion process. This affects the result of parser functions: a comment in the expression of #expr or in the condition of #ifexpr gives an error message unless "Remove comments" is on, and comments affect #if and #ifeq.

Example:

Wikitext:


{{#expr:<!--p-->3}}

{{#ifeq:<!--p-->3|3|1|0}}

{{#if:<!--p-->|1|0}}

Result of normal expansion, and of ExpandTemplates with "Remove comments" on:


{{#expr:3}}

{{#ifeq:3|3|1|0}}

{{#if:|1|0}}


Result of full substitution, and of ExpandTemplates with "Remove comments" off:


0

0

1


Therefore it is typically better to avoid comments in these places, and to put the comment before or after the parser function.

In the case of nested parser functions, to avoid having to put the comments outside the whole, an alternative is {{void|comment}}. In the case of substitution of the parser function, "void" has to be substituted too, e.g. in a template allowing multi-level substitution we can put {{{{{subst1|}}}#expr:3*{{{1}}} {{{{{subst1|}}}void| multiply by 3 }}}}.

Another alternative is making the comment the name of a parameter (in the likely case that it is unused), with the empty string as default, e.g. {{{ multiply by 3 |}}} or, to recognize the intention, use pseudo comment tags: {{{<!- multiply by 3 ->|}}}, or real ones, if the empty string is not used as parameter: {{{<!-- multiply by 3 -->|}}}.

See also Vorlage:Tim.

Attributes

Most tags can have a style attribute. For example <source lang=html4strict>

This is red text.

</source> produces:

This is red text.

Most tags can have classes and IDs. They can be used in conjunction with stylesheets to give a piece of text a descriptive class (or unique identifier) and to refer to that in a stylesheet. For example

<source lang=html4strict>

Example infobox

</source>

Example infobox

Produces the box which floats on the right because infobox class is already defined in local Mediawiki:Common.css.

Classes and IDs can also be used by Javascript code, for example see how {Link FA} works in enwiki.

Classes are also widely used to create microformats. See the microformats project for more information. Some class names are reserved for use in microformats.

Another attribute example is title, for example used in Vorlage:Tl template: note the hover box over "20000 ft"

"a height of Vorlage:H:title above sea level"


Tags with special effect

Pre

<pre> tags work as the combination of <nowiki> and the standard HTML <pre> tag: the content will preformatted, and it will not be parsed, but shown as in the wikitext source. If you want preformatted but parsed text, use a space in the beginning of the line instead. For example,

<pre>This word is <b>bold</b>.</pre>
  This word is <b>bold</b>.

will render as

This word is <b>bold</b>.
This word is bold.

Comments

HTML comments in the wikitext (<!-- ... -->) will not appear in the HTML code at all.

Headers

Headers (<h1>...<h6>) will be treated in a similar way as wikicode headers:

sample header

Note that it appears in the table of contents and has an accompanying edit link. There are some minor differences though: editing such a section won't prefill the edit summary, and the browser won't jump to the beginning of the section when saving the page. Thus, you should use the wikitext equivalents instead.

Exceptions

In some pages in the MediaWiki namespace (typically the short messages like button labels) HTML does not work, and e.g. <span id=abc> produces the HTML &lt;span id=abc&gt; rendered by the browser as <span id=abc>. Some others are interpreted as pure HTML (thus any tag can be used, but wikicode won't be transformed to HTML).

User CSS and JS pages (see Help:User style) are interpreted as if inside a <pre> block. From MW 1.11 this also goes for sitewide CSS/JS; in earlier versions, you have to manually add /*<pre>*/ to the beginning and /*</pre>*/ to the end of those pages to avoid strange rendering.

Validation

Vorlage:Main The MediaWiki software attempts to catch HTML errors, but it does not catch all of them. If you use HTML in wikitext, it is helpful to verify it with the W3C Markup Validation Service.

External links